[bs-140] Extract framework-provided @ConfigurationProperties into @Bean

Allows @ConfigurationProperties beans to be declared explicitly (to set default values)

[#50804109]
This commit is contained in:
Dave Syer 2013-05-30 14:20:24 +01:00
parent cf201ffd80
commit 6c22e0ab6e
3 changed files with 29 additions and 8 deletions

View File

@ -40,9 +40,15 @@ public class ActuatorAutoConfiguration {
* ServerProperties has to be declared in a non-conditional bean, so that it gets
* added to the context early enough
*/
@EnableConfigurationProperties(ManagementServerProperties.class)
@EnableConfigurationProperties
public static class ServerPropertiesConfiguration {
@ConditionalOnMissingBean(ManagementServerProperties.class)
@Bean(name = "org.springframework.bootstrap.actuate.properties.ManagementServerProperties")
public ManagementServerProperties managementServerProperties() {
return new ManagementServerProperties();
}
@Bean
@ConditionalOnMissingBean(EndpointsProperties.class)
public EndpointsProperties endpointsProperties() {

View File

@ -42,9 +42,15 @@ import org.springframework.security.web.authentication.www.BasicAuthenticationEn
@Configuration
@ConditionalOnClass({ EnableWebSecurity.class })
@EnableWebSecurity
@EnableConfigurationProperties(SecurityProperties.class)
@EnableConfigurationProperties
public class SecurityAutoConfiguration {
@ConditionalOnMissingBean(SecurityProperties.class)
@Bean(name = "org.springframework.bootstrap.actuate.properties.SecurityProperties")
public SecurityProperties securityProperties() {
return new SecurityProperties();
}
@Bean
@ConditionalOnMissingBean({ AuthenticationEventPublisher.class })
public AuthenticationEventPublisher authenticationEventPublisher() {
@ -74,11 +80,12 @@ public class SecurityAutoConfiguration {
http.requiresChannel().antMatchers("/**").requiresSecure();
}
if (this.security.getBasic().isEnabled()) {
http.authenticationEntryPoint(entryPoint())
.antMatcher(this.security.getBasic().getPath()).httpBasic()
.authenticationEntryPoint(entryPoint()).and().anonymous()
.disable();
http.authorizeUrls().antMatchers("/**")
HttpConfiguration matcher = http.antMatcher(this.security.getBasic()
.getPath());
matcher.authenticationEntryPoint(entryPoint()).antMatcher("/**")
.httpBasic().authenticationEntryPoint(entryPoint()).and()
.anonymous().disable();
matcher.authorizeUrls().antMatchers("/**")
.hasRole(this.security.getBasic().getRole());
}
// No cookies for service endpoints by default

View File

@ -19,12 +19,14 @@ import org.apache.catalina.valves.AccessLogValve;
import org.apache.catalina.valves.RemoteIpValve;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.bootstrap.context.annotation.ConditionalOnMissingBean;
import org.springframework.bootstrap.context.annotation.EnableConfigurationProperties;
import org.springframework.bootstrap.context.embedded.ConfigurableEmbeddedServletContainerFactory;
import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.bootstrap.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.bootstrap.properties.ServerProperties;
import org.springframework.bootstrap.properties.ServerProperties.Tomcat;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
@ -33,12 +35,18 @@ import org.springframework.util.StringUtils;
*
*/
@Configuration
@EnableConfigurationProperties(ServerProperties.class)
@EnableConfigurationProperties
public class ServerPropertiesConfiguration implements EmbeddedServletContainerCustomizer {
@Autowired
private BeanFactory beanFactory;
@ConditionalOnMissingBean(ServerProperties.class)
@Bean(name = "org.springframework.bootstrap.properties.ServerProperties")
public ServerProperties serverProperties() {
return new ServerProperties();
}
@Override
public void customize(ConfigurableEmbeddedServletContainerFactory factory) {