Final polish before 1.0.0.RC1

This commit is contained in:
Phillip Webb
2014-01-21 13:30:23 -08:00
parent 853b0a8027
commit ac54d7fe3c
67 changed files with 390 additions and 218 deletions

View File

@@ -40,7 +40,6 @@ import org.springframework.util.StringUtils;
* the {@link AutoConfigurationReport} to the log. Reports are logged at the
* {@link LogLevel#DEBUG DEBUG} level unless there was a problem, in which case they are
* the {@link LogLevel#INFO INFO} level is used.
*
* <p>
* This initializer is not intended to be shared across multiple application context
* instances.

View File

@@ -39,20 +39,17 @@ import org.springframework.core.io.support.SpringFactoriesLoader;
* have {@code tomat-embedded.jar} on your classpath you are likely to want a
* {@link TomcatEmbeddedServletContainerFactory} (unless you have defined your own
* {@link EmbeddedServletContainerFactory} bean).
*
* <p>
* Auto-configuration tries to be as intelligent as possible and will back-away as you
* define more of your own configuration. You can always manually {@link #exclude()} any
* configuration that you never want to apply. Auto-configuration is always applied after
* user-defined beans have been registered.
*
* <p>
* The package of the class that is annotated with {@code @EnableAutoConfiguration} has
* specific significance and is often used as a 'default'. For example, it will be used
* when scanning for {@code @Entity} classes. It is generally recommended that you place
* {@code @EnableAutoConfiguration} in a root package so that all sub-packages and classes
* can be searched.
*
* <p>
* Auto-configuration classes are regular Spring {@link Configuration} beans. They are
* located using the {@link SpringFactoriesLoader} mechanism (keyed against this class).

View File

@@ -33,6 +33,8 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager;
/**
* Basic {@link BatchConfigurer} implementation.
*
* @author Dave Syer
*/
@Component
@@ -41,15 +43,28 @@ public class BasicBatchConfigurer implements BatchConfigurer {
private static Log logger = LogFactory.getLog(BasicBatchConfigurer.class);
private DataSource dataSource;
private EntityManagerFactory entityManagerFactory;
private PlatformTransactionManager transactionManager;
private JobRepository jobRepository;
private JobLauncher jobLauncher;
/**
* Create a new {@link BasicBatchConfigurer} instance.
* @param dataSource the underlying data source
*/
public BasicBatchConfigurer(DataSource dataSource) {
this(dataSource, null);
}
/**
* Create a new {@link BasicBatchConfigurer} instance.
* @param dataSource the underlying data source
* @param entityManagerFactory the entity manager factory (or {@code null})
*/
public BasicBatchConfigurer(DataSource dataSource,
EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,7 +38,8 @@ import org.springframework.stereotype.Component;
@Component
public class BatchDatabaseInitializer implements EnvironmentAware {
private static final String DEFAULT_SCHEMA_LOCATION = "classpath:org/springframework/batch/core/schema-@@platform@@.sql";
private static final String DEFAULT_SCHEMA_LOCATION = "classpath:org/springframework/"
+ "batch/core/schema-@@platform@@.sql";
@Autowired
private DataSource dataSource;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -198,16 +198,26 @@ class OnBeanCondition extends SpringBootCondition implements ConfigurationCondit
if (this.types.isEmpty() && this.names.isEmpty()) {
addDeducedBeanType(context, metadata, this.types);
}
Assert.isTrue(
!this.types.isEmpty() || !this.names.isEmpty()
|| !this.annotations.isEmpty(),
"@"
+ ClassUtils.getShortName(annotationType)
+ " annotations must specify at least one bean (type, name or annotation)");
Assert.isTrue(hasAtLeastOne(this.types, this.names, this.annotations),
annotationName(annotationType) + " annotations must "
+ "specify at least one bean (type, name or annotation)");
this.strategy = (SearchStrategy) metadata.getAnnotationAttributes(
annotationType.getName()).get("search");
}
private boolean hasAtLeastOne(List<?>... lists) {
for (List<?> list : lists) {
if (!list.isEmpty()) {
return true;
}
}
return false;
}
private String annotationName(Class<?> annotationType) {
return "@" + ClassUtils.getShortName(annotationType);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private void collect(MultiValueMap<String, Object> attributes, String key,
List<String> destination) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,7 +34,8 @@ import org.springframework.web.context.support.StandardServletEnvironment;
*/
class OnWebApplicationCondition extends SpringBootCondition {
private static final String WEB_CONTEXT_CLASS = "org.springframework.web.context.support.GenericWebApplicationContext";
private static final String WEB_CONTEXT_CLASS = "org.springframework.web.context."
+ "support.GenericWebApplicationContext";
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,9 +31,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.context.ApplicationContext;
@@ -177,6 +177,9 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
}
/**
* Base {@link Condition} for non-embedded database checks.
*/
static abstract class NonEmbeddedDatabaseCondition extends SpringBootCondition {
protected abstract String getDataSourceClassName();
@@ -243,6 +246,10 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
}
}
/**
* {@link Condition} to detect when a commons-dbcp {@code BasicDataSource} backed
* database is used.
*/
static class BasicDatabaseCondition extends NonEmbeddedDatabaseCondition {
private Condition tomcatCondition = new TomcatDatabaseCondition();
@@ -256,12 +263,15 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
if (matches(context, metadata, this.tomcatCondition)) {
return ConditionOutcome.noMatch("tomcat DataSource");
return ConditionOutcome.noMatch("Tomcat DataSource");
}
return super.getMatchOutcome(context, metadata);
}
}
/**
* {@link Condition} to detect when a Tomcat DataSource backed database is used.
*/
static class TomcatDatabaseCondition extends NonEmbeddedDatabaseCondition {
@Override
@@ -271,6 +281,9 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
}
/**
* {@link Condition} to detect when an embedded database is used.
*/
static class EmbeddedDatabaseCondition extends SpringBootCondition {
private SpringBootCondition tomcatCondition = new TomcatDatabaseCondition();
@@ -293,6 +306,9 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
}
}
/**
* {@link Condition} to detect when a database is configured.
*/
static class DatabaseCondition extends SpringBootCondition {
private SpringBootCondition tomcatCondition = new TomcatDatabaseCondition();

View File

@@ -80,16 +80,14 @@ public class JmsTemplateAutoConfiguration {
private ActiveMQConnectionFactoryProperties config;
@Bean
ConnectionFactory jmsConnectionFactory() {
public ConnectionFactory jmsConnectionFactory() {
if (this.config.isPooled()) {
PooledConnectionFactory pool = new PooledConnectionFactory();
pool.setConnectionFactory(new ActiveMQConnectionFactory(this.config
.getBrokerURL()));
return pool;
}
else {
return new ActiveMQConnectionFactory(this.config.getBrokerURL());
}
return new ActiveMQConnectionFactory(this.config.getBrokerURL());
}
}
@@ -108,9 +106,7 @@ public class JmsTemplateAutoConfiguration {
if (this.inMemory) {
return "vm://localhost";
}
else {
return this.brokerURL;
}
return this.brokerURL;
}
public void setBrokerURL(String brokerURL) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +27,6 @@ import org.springframework.jmx.export.MBeanExporter;
/**
* {@link EnableAutoConfiguration Auto-configuration} to enable/disable Spring's
* {@link EnableMBeanExport} mechanism based on configuration properties.
*
* <p>
* To disable auto export of annotation beans set <code>spring.jmx.enabled: false</code>.
*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,7 +48,6 @@ public class ReactorAutoConfiguration {
@ConditionalOnMissingBean(Environment.class)
@EnableReactor
protected static class ReactorConfiguration {
}
}

View File

@@ -33,6 +33,11 @@ import org.springframework.security.config.annotation.ObjectPostProcessor;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configurers.provisioning.InMemoryUserDetailsManagerConfigurer;
/**
* Configuration for a Spring Security in-memory {@link AuthenticationManager}.
*
* @author Dave Syer
*/
@Configuration
@ConditionalOnBean(ObjectPostProcessor.class)
@ConditionalOnMissingBean(AuthenticationManager.class)
@@ -69,4 +74,4 @@ public class AuthenticationManagerConfiguration {
}
}
}

View File

@@ -16,6 +16,7 @@
package org.springframework.boot.autoconfigure.security;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -24,6 +25,11 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.security.authentication.AuthenticationManager;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Security.
*
* @author Dave Syer
*/
@Configuration
@ConditionalOnClass(AuthenticationManager.class)
@EnableConfigurationProperties
@@ -37,4 +43,4 @@ public class SecurityAutoConfiguration {
return new SecurityProperties();
}
}
}

View File

@@ -87,7 +87,6 @@ import org.springframework.web.servlet.support.RequestDataValueProcessor;
@ConditionalOnClass({ EnableWebSecurity.class })
@ConditionalOnMissingBean(WebSecurityConfiguration.class)
@ConditionalOnWebApplication
// @ConditionalOnMissingBean(annotation = EnableWebSecurity.class)
public class SpringBootWebSecurityConfiguration {
private static List<String> DEFAULT_IGNORED = Arrays.asList("/css/**", "/js/**",
@@ -107,6 +106,39 @@ public class SpringBootWebSecurityConfiguration {
return new IgnoredPathsWebSecurityConfigurerAdapter();
}
public static void configureHeaders(HeadersConfigurer<?> configurer,
SecurityProperties.Headers headers) throws Exception {
if (headers.getHsts() != Headers.HSTS.none) {
boolean includeSubdomains = headers.getHsts() == Headers.HSTS.all;
HstsHeaderWriter writer = new HstsHeaderWriter(includeSubdomains);
writer.setRequestMatcher(AnyRequestMatcher.INSTANCE);
configurer.addHeaderWriter(writer);
}
if (headers.isContentType()) {
configurer.contentTypeOptions();
}
if (headers.isXss()) {
configurer.xssProtection();
}
if (headers.isCache()) {
configurer.cacheControl();
}
if (headers.isFrame()) {
configurer.frameOptions();
}
}
public static List<String> getIgnored(SecurityProperties security) {
List<String> ignored = new ArrayList<String>(security.getIgnored());
if (ignored.isEmpty()) {
ignored.addAll(DEFAULT_IGNORED);
}
else if (ignored.contains("none")) {
ignored.remove("none");
}
return ignored;
}
// Get the ignored paths in early
@Order(Ordered.HIGHEST_PRECEDENCE)
private static class IgnoredPathsWebSecurityConfigurerAdapter implements
@@ -135,10 +167,12 @@ public class SpringBootWebSecurityConfiguration {
@ConditionalOnExpression("${security.basic.enabled:true}")
@Configuration
protected static class WebMvcSecurityConfigurationConditions {
@Configuration
@EnableWebMvcSecurity
protected static class DefaultWebMvcSecurityConfiguration {
}
}
// Pull in a plain @EnableWebSecurity if Spring MVC is not available
@@ -223,37 +257,4 @@ public class SpringBootWebSecurityConfiguration {
}
public static void configureHeaders(HeadersConfigurer<?> configurer,
SecurityProperties.Headers headers) throws Exception {
if (headers.getHsts() != Headers.HSTS.none) {
boolean includeSubdomains = headers.getHsts() == Headers.HSTS.all;
HstsHeaderWriter writer = new HstsHeaderWriter(includeSubdomains);
writer.setRequestMatcher(AnyRequestMatcher.INSTANCE);
configurer.addHeaderWriter(writer);
}
if (headers.isContentType()) {
configurer.contentTypeOptions();
}
if (headers.isXss()) {
configurer.xssProtection();
}
if (headers.isCache()) {
configurer.cacheControl();
}
if (headers.isFrame()) {
configurer.frameOptions();
}
}
public static List<String> getIgnored(SecurityProperties security) {
List<String> ignored = new ArrayList<String>(security.getIgnored());
if (ignored.isEmpty()) {
ignored.addAll(DEFAULT_IGNORED);
}
else if (ignored.contains("none")) {
ignored.remove("none");
}
return ignored;
}
}