diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java index b4a8ef2998..bbd105e413 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java @@ -364,6 +364,7 @@ public class EndpointWebMvcChildContextConfiguration { } abstract void customize(T container); + } static class TomcatAccessLogCustomizer diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java index 2e65671ed9..02e2e51032 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java @@ -188,8 +188,9 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter roles = Arrays.asList(StringUtils.trimArrayElements(StringUtils - .commaDelimitedListToStringArray(this.roleResolver.getProperty("roles", "ROLE_ADMIN")))); + List roles = Arrays.asList(StringUtils + .trimArrayElements(StringUtils.commaDelimitedListToStringArray( + this.roleResolver.getProperty("roles", "ROLE_ADMIN")))); for (GrantedAuthority authority : authentication.getAuthorities()) { String name = authority.getAuthority(); for (String role : roles) { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfigurationTests.java index 055a64f181..f588333ab6 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfigurationTests.java @@ -42,7 +42,7 @@ import org.springframework.web.context.support.AnnotationConfigWebApplicationCon import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link EndpointWebMvcHypermediaManagementContextConfigurationTests}. + * Tests for {@link EndpointWebMvcHypermediaManagementContextConfiguration}. * * @author Andy Wilkinson */ diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpointTests.java index e03ab21ac5..16c3a28ec7 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpointTests.java @@ -60,15 +60,18 @@ public class HealthMvcEndpointTests { private MockEnvironment environment; - private UsernamePasswordAuthenticationToken user = createAuthenticationToken("ROLE_USER"); + private UsernamePasswordAuthenticationToken user = createAuthenticationToken( + "ROLE_USER"); - private UsernamePasswordAuthenticationToken admin = createAuthenticationToken("ROLE_ADMIN"); + private UsernamePasswordAuthenticationToken admin = createAuthenticationToken( + "ROLE_ADMIN"); - private UsernamePasswordAuthenticationToken hero = createAuthenticationToken("ROLE_HERO"); + private UsernamePasswordAuthenticationToken hero = createAuthenticationToken( + "ROLE_HERO"); - private UsernamePasswordAuthenticationToken createAuthenticationToken(String authority) { - return new UsernamePasswordAuthenticationToken( - "user", "password", + private UsernamePasswordAuthenticationToken createAuthenticationToken( + String authority) { + return new UsernamePasswordAuthenticationToken("user", "password", AuthorityUtils.commaSeparatedStringToAuthorityList(authority)); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestConfigurer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestConfigurer.java index 8570000390..2c4b459dc7 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestConfigurer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestConfigurer.java @@ -24,10 +24,10 @@ import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapt import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; /** - * A {@code RepositoryRestConfigurer} that applies that applies configuration items - * from the {@code spring.data.rest} namespace to Spring Data REST. Also, if a - * {@link Jackson2ObjectMapperBuilder} is available, it is used to configure Spring - * Data REST's {@link ObjectMapper ObjectMappers}. + * A {@code RepositoryRestConfigurer} that applies that applies configuration items from + * the {@code spring.data.rest} namespace to Spring Data REST. Also, if a + * {@link Jackson2ObjectMapperBuilder} is available, it is used to configure Spring Data + * REST's {@link ObjectMapper ObjectMappers}. * * @author Andy Wilkinson * @author Stephane Nicoll diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java index 512998bc03..e186020e34 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java @@ -101,7 +101,7 @@ public class DataSourceAutoConfiguration { @ConditionalOnMissingBean({ DataSource.class, XADataSource.class }) @Import({ DataSourceConfiguration.Tomcat.class, DataSourceConfiguration.Hikari.class, DataSourceConfiguration.Dbcp.class, DataSourceConfiguration.Dbcp2.class, - DataSourceConfiguration.Generic.class}) + DataSourceConfiguration.Generic.class }) protected static class PooledDataSourceConfiguration { } @@ -139,10 +139,12 @@ public class DataSourceAutoConfiguration { } @ConditionalOnProperty(prefix = "spring.datasource", name = "type") - static class ExplicitType { } + static class ExplicitType { + } @Conditional(PooledDataSourceAvailableCondition.class) - static class PooledDataSourceAvailable { } + static class PooledDataSourceAvailable { + } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration.java index ca43235119..9f5c0d3087 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration.java @@ -114,10 +114,10 @@ abstract class DataSourceConfiguration { static class Generic { @Bean - public DataSource dataSource( - DataSourceProperties properties) { + public DataSource dataSource(DataSourceProperties properties) { return properties.initializeDataSourceBuilder().build(); } + } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceProperties.java index ad5ca6bb92..0d8dd371b8 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceProperties.java @@ -166,15 +166,13 @@ public class DataSourceProperties /** * Initialize a {@link DataSourceBuilder} with the state of this instance. - * @return a {@link DataSourceBuilder} initialized with the customizations - * defined on this instance + * @return a {@link DataSourceBuilder} initialized with the customizations defined on + * this instance */ public DataSourceBuilder initializeDataSourceBuilder() { - return DataSourceBuilder.create(getClassLoader()) - .type(getType()) - .driverClassName(determineDriverClassName()) - .url(determineUrl()).username(determineUsername()) - .password(determinePassword()); + return DataSourceBuilder.create(getClassLoader()).type(getType()) + .driverClassName(determineDriverClassName()).url(determineUrl()) + .username(determineUsername()).password(determinePassword()); } public String getName() { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/HikariDriverConfigurationFailureAnalyzer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/HikariDriverConfigurationFailureAnalyzer.java index 71904b48b1..dc552ab1c8 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/HikariDriverConfigurationFailureAnalyzer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/HikariDriverConfigurationFailureAnalyzer.java @@ -22,24 +22,28 @@ import org.springframework.boot.diagnostics.FailureAnalysis; /** * An {@link AbstractFailureAnalyzer} that performs analysis of a Hikari configuration * failure caused by the use of the unsupported 'dataSourceClassName' property. - + * * @author Stephane Nicoll */ -class HikariDriverConfigurationFailureAnalyzer extends AbstractFailureAnalyzer { +class HikariDriverConfigurationFailureAnalyzer + extends AbstractFailureAnalyzer { - static final String EXPECTED_MESSAGE = "both driverClassName and dataSourceClassName are " + - "specified, one or the other should be used"; + private static final String EXPECTED_MESSAGE = "both driverClassName and " + + "dataSourceClassName are specified, one or the other should be used"; @Override - protected FailureAnalysis analyze(Throwable rootFailure, IllegalStateException cause) { + protected FailureAnalysis analyze(Throwable rootFailure, + IllegalStateException cause) { if (!EXPECTED_MESSAGE.equals(cause.getMessage())) { return null; } - return new FailureAnalysis("Configuration of the Hikari connection pool failed: " + - "'dataSourceClassName' is not supported.", - "Spring Boot auto-configures only a driver and can't specify a custom " + - "DataSource. Consider configuring the Hikari DataSource in your " + - "own configuration.", cause); + return new FailureAnalysis( + "Configuration of the Hikari connection pool failed: " + + "'dataSourceClassName' is not supported.", + "Spring Boot auto-configures only a driver and can't specify a custom " + + "DataSource. Consider configuring the Hikari DataSource in " + + "your own configuration.", + cause); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java index bf89963e21..ccea644b9b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java @@ -186,8 +186,8 @@ public class DataSourceAutoConfigurationTests { } /** - * This test makes sure that if no supported data source is present, a datasource - * is still created if "spring.datasource.type" is present. + * This test makes sure that if no supported data source is present, a datasource is + * still created if "spring.datasource.type" is present. */ @Test public void explicitTypeNoSupportedDataSource() { @@ -195,9 +195,9 @@ public class DataSourceAutoConfigurationTests { "spring.datasource.driverClassName:org.hsqldb.jdbcDriver", "spring.datasource.url:jdbc:hsqldb:mem:testdb", "spring.datasource.type:" + SimpleDriverDataSource.class.getName()); - this.context.setClassLoader(new HidePackagesClassLoader( - "org.apache.tomcat", "com.zaxxer.hikari", "org.apache.commons.dbcp", - "org.apache.commons.dbcp2")); + this.context.setClassLoader( + new HidePackagesClassLoader("org.apache.tomcat", "com.zaxxer.hikari", + "org.apache.commons.dbcp", "org.apache.commons.dbcp2")); testExplicitType(); } @@ -329,7 +329,6 @@ public class DataSourceAutoConfigurationTests { this.hiddenPackages = hiddenPackages; } - @Override protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/HikariDriverConfigurationFailureAnalyzerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/HikariDriverConfigurationFailureAnalyzerTests.java index 0d948323c5..d2950d2d05 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/HikariDriverConfigurationFailureAnalyzerTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/HikariDriverConfigurationFailureAnalyzerTests.java @@ -39,11 +39,11 @@ public class HikariDriverConfigurationFailureAnalyzerTests { public void failureAnalysisIsPerformed() { FailureAnalysis failureAnalysis = performAnalysis(TestConfiguration.class); assertThat(failureAnalysis).isNotNull(); - assertThat(failureAnalysis.getDescription()).isEqualTo( - "Configuration of the Hikari connection pool failed: " + - "'dataSourceClassName' is not supported."); - assertThat(failureAnalysis.getAction()).contains( - "Spring Boot auto-configures only a driver"); + assertThat(failureAnalysis.getDescription()) + .isEqualTo("Configuration of the Hikari connection pool failed: " + + "'dataSourceClassName' is not supported."); + assertThat(failureAnalysis.getAction()) + .contains("Spring Boot auto-configures only a driver"); } @Test diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextCustomizer.java b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextCustomizer.java index 1bc409e762..fe3c0b2607 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextCustomizer.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextCustomizer.java @@ -23,7 +23,6 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.boot.context.embedded.AbstractConfigurableEmbeddedServletContainer; -import org.springframework.boot.context.embedded.Ssl; import org.springframework.boot.test.web.client.LocalHostUriTemplateHandler; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.client.TestRestTemplate.HttpClientOption; @@ -86,6 +85,10 @@ class SpringBootTestContextCustomizer implements ContextCustomizer { public static class TestRestTemplateFactory implements FactoryBean, ApplicationContextAware { + private static final HttpClientOption[] DEFAULT_OPTIONS = {}; + + private static final HttpClientOption[] SSL_OPTIONS = { HttpClientOption.SSL }; + private TestRestTemplate object; @Override @@ -93,25 +96,19 @@ class SpringBootTestContextCustomizer implements ContextCustomizer { throws BeansException { RestTemplateBuilder builder = getRestTemplateBuilder(applicationContext); boolean sslEnabled = isSslEnabled(applicationContext); - TestRestTemplate template; - if (sslEnabled) { - template = new TestRestTemplate(builder.build(), null, null, - HttpClientOption.SSL); - } - else { - template = new TestRestTemplate(builder.build()); - } - template.setUriTemplateHandler(new LocalHostUriTemplateHandler( - applicationContext.getEnvironment(), sslEnabled ? "https" : "http")); + TestRestTemplate template = new TestRestTemplate(builder.build(), null, null, + sslEnabled ? SSL_OPTIONS : DEFAULT_OPTIONS); + LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler( + applicationContext.getEnvironment(), sslEnabled ? "https" : "http"); + template.setUriTemplateHandler(handler); this.object = template; } - private boolean isSslEnabled(ApplicationContext applicationContext) { + private boolean isSslEnabled(ApplicationContext context) { try { - Ssl ssl = applicationContext - .getBean(AbstractConfigurableEmbeddedServletContainer.class) - .getSsl(); - return ssl != null && ssl.isEnabled(); + AbstractConfigurableEmbeddedServletContainer container = context + .getBean(AbstractConfigurableEmbeddedServletContainer.class); + return container.getSsl() != null && container.getSsl().isEnabled(); } catch (NoSuchBeanDefinitionException ex) { return false; diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/LocalHostUriTemplateHandler.java b/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/LocalHostUriTemplateHandler.java index dfb6fafa0b..6f2dbcb1e5 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/LocalHostUriTemplateHandler.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/LocalHostUriTemplateHandler.java @@ -39,7 +39,6 @@ public class LocalHostUriTemplateHandler extends RootUriTemplateHandler { /** * Create a new {@code LocalHostUriTemplateHandler} that will generate {@code http} * URIs using the given {@code environment} to determine the port. - * * @param environment the environment used to determine the port */ public LocalHostUriTemplateHandler(Environment environment) { @@ -49,7 +48,6 @@ public class LocalHostUriTemplateHandler extends RootUriTemplateHandler { /** * Create a new {@code LocalHostUriTemplateHandler} the will generate URIs with the * given {@code scheme} and use the given {@code environment} to determine the port. - * * @param environment the environment used to determine the port * @param scheme the scheme of the root uri * @since 1.4.1 diff --git a/spring-boot/src/main/java/org/springframework/boot/ApplicationInfo.java b/spring-boot/src/main/java/org/springframework/boot/ApplicationInfo.java index 08b38d4f43..ba6b56c9a5 100644 --- a/spring-boot/src/main/java/org/springframework/boot/ApplicationInfo.java +++ b/spring-boot/src/main/java/org/springframework/boot/ApplicationInfo.java @@ -31,7 +31,8 @@ public final class ApplicationInfo { private final Banner banner; - protected ApplicationInfo(SpringApplication application, ApplicationArguments applicationArguments, Banner banner) { + protected ApplicationInfo(SpringApplication application, + ApplicationArguments applicationArguments, Banner banner) { this.mainApplicationClass = application.getMainApplicationClass(); this.applicationArguments = applicationArguments; this.banner = banner; diff --git a/spring-boot/src/main/java/org/springframework/boot/diagnostics/FailureAnalyzers.java b/spring-boot/src/main/java/org/springframework/boot/diagnostics/FailureAnalyzers.java index b6a2e1309b..96a90447f9 100644 --- a/spring-boot/src/main/java/org/springframework/boot/diagnostics/FailureAnalyzers.java +++ b/spring-boot/src/main/java/org/springframework/boot/diagnostics/FailureAnalyzers.java @@ -28,6 +28,7 @@ import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.io.support.SpringFactoriesLoader; +import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -53,42 +54,23 @@ public final class FailureAnalyzers { private final List analyzers; - public FailureAnalyzers(ConfigurableApplicationContext context) { - this.classLoader = context.getClassLoader(); - this.analyzers = loadFailureAnalyzers(this.classLoader); - prepareFailureAnalyzers(this.analyzers, context); - } - /** - * Analyze and report the specified {@code failure}. - * - * @param failure the failure to analyze - * @return {@code true} if the failure was handled + * Create a new {@link FailureAnalyzers} instance. + * @param context the source application context + * @since 1.4.1 */ - public boolean analyzeAndReport(Throwable failure) { - FailureAnalysis analysis = analyze(failure, this.analyzers); - return report(analysis, this.classLoader); + public FailureAnalyzers(ConfigurableApplicationContext context) { + this(context, null); } - /** - * Analyze and report the specified {@code failure}. - * - * @param failure the failure to analyze - * @param classLoader the classloader to use - * @param context the context to use - * @return {@code true} if the failure was handled - * @deprecated in favour of {@link #analyzeAndReport(Throwable)} - */ - @Deprecated - public static boolean analyzeAndReport(Throwable failure, ClassLoader classLoader, - ConfigurableApplicationContext context) { - List analyzers = loadFailureAnalyzers(classLoader); - prepareFailureAnalyzers(analyzers, context); - FailureAnalysis analysis = analyze(failure, analyzers); - return report(analysis, classLoader); + FailureAnalyzers(ConfigurableApplicationContext context, ClassLoader classLoader) { + Assert.notNull(context, "Context must not be null"); + this.classLoader = (classLoader == null ? context.getClassLoader() : classLoader); + this.analyzers = loadFailureAnalyzers(this.classLoader); + prepareFailureAnalyzers(this.analyzers, context); } - private static List loadFailureAnalyzers(ClassLoader classLoader) { + private List loadFailureAnalyzers(ClassLoader classLoader) { List analyzerNames = SpringFactoriesLoader .loadFactoryNames(FailureAnalyzer.class, classLoader); List analyzers = new ArrayList(); @@ -107,15 +89,31 @@ public final class FailureAnalyzers { return analyzers; } - private static void prepareFailureAnalyzers(List analyzers, + private void prepareFailureAnalyzers(List analyzers, ConfigurableApplicationContext context) { for (FailureAnalyzer analyzer : analyzers) { prepareAnalyzer(context, analyzer); } } - private static FailureAnalysis analyze(Throwable failure, - List analyzers) { + private void prepareAnalyzer(ConfigurableApplicationContext context, + FailureAnalyzer analyzer) { + if (analyzer instanceof BeanFactoryAware) { + ((BeanFactoryAware) analyzer).setBeanFactory(context.getBeanFactory()); + } + } + + /** + * Analyze and report the specified {@code failure}. + * @param failure the failure to analyze + * @return {@code true} if the failure was handled + */ + public boolean analyzeAndReport(Throwable failure) { + FailureAnalysis analysis = analyze(failure, this.analyzers); + return report(analysis, this.classLoader); + } + + private FailureAnalysis analyze(Throwable failure, List analyzers) { for (FailureAnalyzer analyzer : analyzers) { FailureAnalysis analysis = analyzer.analyze(failure); if (analysis != null) { @@ -125,15 +123,7 @@ public final class FailureAnalyzers { return null; } - private static void prepareAnalyzer(ConfigurableApplicationContext context, - FailureAnalyzer analyzer) { - if (analyzer instanceof BeanFactoryAware) { - ((BeanFactoryAware) analyzer).setBeanFactory(context.getBeanFactory()); - } - } - - private static boolean report(FailureAnalysis analysis, - ClassLoader classLoader) { + private boolean report(FailureAnalysis analysis, ClassLoader classLoader) { List reporters = SpringFactoriesLoader .loadFactories(FailureAnalysisReporter.class, classLoader); if (analysis == null || reporters.isEmpty()) { @@ -145,4 +135,18 @@ public final class FailureAnalyzers { return true; } + /** + * Analyze and report the specified {@code failure}. + * @param failure the failure to analyze + * @param classLoader the classloader to use + * @param context the context to use + * @return {@code true} if the failure was handled + * @deprecated as of 1.4.1 in favor of {@link #analyzeAndReport(Throwable)} + */ + @Deprecated + public static boolean analyzeAndReport(Throwable failure, ClassLoader classLoader, + ConfigurableApplicationContext context) { + return new FailureAnalyzers(context, classLoader).analyzeAndReport(failure); + } + } diff --git a/spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityManagerFactoryBuilder.java b/spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityManagerFactoryBuilder.java index e8b1f2ce5c..61a57feecf 100644 --- a/spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityManagerFactoryBuilder.java +++ b/spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityManagerFactoryBuilder.java @@ -50,7 +50,8 @@ import org.springframework.util.ResourceUtils; */ public class EntityManagerFactoryBuilder { - private static final Log logger = LogFactory.getLog(EntityManagerFactoryBuilder.class); + private static final Log logger = LogFactory + .getLog(EntityManagerFactoryBuilder.class); private JpaVendorAdapter jpaVendorAdapter; @@ -105,8 +106,8 @@ public class EntityManagerFactoryBuilder { protected String determinePersistenceUnitRootLocation() { if (this.applicationClass != null) { try { - URL mainLocation = this.applicationClass.getProtectionDomain(). - getCodeSource().getLocation(); + URL mainLocation = this.applicationClass.getProtectionDomain() + .getCodeSource().getLocation(); return ResourceUtils.extractJarFileURL(mainLocation).toString(); } catch (Exception ex) { @@ -116,7 +117,6 @@ public class EntityManagerFactoryBuilder { return null; } - /** * A fluent builder for a LocalContainerEntityManagerFactoryBean. */ diff --git a/spring-boot/src/test/java/org/springframework/boot/BannerTests.java b/spring-boot/src/test/java/org/springframework/boot/BannerTests.java index b79b678ebd..59b1833e85 100644 --- a/spring-boot/src/test/java/org/springframework/boot/BannerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/BannerTests.java @@ -101,8 +101,8 @@ public class BannerTests { this.context = application.run(); assertThat(this.context.containsBean("springBootBanner")).isTrue(); assertThat(this.context.containsBean("springApplicationInfo")).isTrue(); - assertThat(this.context.getBean( - "springApplicationInfo", ApplicationInfo.class).getBanner()).isNotNull(); + assertThat(this.context.getBean("springApplicationInfo", ApplicationInfo.class) + .getBanner()).isNotNull(); } @Test @@ -132,8 +132,8 @@ public class BannerTests { application.setWebEnvironment(false); this.context = application.run(); assertThat(this.context.containsBean("springBootBanner")).isFalse(); - assertThat(this.context.getBean("springApplicationInfo", ApplicationInfo.class). - getBanner()).isNull(); + assertThat(this.context.getBean("springApplicationInfo", ApplicationInfo.class) + .getBanner()).isNull(); } @Test @@ -150,8 +150,8 @@ public class BannerTests { this.context = application.run(); assertThat(this.out.toString()).contains("I printed a deprecated banner"); assertThat(this.context.containsBean("springBootBanner")).isFalse(); - assertThat(this.context.getBean("springApplicationInfo", ApplicationInfo.class). - getBanner()).isNull(); + assertThat(this.context.getBean("springApplicationInfo", ApplicationInfo.class) + .getBanner()).isNull(); } static class DummyBanner implements Banner { diff --git a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index 5c1cd44b3f..16d2ca22a4 100644 --- a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -785,8 +785,8 @@ public class SpringApplicationTests { application.setWebEnvironment(false); this.context = application.run("foo"); ApplicationInfo applicationInfo = this.context.getBean(ApplicationInfo.class); - assertThat(application.getMainApplicationClass()).isEqualTo(application - .getMainApplicationClass()); + assertThat(application.getMainApplicationClass()) + .isEqualTo(application.getMainApplicationClass()); assertThat(applicationInfo.getApplicationArguments()).isNotNull(); assertThat(applicationInfo.getApplicationArguments().getNonOptionArgs()) .containsExactly("foo"); diff --git a/spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersTests.java b/spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersTests.java index 075c1cbe11..eae067faf1 100644 --- a/spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersTests.java @@ -68,24 +68,10 @@ public class FailureAnalyzersTests { verify(failureAnalyzer, times(1)).analyze(failure); } - private void analyzeAndReport(final String factoriesName, Throwable failure) { + private void analyzeAndReport(String factoriesName, Throwable failure) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - context.setClassLoader( - new ClassLoader(getClass().getClassLoader()) { - - @Override - public Enumeration getResources(String name) throws IOException { - if ("META-INF/spring.factories".equals(name)) { - return super.getResources( - "failure-analyzers-tests/" + factoriesName); - } - else { - return super.getResources(name); - } - } - - }); - new FailureAnalyzers(context).analyzeAndReport(failure); + ClassLoader classLoader = new CustomSpringFactoriesClassLoader(factoriesName); + new FailureAnalyzers(context, classLoader).analyzeAndReport(failure); } static class BasicFailureAnalyzer implements FailureAnalyzer { @@ -124,4 +110,24 @@ public class FailureAnalyzersTests { } + static class CustomSpringFactoriesClassLoader extends ClassLoader { + + private final String factoriesName; + + CustomSpringFactoriesClassLoader(String factoriesName) { + super(CustomSpringFactoriesClassLoader.class.getClassLoader()); + this.factoriesName = factoriesName; + } + + @Override + public Enumeration getResources(String name) throws IOException { + if ("META-INF/spring.factories".equals(name)) { + return super.getResources( + "failure-analyzers-tests/" + this.factoriesName); + } + return super.getResources(name); + } + + } + }