diff --git a/docs/howto.md b/docs/howto.md index 31dcd13ae28..eb2bf041c30 100644 --- a/docs/howto.md +++ b/docs/howto.md @@ -935,7 +935,7 @@ additional ones: * declarative for all applications by adding a `MTEA-INF/spring.factories` and packaging a jar file that the applications all use as a library - + Any `ApplicationContextInitializer` registered programmatically or via `spring.factories` that is also an `ApplicationListener` will be automatically cross registered (and vice versa for listeners that are diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementSecurityAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementSecurityAutoConfiguration.java index 58d79722bcc..93d5200ed40 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementSecurityAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementSecurityAutoConfiguration.java @@ -128,7 +128,8 @@ public class ManagementSecurityAutoConfiguration { IgnoredRequestConfigurer ignoring = builder.ignoring(); // The ignores are not cumulative, so to prevent overwriting the defaults we // add them back. - List ignored = SpringBootWebSecurityConfiguration.getIgnored(this.security); + List ignored = SpringBootWebSecurityConfiguration + .getIgnored(this.security); ignored.addAll(Arrays.asList(getEndpointPaths(this.endpointHandlerMapping, false))); if (!this.management.getSecurity().isEnabled()) { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java index f792a0b5035..c4705fa39d6 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java @@ -142,7 +142,8 @@ public class EndpointWebMvcAutoConfigurationTests { @Test public void contextPath() throws Exception { - EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.contextPath:/test"); + EnvironmentTestUtils.addEnvironment(this.applicationContext, + "management.contextPath:/test"); this.applicationContext.register(RootConfig.class, PropertyPlaceholderAutoConfiguration.class, ManagementServerPropertiesAutoConfiguration.class, diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java index 8265180733a..8c81ffc8d6c 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java @@ -59,7 +59,8 @@ public class EnvironmentMvcEndpointTests { @Before public void setUp() { this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build(); - EnvironmentTestUtils.addEnvironment((ConfigurableApplicationContext) this.context, "foo:bar"); + EnvironmentTestUtils.addEnvironment( + (ConfigurableApplicationContext) this.context, "foo:bar"); } @Test diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/JolokiaEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/JolokiaEndpointTests.java index 12514640730..a1a52875dee 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/JolokiaEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/JolokiaEndpointTests.java @@ -66,7 +66,8 @@ public class JolokiaEndpointTests { @Before public void setUp() { this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build(); - EnvironmentTestUtils.addEnvironment((ConfigurableApplicationContext) this.context, "foo:bar"); + EnvironmentTestUtils.addEnvironment( + (ConfigurableApplicationContext) this.context, "foo:bar"); } @Test diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java index c4a5a1b9493..93f6653124a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java @@ -15,6 +15,7 @@ */ package org.springframework.boot.autoconfigure; + import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -37,7 +38,6 @@ import org.springframework.core.type.classreading.MetadataReader; import org.springframework.core.type.classreading.MetadataReaderFactory; import org.springframework.util.Assert; - /** * Sort {@link EnableAutoConfiguration auto-configuration} classes into priority order by * reading {@link Ordered} and {@link AutoConfigureAfter} annotations (without loading diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java index b5b6bbbc917..5955fb1d849 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java @@ -27,7 +27,8 @@ import org.springframework.security.authentication.AuthenticationManager; @Configuration @ConditionalOnClass(AuthenticationManager.class) @EnableConfigurationProperties -@Import({ SpringBootWebSecurityConfiguration.class, AuthenticationManagerConfiguration.class }) +@Import({ SpringBootWebSecurityConfiguration.class, + AuthenticationManagerConfiguration.class }) public class SecurityAutoConfiguration { @Bean(name = "org.springframework.autoconfigure.security.SecurityProperties") diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoconfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoconfigurationTests.java index 042651e6740..0a7d1b1d36f 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoconfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoconfigurationTests.java @@ -65,9 +65,10 @@ public class RabbitAutoconfigurationTests { public void testRabbitTemplateWithOverrides() { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class); - EnvironmentTestUtils.addEnvironment(this.context, "spring.rabbitmq.host:remote-server", - "spring.rabbitmq.port:9000", "spring.rabbitmq.username:alice", - "spring.rabbitmq.password:secret", "spring.rabbitmq.virtual_host:/vhost"); + EnvironmentTestUtils.addEnvironment(this.context, + "spring.rabbitmq.host:remote-server", "spring.rabbitmq.port:9000", + "spring.rabbitmq.username:alice", "spring.rabbitmq.password:secret", + "spring.rabbitmq.virtual_host:/vhost"); this.context.refresh(); CachingConnectionFactory connectionFactory = this.context .getBean(CachingConnectionFactory.class); @@ -80,7 +81,8 @@ public class RabbitAutoconfigurationTests { public void testRabbitTemplateEmptyVirtualHost() { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class); - EnvironmentTestUtils.addEnvironment(this.context, "spring.rabbitmq.virtual_host:"); + EnvironmentTestUtils + .addEnvironment(this.context, "spring.rabbitmq.virtual_host:"); this.context.refresh(); CachingConnectionFactory connectionFactory = this.context .getBean(CachingConnectionFactory.class); @@ -91,7 +93,8 @@ public class RabbitAutoconfigurationTests { public void testRabbitTemplateVirtualHostMissingSlash() { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class); - EnvironmentTestUtils.addEnvironment(this.context, "spring.rabbitmq.virtual_host:foo"); + EnvironmentTestUtils.addEnvironment(this.context, + "spring.rabbitmq.virtual_host:foo"); this.context.refresh(); CachingConnectionFactory connectionFactory = this.context .getBean(CachingConnectionFactory.class); @@ -102,7 +105,8 @@ public class RabbitAutoconfigurationTests { public void testRabbitTemplateDefaultVirtualHost() { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class); - EnvironmentTestUtils.addEnvironment(this.context, "spring.rabbitmq.virtual_host:/"); + EnvironmentTestUtils.addEnvironment(this.context, + "spring.rabbitmq.virtual_host:/"); this.context.refresh(); CachingConnectionFactory connectionFactory = this.context .getBean(CachingConnectionFactory.class); @@ -126,7 +130,8 @@ public class RabbitAutoconfigurationTests { public void testStaticQueues() { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class); - EnvironmentTestUtils.addEnvironment(this.context, "spring.rabbitmq.dynamic:false"); + EnvironmentTestUtils + .addEnvironment(this.context, "spring.rabbitmq.dynamic:false"); this.context.refresh(); // There should NOT be an AmqpAdmin bean when dynamic is switch to false this.thrown.expect(NoSuchBeanDefinitionException.class); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/aop/AopAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/aop/AopAutoConfigurationTests.java index ec6d3c9a48e..3e1f027a10e 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/aop/AopAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/aop/AopAutoConfigurationTests.java @@ -56,7 +56,8 @@ public class AopAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestConfiguration.class, AopAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); - EnvironmentTestUtils.addEnvironment(this.context, "spring.aop.proxyTargetClass:true"); + EnvironmentTestUtils.addEnvironment(this.context, + "spring.aop.proxyTargetClass:true"); this.context.refresh(); TestAspect aspect = this.context.getBean(TestAspect.class); assertFalse(aspect.isCalled()); @@ -70,7 +71,8 @@ public class AopAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext(); this.context.register(TestConfiguration.class, AopAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); - EnvironmentTestUtils.addEnvironment(this.context, "spring.aop.proxyTargetClass:false"); + EnvironmentTestUtils.addEnvironment(this.context, + "spring.aop.proxyTargetClass:false"); this.context.refresh(); TestAspect aspect = this.context.getBean(TestAspect.class); assertFalse(aspect.isCalled()); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java index eeec16f78e5..d37a7b67da5 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java @@ -56,7 +56,8 @@ public class TomcatDataSourceConfigurationTests { @Test public void testDataSourcePropertiesOverridden() throws Exception { this.context.register(TomcatDataSourceConfiguration.class); - EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.url:jdbc:foo//bar/spam"); + EnvironmentTestUtils.addEnvironment(this.context, + "spring.datasource.url:jdbc:foo//bar/spam"); this.context.refresh(); assertEquals("jdbc:foo//bar/spam", this.context.getBean(org.apache.tomcat.jdbc.pool.DataSource.class) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsTemplateAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsTemplateAutoConfigurationTests.java index 48cede436d4..15b664ca79c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsTemplateAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsTemplateAutoConfigurationTests.java @@ -118,7 +118,8 @@ public class JmsTemplateAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext(); this.context .register(TestConfiguration.class, JmsTemplateAutoConfiguration.class); - EnvironmentTestUtils.addEnvironment(this.context, "spring.jms.pubSubDomain:false"); + EnvironmentTestUtils + .addEnvironment(this.context, "spring.jms.pubSubDomain:false"); this.context.refresh(); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); ActiveMQConnectionFactory connectionFactory = this.context @@ -134,7 +135,8 @@ public class JmsTemplateAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext(); this.context .register(TestConfiguration.class, JmsTemplateAutoConfiguration.class); - EnvironmentTestUtils.addEnvironment(this.context, "spring.activemq.inMemory:false"); + EnvironmentTestUtils.addEnvironment(this.context, + "spring.activemq.inMemory:false"); this.context.refresh(); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); ActiveMQConnectionFactory connectionFactory = this.context @@ -153,7 +155,8 @@ public class JmsTemplateAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext(); this.context .register(TestConfiguration.class, JmsTemplateAutoConfiguration.class); - EnvironmentTestUtils.addEnvironment(this.context, "spring.activemq.inMemory:false", + EnvironmentTestUtils.addEnvironment(this.context, + "spring.activemq.inMemory:false", "spring.activemq.brokerURL:tcp://remote-host:10000"); this.context.refresh(); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java index ede5befdf5f..86e394a72b1 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java @@ -38,8 +38,9 @@ public class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigura @Test public void testCustomNamingStrategy() throws Exception { - EnvironmentTestUtils.addEnvironment(this.context, "spring.jpa.hibernate.namingstrategy:" - + "org.hibernate.cfg.EJB3NamingStrategy"); + EnvironmentTestUtils.addEnvironment(this.context, + "spring.jpa.hibernate.namingstrategy:" + + "org.hibernate.cfg.EJB3NamingStrategy"); setupTestConfiguration(); this.context.refresh(); LocalContainerEntityManagerFactoryBean bean = this.context diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java index 718b8f8c5d3..c4f0b436365 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java @@ -86,8 +86,8 @@ public class ServerPropertiesAutoConfigurationTests { this.context = new AnnotationConfigEmbeddedWebApplicationContext(); this.context.register(Config.class, ServerPropertiesAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); - EnvironmentTestUtils.addEnvironment(this.context, "server.tomcat.basedir:target/foo", - "server.port:9000"); + EnvironmentTestUtils.addEnvironment(this.context, + "server.tomcat.basedir:target/foo", "server.port:9000"); this.context.refresh(); ServerProperties server = this.context.getBean(ServerProperties.class); assertNotNull(server); diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/InitCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/InitCommand.java index ab50ca7b680..e1b556ec048 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/InitCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/InitCommand.java @@ -75,8 +75,8 @@ public class InitCommand extends OptionParsingCommand { ClassLoader loader = Thread.currentThread().getContextClassLoader(); boolean enhanced = false; - SourceOptions sourceOptions = new SourceOptions(options, loader, "init.groovy", - "spring.groovy"); + SourceOptions sourceOptions = new SourceOptions(options, loader, + "init.groovy", "spring.groovy"); String[] sources = sourceOptions.getSourcesArray(); if (!(loader instanceof GroovyClassLoader)) { diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/testrunner/TestRunner.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/testrunner/TestRunner.java index 8a980c7aa24..2871902d752 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/testrunner/TestRunner.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/testrunner/TestRunner.java @@ -43,7 +43,8 @@ public class TestRunner { * @param sources * @param args */ - public TestRunner(TestRunnerConfiguration configuration, String[] sources, String[] args) { + public TestRunner(TestRunnerConfiguration configuration, String[] sources, + String[] args) { this.sources = sources.clone(); this.compiler = new GroovyCompiler(configuration); } diff --git a/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleSecureApplication.java b/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleSecureApplication.java index 9d72d44af1c..58d25dcfde8 100644 --- a/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleSecureApplication.java +++ b/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleSecureApplication.java @@ -41,7 +41,8 @@ public class SampleSecureApplication implements CommandLineRunner { .commaSeparatedStringToAuthorityList("ROLE_USER"))); try { System.out.println(service.secure()); - } finally { + } + finally { SecurityContextHolder.clearContext(); } } diff --git a/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleService.java b/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleService.java index a5b02eb6767..82887733c4a 100644 --- a/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleService.java +++ b/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleService.java @@ -22,11 +22,11 @@ import org.springframework.stereotype.Service; /** * @author Dave Syer - * + * */ @Service public class SampleService { - + @Secured("ROLE_USER") public String secure() { return "Hello Security"; diff --git a/spring-boot-samples/spring-boot-sample-servlet/src/main/java/sample/servlet/SampleServletApplication.java b/spring-boot-samples/spring-boot-sample-servlet/src/main/java/sample/servlet/SampleServletApplication.java index 5eb5b0a5a99..61456fc900e 100644 --- a/spring-boot-samples/spring-boot-sample-servlet/src/main/java/sample/servlet/SampleServletApplication.java +++ b/spring-boot-samples/spring-boot-sample-servlet/src/main/java/sample/servlet/SampleServletApplication.java @@ -51,7 +51,7 @@ public class SampleServletApplication extends SpringBootServletInitializer { public static void main(String[] args) throws Exception { SpringApplication.run(SampleServletApplication.class, args); } - + @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(SampleServletApplication.class); diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/logback.xml b/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/logback.xml index ef753364ed2..620db4a2ac0 100644 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/logback.xml +++ b/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/logback.xml @@ -1,8 +1,8 @@ - - + + - + diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java index fac4d445d40..4eefb8cda7b 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java @@ -74,6 +74,7 @@ import org.springframework.boot.loader.util.SystemPropertyUtils; * * * @author Dave Syer + * @author Janne Valkealahti */ public class PropertiesLauncher extends Launcher { @@ -326,27 +327,39 @@ public class PropertiesLauncher extends Launcher { @Override protected ClassLoader createClassLoader(List archives) throws Exception { ClassLoader loader = super.createClassLoader(archives); - String classLoaderType = getProperty("loader.classLoader"); - if (classLoaderType != null) { - Class type = Class.forName(classLoaderType, true, loader); - try { - loader = (ClassLoader) type.getConstructor(ClassLoader.class) - .newInstance(loader); - } - catch (NoSuchMethodException e) { - try { - loader = (ClassLoader) type.getConstructor(URL[].class, - ClassLoader.class).newInstance(new URL[0], loader); - } - catch (NoSuchMethodException ex) { - loader = (ClassLoader) type.newInstance(); - } - } - this.logger.info("Using custom class loader: " + classLoaderType); + String customLoaderClassName = getProperty("loader.classLoader"); + if (customLoaderClassName != null) { + loader = wrapWithCustomClassLoader(loader, customLoaderClassName); + this.logger.info("Using custom class loader: " + customLoaderClassName); } return loader; } + @SuppressWarnings("unchecked") + private ClassLoader wrapWithCustomClassLoader(ClassLoader parent, + String loaderClassName) throws Exception { + + Class loaderClass = (Class) Class.forName( + loaderClassName, true, parent); + + try { + return loaderClass.getConstructor(ClassLoader.class).newInstance(parent); + } + catch (NoSuchMethodException e) { + // Ignore and try with URLs + } + + try { + return loaderClass.getConstructor(URL[].class, ClassLoader.class) + .newInstance(new URL[0], parent); + } + catch (NoSuchMethodException ex) { + // Ignore and try without any arguments + } + + return loaderClass.newInstance(); + } + private String getProperty(String propertyKey) throws Exception { return getProperty(propertyKey, null); } @@ -356,18 +369,21 @@ public class PropertiesLauncher extends Launcher { manifestKey = propertyKey.replace(".", "-"); manifestKey = toCamelCase(manifestKey); } + String property = SystemPropertyUtils.getProperty(propertyKey); if (property != null) { String value = SystemPropertyUtils.resolvePlaceholders(property); this.logger.fine("Property '" + propertyKey + "' from environment: " + value); return value; } + if (this.properties.containsKey(propertyKey)) { String value = SystemPropertyUtils.resolvePlaceholders(this.properties .getProperty(propertyKey)); this.logger.fine("Property '" + propertyKey + "' from properties: " + value); return value; } + try { // Prefer home dir for MANIFEST if there is one Manifest manifest = new ExplodedArchive(this.home).getManifest(); @@ -379,7 +395,9 @@ public class PropertiesLauncher extends Launcher { } } catch (IllegalStateException ex) { + // Ignore } + // Otherwise try the parent archive Manifest manifest = createArchive().getManifest(); if (manifest != null) { diff --git a/spring-boot/src/main/java/org/springframework/boot/context/listener/EnvironmentDelegateApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/context/listener/EnvironmentDelegateApplicationListener.java index 3c6f1ed8f0c..55ccc5941f3 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/listener/EnvironmentDelegateApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/listener/EnvironmentDelegateApplicationListener.java @@ -50,6 +50,7 @@ public class EnvironmentDelegateApplicationListener implements private SimpleApplicationEventMulticaster multicaster; + @Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof SpringApplicationEnvironmentAvailableEvent) { List> delegates = getListeners(((SpringApplicationEnvironmentAvailableEvent) event) diff --git a/spring-boot/src/test/java/org/springframework/boot/context/initializer/ContextIdApplicationContextInitializerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/initializer/ContextIdApplicationContextInitializerTests.java index 502d987dd8f..d91fd52c5ee 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/initializer/ContextIdApplicationContextInitializerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/initializer/ContextIdApplicationContextInitializerTests.java @@ -42,7 +42,8 @@ public class ContextIdApplicationContextInitializerTests { @Test public void testNameAndPort() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); - EnvironmentTestUtils.addEnvironment(context, "spring.application.name:foo", "PORT:8080"); + EnvironmentTestUtils.addEnvironment(context, "spring.application.name:foo", + "PORT:8080"); this.initializer.initialize(context); assertEquals("foo:8080", context.getId()); } @@ -59,8 +60,9 @@ public class ContextIdApplicationContextInitializerTests { @Test public void testCloudFoundry() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); - EnvironmentTestUtils.addEnvironment(context, "spring.config.name:foo", "PORT:8080", - "vcap.application.name:bar", "vcap.application.instance_index:2"); + EnvironmentTestUtils.addEnvironment(context, "spring.config.name:foo", + "PORT:8080", "vcap.application.name:bar", + "vcap.application.instance_index:2"); this.initializer.initialize(context); assertEquals("bar:2", context.getId()); } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/initializer/EnvironmentDelegateApplicationContextInitializerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/initializer/EnvironmentDelegateApplicationContextInitializerTests.java index 85fccd47596..313c2f431d6 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/initializer/EnvironmentDelegateApplicationContextInitializerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/initializer/EnvironmentDelegateApplicationContextInitializerTests.java @@ -46,9 +46,8 @@ public class EnvironmentDelegateApplicationContextInitializerTests { @Test public void orderedInitialize() throws Exception { StaticApplicationContext context = new StaticApplicationContext(); - EnvironmentTestUtils.addEnvironment(context, - "context.initializer.classes:" + MockInitB.class.getName() + "," - + MockInitA.class.getName()); + EnvironmentTestUtils.addEnvironment(context, "context.initializer.classes:" + + MockInitB.class.getName() + "," + MockInitA.class.getName()); this.initializer.initialize(context); assertThat(context.getBeanFactory().getSingleton("a"), equalTo((Object) "a")); assertThat(context.getBeanFactory().getSingleton("b"), equalTo((Object) "b")); @@ -79,8 +78,8 @@ public class EnvironmentDelegateApplicationContextInitializerTests { @Test public void notAnInitializerClass() throws Exception { StaticApplicationContext context = new StaticApplicationContext(); - EnvironmentTestUtils.addEnvironment(context, - "context.initializer.classes:" + Object.class.getName()); + EnvironmentTestUtils.addEnvironment(context, "context.initializer.classes:" + + Object.class.getName()); this.thrown.expect(IllegalArgumentException.class); this.initializer.initialize(context); } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/listener/FileEncodingApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/listener/FileEncodingApplicationListenerTests.java index 00094f00119..64b5ba2b18e 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/listener/FileEncodingApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/listener/FileEncodingApplicationListenerTests.java @@ -25,6 +25,8 @@ import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.StandardEnvironment; /** + * Tests for {@link FileEncodingApplicationListener}. + * * @author Dave Syer */ public class FileEncodingApplicationListenerTests { @@ -36,7 +38,8 @@ public class FileEncodingApplicationListenerTests { @Test(expected = IllegalStateException.class) public void testIllegalState() { - EnvironmentTestUtils.addEnviroment(this.environment, "spring.mandatory_file_encoding:FOO"); + EnvironmentTestUtils.addEnviroment(this.environment, + "spring.mandatory_file_encoding:FOO"); this.initializer.onApplicationEvent(this.event); } @@ -48,8 +51,8 @@ public class FileEncodingApplicationListenerTests { @Test public void testSunnyDayMandated() { Assume.assumeNotNull(System.getProperty("file.encoding")); - EnvironmentTestUtils.addEnviroment(this.environment, "spring.mandatory_file_encoding:" - + System.getProperty("file.encoding")); + EnvironmentTestUtils.addEnviroment(this.environment, + "spring.mandatory_file_encoding:" + System.getProperty("file.encoding")); this.initializer.onApplicationEvent(this.event); } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/listener/LoggingApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/listener/LoggingApplicationListenerTests.java index ee62f9e3a87..6aeebbc5cb6 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/listener/LoggingApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/listener/LoggingApplicationListenerTests.java @@ -108,7 +108,8 @@ public class LoggingApplicationListenerTests { @Test public void testOverrideConfigDoesNotExist() throws Exception { - EnvironmentTestUtils.addEnvironment(this.context, "logging.config: doesnotexist.xml"); + EnvironmentTestUtils.addEnvironment(this.context, + "logging.config: doesnotexist.xml"); this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader()); // Should not throw diff --git a/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java b/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java index c0ced6e9bd6..4b621cc00b7 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java @@ -184,7 +184,8 @@ public class EnableConfigurationPropertiesTests { @Test public void testCollectionPropertiesBindingFromYamlArray() { this.context.register(TestConfiguration.class); - EnvironmentTestUtils.addEnvironment(this.context, "name:foo", "list[0]:1", "list[1]:2"); + EnvironmentTestUtils.addEnvironment(this.context, "name:foo", "list[0]:1", + "list[1]:2"); this.context.refresh(); assertEquals(2, this.context.getBean(TestProperties.class).getList().size()); } @@ -227,7 +228,8 @@ public class EnableConfigurationPropertiesTests { @Test public void testBindingDirectlyToFileResolvedFromEnvironment() { - EnvironmentTestUtils.addEnvironment(this.context, "binding.location:classpath:other.yml"); + EnvironmentTestUtils.addEnvironment(this.context, + "binding.location:classpath:other.yml"); this.context.register(ResourceBindingProperties.class, TestConfiguration.class); this.context.refresh(); assertEquals(1, @@ -317,7 +319,8 @@ public class EnableConfigurationPropertiesTests { @Test public void testMultipleExplicitTypes() throws Exception { - EnvironmentTestUtils.addEnvironment(this.context, "external.name:foo", "another.name:bar"); + EnvironmentTestUtils.addEnvironment(this.context, "external.name:foo", + "another.name:bar"); this.context.register(FurtherExampleConfig.class); this.context.refresh(); assertEquals("foo", this.context.getBean(External.class).getName());