Merge branch '1.5.x'
This commit is contained in:
@@ -27,8 +27,7 @@ import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.filter.TypeFilter;
|
||||
|
||||
/**
|
||||
* A {@link TypeFilter} implementation that matches registered auto-configuration
|
||||
* classes.
|
||||
* A {@link TypeFilter} implementation that matches registered auto-configuration classes.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.5.0
|
||||
@@ -37,7 +36,7 @@ public class AutoConfigurationExcludeFilter implements TypeFilter, BeanClassLoad
|
||||
|
||||
private ClassLoader beanClassLoader;
|
||||
|
||||
private List<String> candidateAutoConfigurations;
|
||||
private volatile List<String> autoConfigurations;
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(ClassLoader beanClassLoader) {
|
||||
@@ -50,22 +49,22 @@ public class AutoConfigurationExcludeFilter implements TypeFilter, BeanClassLoad
|
||||
return isConfiguration(metadataReader) && isAutoConfiguration(metadataReader);
|
||||
}
|
||||
|
||||
protected List<String> getCandidateAutoConfigurations() {
|
||||
if (this.candidateAutoConfigurations == null) {
|
||||
this.candidateAutoConfigurations = SpringFactoriesLoader.loadFactoryNames(
|
||||
EnableAutoConfiguration.class, this.beanClassLoader);
|
||||
}
|
||||
return this.candidateAutoConfigurations;
|
||||
}
|
||||
|
||||
private boolean isConfiguration(MetadataReader metadataReader) {
|
||||
return metadataReader.getAnnotationMetadata()
|
||||
.isAnnotated(Configuration.class.getName());
|
||||
}
|
||||
|
||||
private boolean isAutoConfiguration(MetadataReader metadataReader) {
|
||||
return getCandidateAutoConfigurations().contains(
|
||||
metadataReader.getClassMetadata().getClassName());
|
||||
return getAutoConfigurations()
|
||||
.contains(metadataReader.getClassMetadata().getClassName());
|
||||
}
|
||||
|
||||
protected List<String> getAutoConfigurations() {
|
||||
if (this.autoConfigurations == null) {
|
||||
this.autoConfigurations = SpringFactoriesLoader.loadFactoryNames(
|
||||
EnableAutoConfiguration.class, this.beanClassLoader);
|
||||
}
|
||||
return this.autoConfigurations;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,16 +16,12 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.orm.jpa;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
@@ -53,7 +49,6 @@ import org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor;
|
||||
import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.jta.JtaTransactionManager;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
@@ -69,8 +64,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
|
||||
@Import(DataSourceInitializedPublisher.Registrar.class)
|
||||
public abstract class JpaBaseConfiguration implements BeanFactoryAware {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(JpaBaseConfiguration.class);
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
private final JpaProperties properties;
|
||||
@@ -110,8 +103,7 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware {
|
||||
ObjectProvider<PersistenceUnitManager> persistenceUnitManagerProvider) {
|
||||
EntityManagerFactoryBuilder builder = new EntityManagerFactoryBuilder(
|
||||
jpaVendorAdapter, this.properties.getProperties(),
|
||||
persistenceUnitManagerProvider.getIfAvailable(),
|
||||
determinePersistenceUnitRootLocation());
|
||||
persistenceUnitManagerProvider.getIfAvailable());
|
||||
builder.setCallback(getVendorCallback());
|
||||
return builder;
|
||||
}
|
||||
@@ -190,19 +182,6 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware {
|
||||
this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
|
||||
}
|
||||
|
||||
private URL determinePersistenceUnitRootLocation() {
|
||||
Class<?> source = getClass();
|
||||
try {
|
||||
URL url = source.getProtectionDomain().getCodeSource().getLocation();
|
||||
return ResourceUtils.extractJarFileURL(url);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.info("Could not determine persistence " + "unit root location from "
|
||||
+ source + " : " + ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnWebApplication
|
||||
@ConditionalOnClass(WebMvcConfigurerAdapter.class)
|
||||
|
||||
@@ -675,9 +675,9 @@ public class ServerProperties
|
||||
private int acceptCount = 0;
|
||||
|
||||
/**
|
||||
* Comma-separated list of additional patterns that match jars to ignore for
|
||||
* TLD scanning. The special '?' and '*' characters can be used in the pattern
|
||||
* to match one and only one character and zero or more characters respectively.
|
||||
* Comma-separated list of additional patterns that match jars to ignore for TLD
|
||||
* scanning. The special '?' and '*' characters can be used in the pattern to
|
||||
* match one and only one character and zero or more characters respectively.
|
||||
*/
|
||||
private List<String> additionalTldSkipPatterns = new ArrayList<String>();
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class AutoConfigurationExcludeFilterTests {
|
||||
|
||||
private static final Class<?> FILTERED = ExampleFilteredAutoConfiguration.class;
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@@ -59,10 +61,9 @@ public class AutoConfigurationExcludeFilterTests {
|
||||
assertThat(this.context.getBeansOfType(String.class)).hasSize(1);
|
||||
assertThat(this.context.getBean(String.class)).isEqualTo("test");
|
||||
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
||||
this.context.getBean(ExampleFilteredAutoConfiguration.class);
|
||||
this.context.getBean(FILTERED);
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackageClasses = ExampleConfiguration.class, excludeFilters = @ComponentScan.Filter(type = FilterType.CUSTOM, classes = TestAutoConfigurationExcludeFilter.class))
|
||||
static class Config {
|
||||
@@ -71,10 +72,12 @@ public class AutoConfigurationExcludeFilterTests {
|
||||
|
||||
static class TestAutoConfigurationExcludeFilter
|
||||
extends AutoConfigurationExcludeFilter {
|
||||
|
||||
@Override
|
||||
protected List<String> getCandidateAutoConfigurations() {
|
||||
return Collections.singletonList(ExampleFilteredAutoConfiguration.class.getName());
|
||||
protected List<String> getAutoConfigurations() {
|
||||
return Collections.singletonList(FILTERED.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -493,7 +493,6 @@ public class ServerPropertiesTests {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("server.tomcat.additional-tld-skip-patterns", "foo.jar,bar.jar");
|
||||
bindProperties(map);
|
||||
|
||||
testCustomTomcatTldSkip("foo.jar", "bar.jar");
|
||||
}
|
||||
|
||||
@@ -503,7 +502,6 @@ public class ServerPropertiesTests {
|
||||
map.put("server.tomcat.additional-tld-skip-patterns[0]", "biz.jar");
|
||||
map.put("server.tomcat.additional-tld-skip-patterns[1]", "bah.jar");
|
||||
bindProperties(map);
|
||||
|
||||
testCustomTomcatTldSkip("biz.jar", "bah.jar");
|
||||
}
|
||||
|
||||
@@ -511,7 +509,8 @@ public class ServerPropertiesTests {
|
||||
TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory();
|
||||
this.properties.customize(container);
|
||||
assertThat(container.getTldSkipPatterns()).contains(expectedJars);
|
||||
assertThat(container.getTldSkipPatterns()).contains("junit-*.jar", "spring-boot-*.jar");
|
||||
assertThat(container.getTldSkipPatterns()).contains("junit-*.jar",
|
||||
"spring-boot-*.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user