Polish
This commit is contained in:
parent
26d900f3ad
commit
47da8a817a
|
|
@ -128,7 +128,8 @@ public class ManagementSecurityAutoConfiguration {
|
||||||
IgnoredRequestConfigurer ignoring = builder.ignoring();
|
IgnoredRequestConfigurer ignoring = builder.ignoring();
|
||||||
// The ignores are not cumulative, so to prevent overwriting the defaults we
|
// The ignores are not cumulative, so to prevent overwriting the defaults we
|
||||||
// add them back.
|
// add them back.
|
||||||
List<String> ignored = SpringBootWebSecurityConfiguration.getIgnored(this.security);
|
List<String> ignored = SpringBootWebSecurityConfiguration
|
||||||
|
.getIgnored(this.security);
|
||||||
ignored.addAll(Arrays.asList(getEndpointPaths(this.endpointHandlerMapping,
|
ignored.addAll(Arrays.asList(getEndpointPaths(this.endpointHandlerMapping,
|
||||||
false)));
|
false)));
|
||||||
if (!this.management.getSecurity().isEnabled()) {
|
if (!this.management.getSecurity().isEnabled()) {
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,8 @@ public class EndpointWebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contextPath() throws Exception {
|
public void contextPath() throws Exception {
|
||||||
EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.contextPath:/test");
|
EnvironmentTestUtils.addEnvironment(this.applicationContext,
|
||||||
|
"management.contextPath:/test");
|
||||||
this.applicationContext.register(RootConfig.class,
|
this.applicationContext.register(RootConfig.class,
|
||||||
PropertyPlaceholderAutoConfiguration.class,
|
PropertyPlaceholderAutoConfiguration.class,
|
||||||
ManagementServerPropertiesAutoConfiguration.class,
|
ManagementServerPropertiesAutoConfiguration.class,
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,8 @@ public class EnvironmentMvcEndpointTests {
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
|
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
|
||||||
EnvironmentTestUtils.addEnvironment((ConfigurableApplicationContext) this.context, "foo:bar");
|
EnvironmentTestUtils.addEnvironment(
|
||||||
|
(ConfigurableApplicationContext) this.context, "foo:bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,8 @@ public class JolokiaEndpointTests {
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
|
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
|
||||||
EnvironmentTestUtils.addEnvironment((ConfigurableApplicationContext) this.context, "foo:bar");
|
EnvironmentTestUtils.addEnvironment(
|
||||||
|
(ConfigurableApplicationContext) this.context, "foo:bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure;
|
package org.springframework.boot.autoconfigure;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
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.core.type.classreading.MetadataReaderFactory;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort {@link EnableAutoConfiguration auto-configuration} classes into priority order by
|
* Sort {@link EnableAutoConfiguration auto-configuration} classes into priority order by
|
||||||
* reading {@link Ordered} and {@link AutoConfigureAfter} annotations (without loading
|
* reading {@link Ordered} and {@link AutoConfigureAfter} annotations (without loading
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,8 @@ import org.springframework.security.authentication.AuthenticationManager;
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass(AuthenticationManager.class)
|
@ConditionalOnClass(AuthenticationManager.class)
|
||||||
@EnableConfigurationProperties
|
@EnableConfigurationProperties
|
||||||
@Import({ SpringBootWebSecurityConfiguration.class, AuthenticationManagerConfiguration.class })
|
@Import({ SpringBootWebSecurityConfiguration.class,
|
||||||
|
AuthenticationManagerConfiguration.class })
|
||||||
public class SecurityAutoConfiguration {
|
public class SecurityAutoConfiguration {
|
||||||
|
|
||||||
@Bean(name = "org.springframework.autoconfigure.security.SecurityProperties")
|
@Bean(name = "org.springframework.autoconfigure.security.SecurityProperties")
|
||||||
|
|
|
||||||
|
|
@ -65,9 +65,10 @@ public class RabbitAutoconfigurationTests {
|
||||||
public void testRabbitTemplateWithOverrides() {
|
public void testRabbitTemplateWithOverrides() {
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class);
|
this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class);
|
||||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.rabbitmq.host:remote-server",
|
EnvironmentTestUtils.addEnvironment(this.context,
|
||||||
"spring.rabbitmq.port:9000", "spring.rabbitmq.username:alice",
|
"spring.rabbitmq.host:remote-server", "spring.rabbitmq.port:9000",
|
||||||
"spring.rabbitmq.password:secret", "spring.rabbitmq.virtual_host:/vhost");
|
"spring.rabbitmq.username:alice", "spring.rabbitmq.password:secret",
|
||||||
|
"spring.rabbitmq.virtual_host:/vhost");
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
CachingConnectionFactory connectionFactory = this.context
|
CachingConnectionFactory connectionFactory = this.context
|
||||||
.getBean(CachingConnectionFactory.class);
|
.getBean(CachingConnectionFactory.class);
|
||||||
|
|
@ -80,7 +81,8 @@ public class RabbitAutoconfigurationTests {
|
||||||
public void testRabbitTemplateEmptyVirtualHost() {
|
public void testRabbitTemplateEmptyVirtualHost() {
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class);
|
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();
|
this.context.refresh();
|
||||||
CachingConnectionFactory connectionFactory = this.context
|
CachingConnectionFactory connectionFactory = this.context
|
||||||
.getBean(CachingConnectionFactory.class);
|
.getBean(CachingConnectionFactory.class);
|
||||||
|
|
@ -91,7 +93,8 @@ public class RabbitAutoconfigurationTests {
|
||||||
public void testRabbitTemplateVirtualHostMissingSlash() {
|
public void testRabbitTemplateVirtualHostMissingSlash() {
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class);
|
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();
|
this.context.refresh();
|
||||||
CachingConnectionFactory connectionFactory = this.context
|
CachingConnectionFactory connectionFactory = this.context
|
||||||
.getBean(CachingConnectionFactory.class);
|
.getBean(CachingConnectionFactory.class);
|
||||||
|
|
@ -102,7 +105,8 @@ public class RabbitAutoconfigurationTests {
|
||||||
public void testRabbitTemplateDefaultVirtualHost() {
|
public void testRabbitTemplateDefaultVirtualHost() {
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class);
|
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();
|
this.context.refresh();
|
||||||
CachingConnectionFactory connectionFactory = this.context
|
CachingConnectionFactory connectionFactory = this.context
|
||||||
.getBean(CachingConnectionFactory.class);
|
.getBean(CachingConnectionFactory.class);
|
||||||
|
|
@ -126,7 +130,8 @@ public class RabbitAutoconfigurationTests {
|
||||||
public void testStaticQueues() {
|
public void testStaticQueues() {
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class);
|
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();
|
this.context.refresh();
|
||||||
// There should NOT be an AmqpAdmin bean when dynamic is switch to false
|
// There should NOT be an AmqpAdmin bean when dynamic is switch to false
|
||||||
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,8 @@ public class AopAutoConfigurationTests {
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
this.context.register(TestConfiguration.class, AopAutoConfiguration.class,
|
this.context.register(TestConfiguration.class, AopAutoConfiguration.class,
|
||||||
PropertyPlaceholderAutoConfiguration.class);
|
PropertyPlaceholderAutoConfiguration.class);
|
||||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.aop.proxyTargetClass:true");
|
EnvironmentTestUtils.addEnvironment(this.context,
|
||||||
|
"spring.aop.proxyTargetClass:true");
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
TestAspect aspect = this.context.getBean(TestAspect.class);
|
TestAspect aspect = this.context.getBean(TestAspect.class);
|
||||||
assertFalse(aspect.isCalled());
|
assertFalse(aspect.isCalled());
|
||||||
|
|
@ -70,7 +71,8 @@ public class AopAutoConfigurationTests {
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
this.context.register(TestConfiguration.class, AopAutoConfiguration.class,
|
this.context.register(TestConfiguration.class, AopAutoConfiguration.class,
|
||||||
PropertyPlaceholderAutoConfiguration.class);
|
PropertyPlaceholderAutoConfiguration.class);
|
||||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.aop.proxyTargetClass:false");
|
EnvironmentTestUtils.addEnvironment(this.context,
|
||||||
|
"spring.aop.proxyTargetClass:false");
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
TestAspect aspect = this.context.getBean(TestAspect.class);
|
TestAspect aspect = this.context.getBean(TestAspect.class);
|
||||||
assertFalse(aspect.isCalled());
|
assertFalse(aspect.isCalled());
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,8 @@ public class TomcatDataSourceConfigurationTests {
|
||||||
@Test
|
@Test
|
||||||
public void testDataSourcePropertiesOverridden() throws Exception {
|
public void testDataSourcePropertiesOverridden() throws Exception {
|
||||||
this.context.register(TomcatDataSourceConfiguration.class);
|
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();
|
this.context.refresh();
|
||||||
assertEquals("jdbc:foo//bar/spam",
|
assertEquals("jdbc:foo//bar/spam",
|
||||||
this.context.getBean(org.apache.tomcat.jdbc.pool.DataSource.class)
|
this.context.getBean(org.apache.tomcat.jdbc.pool.DataSource.class)
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,8 @@ public class JmsTemplateAutoConfigurationTests {
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
this.context
|
this.context
|
||||||
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class);
|
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class);
|
||||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.jms.pubSubDomain:false");
|
EnvironmentTestUtils
|
||||||
|
.addEnvironment(this.context, "spring.jms.pubSubDomain:false");
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
|
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
|
||||||
ActiveMQConnectionFactory connectionFactory = this.context
|
ActiveMQConnectionFactory connectionFactory = this.context
|
||||||
|
|
@ -134,7 +135,8 @@ public class JmsTemplateAutoConfigurationTests {
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
this.context
|
this.context
|
||||||
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class);
|
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class);
|
||||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.activemq.inMemory:false");
|
EnvironmentTestUtils.addEnvironment(this.context,
|
||||||
|
"spring.activemq.inMemory:false");
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
|
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
|
||||||
ActiveMQConnectionFactory connectionFactory = this.context
|
ActiveMQConnectionFactory connectionFactory = this.context
|
||||||
|
|
@ -153,7 +155,8 @@ public class JmsTemplateAutoConfigurationTests {
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
this.context
|
this.context
|
||||||
.register(TestConfiguration.class, JmsTemplateAutoConfiguration.class);
|
.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");
|
"spring.activemq.brokerURL:tcp://remote-host:10000");
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
|
JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,9 @@ public class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigura
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomNamingStrategy() throws Exception {
|
public void testCustomNamingStrategy() throws Exception {
|
||||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.jpa.hibernate.namingstrategy:"
|
EnvironmentTestUtils.addEnvironment(this.context,
|
||||||
+ "org.hibernate.cfg.EJB3NamingStrategy");
|
"spring.jpa.hibernate.namingstrategy:"
|
||||||
|
+ "org.hibernate.cfg.EJB3NamingStrategy");
|
||||||
setupTestConfiguration();
|
setupTestConfiguration();
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
LocalContainerEntityManagerFactoryBean bean = this.context
|
LocalContainerEntityManagerFactoryBean bean = this.context
|
||||||
|
|
|
||||||
|
|
@ -86,8 +86,8 @@ public class ServerPropertiesAutoConfigurationTests {
|
||||||
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
|
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
|
||||||
this.context.register(Config.class, ServerPropertiesAutoConfiguration.class,
|
this.context.register(Config.class, ServerPropertiesAutoConfiguration.class,
|
||||||
PropertyPlaceholderAutoConfiguration.class);
|
PropertyPlaceholderAutoConfiguration.class);
|
||||||
EnvironmentTestUtils.addEnvironment(this.context, "server.tomcat.basedir:target/foo",
|
EnvironmentTestUtils.addEnvironment(this.context,
|
||||||
"server.port:9000");
|
"server.tomcat.basedir:target/foo", "server.port:9000");
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
ServerProperties server = this.context.getBean(ServerProperties.class);
|
ServerProperties server = this.context.getBean(ServerProperties.class);
|
||||||
assertNotNull(server);
|
assertNotNull(server);
|
||||||
|
|
|
||||||
|
|
@ -75,8 +75,8 @@ public class InitCommand extends OptionParsingCommand {
|
||||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||||
boolean enhanced = false;
|
boolean enhanced = false;
|
||||||
|
|
||||||
SourceOptions sourceOptions = new SourceOptions(options, loader, "init.groovy",
|
SourceOptions sourceOptions = new SourceOptions(options, loader,
|
||||||
"spring.groovy");
|
"init.groovy", "spring.groovy");
|
||||||
String[] sources = sourceOptions.getSourcesArray();
|
String[] sources = sourceOptions.getSourcesArray();
|
||||||
|
|
||||||
if (!(loader instanceof GroovyClassLoader)) {
|
if (!(loader instanceof GroovyClassLoader)) {
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,8 @@ public class TestRunner {
|
||||||
* @param sources
|
* @param sources
|
||||||
* @param args
|
* @param args
|
||||||
*/
|
*/
|
||||||
public TestRunner(TestRunnerConfiguration configuration, String[] sources, String[] args) {
|
public TestRunner(TestRunnerConfiguration configuration, String[] sources,
|
||||||
|
String[] args) {
|
||||||
this.sources = sources.clone();
|
this.sources = sources.clone();
|
||||||
this.compiler = new GroovyCompiler(configuration);
|
this.compiler = new GroovyCompiler(configuration);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,8 @@ public class SampleSecureApplication implements CommandLineRunner {
|
||||||
.commaSeparatedStringToAuthorityList("ROLE_USER")));
|
.commaSeparatedStringToAuthorityList("ROLE_USER")));
|
||||||
try {
|
try {
|
||||||
System.out.println(service.secure());
|
System.out.println(service.secure());
|
||||||
} finally {
|
}
|
||||||
|
finally {
|
||||||
SecurityContextHolder.clearContext();
|
SecurityContextHolder.clearContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@ import org.springframework.boot.loader.util.SystemPropertyUtils;
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
|
* @author Janne Valkealahti
|
||||||
*/
|
*/
|
||||||
public class PropertiesLauncher extends Launcher {
|
public class PropertiesLauncher extends Launcher {
|
||||||
|
|
||||||
|
|
@ -326,27 +327,39 @@ public class PropertiesLauncher extends Launcher {
|
||||||
@Override
|
@Override
|
||||||
protected ClassLoader createClassLoader(List<Archive> archives) throws Exception {
|
protected ClassLoader createClassLoader(List<Archive> archives) throws Exception {
|
||||||
ClassLoader loader = super.createClassLoader(archives);
|
ClassLoader loader = super.createClassLoader(archives);
|
||||||
String classLoaderType = getProperty("loader.classLoader");
|
String customLoaderClassName = getProperty("loader.classLoader");
|
||||||
if (classLoaderType != null) {
|
if (customLoaderClassName != null) {
|
||||||
Class<?> type = Class.forName(classLoaderType, true, loader);
|
loader = wrapWithCustomClassLoader(loader, customLoaderClassName);
|
||||||
try {
|
this.logger.info("Using custom class loader: " + customLoaderClassName);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
return loader;
|
return loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private ClassLoader wrapWithCustomClassLoader(ClassLoader parent,
|
||||||
|
String loaderClassName) throws Exception {
|
||||||
|
|
||||||
|
Class<ClassLoader> loaderClass = (Class<ClassLoader>) 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 {
|
private String getProperty(String propertyKey) throws Exception {
|
||||||
return getProperty(propertyKey, null);
|
return getProperty(propertyKey, null);
|
||||||
}
|
}
|
||||||
|
|
@ -356,18 +369,21 @@ public class PropertiesLauncher extends Launcher {
|
||||||
manifestKey = propertyKey.replace(".", "-");
|
manifestKey = propertyKey.replace(".", "-");
|
||||||
manifestKey = toCamelCase(manifestKey);
|
manifestKey = toCamelCase(manifestKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
String property = SystemPropertyUtils.getProperty(propertyKey);
|
String property = SystemPropertyUtils.getProperty(propertyKey);
|
||||||
if (property != null) {
|
if (property != null) {
|
||||||
String value = SystemPropertyUtils.resolvePlaceholders(property);
|
String value = SystemPropertyUtils.resolvePlaceholders(property);
|
||||||
this.logger.fine("Property '" + propertyKey + "' from environment: " + value);
|
this.logger.fine("Property '" + propertyKey + "' from environment: " + value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.properties.containsKey(propertyKey)) {
|
if (this.properties.containsKey(propertyKey)) {
|
||||||
String value = SystemPropertyUtils.resolvePlaceholders(this.properties
|
String value = SystemPropertyUtils.resolvePlaceholders(this.properties
|
||||||
.getProperty(propertyKey));
|
.getProperty(propertyKey));
|
||||||
this.logger.fine("Property '" + propertyKey + "' from properties: " + value);
|
this.logger.fine("Property '" + propertyKey + "' from properties: " + value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Prefer home dir for MANIFEST if there is one
|
// Prefer home dir for MANIFEST if there is one
|
||||||
Manifest manifest = new ExplodedArchive(this.home).getManifest();
|
Manifest manifest = new ExplodedArchive(this.home).getManifest();
|
||||||
|
|
@ -379,7 +395,9 @@ public class PropertiesLauncher extends Launcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IllegalStateException ex) {
|
catch (IllegalStateException ex) {
|
||||||
|
// Ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise try the parent archive
|
// Otherwise try the parent archive
|
||||||
Manifest manifest = createArchive().getManifest();
|
Manifest manifest = createArchive().getManifest();
|
||||||
if (manifest != null) {
|
if (manifest != null) {
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ public class EnvironmentDelegateApplicationListener implements
|
||||||
|
|
||||||
private SimpleApplicationEventMulticaster multicaster;
|
private SimpleApplicationEventMulticaster multicaster;
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onApplicationEvent(ApplicationEvent event) {
|
public void onApplicationEvent(ApplicationEvent event) {
|
||||||
if (event instanceof SpringApplicationEnvironmentAvailableEvent) {
|
if (event instanceof SpringApplicationEnvironmentAvailableEvent) {
|
||||||
List<ApplicationListener<ApplicationEvent>> delegates = getListeners(((SpringApplicationEnvironmentAvailableEvent) event)
|
List<ApplicationListener<ApplicationEvent>> delegates = getListeners(((SpringApplicationEnvironmentAvailableEvent) event)
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,8 @@ public class ContextIdApplicationContextInitializerTests {
|
||||||
@Test
|
@Test
|
||||||
public void testNameAndPort() {
|
public void testNameAndPort() {
|
||||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
|
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);
|
this.initializer.initialize(context);
|
||||||
assertEquals("foo:8080", context.getId());
|
assertEquals("foo:8080", context.getId());
|
||||||
}
|
}
|
||||||
|
|
@ -59,8 +60,9 @@ public class ContextIdApplicationContextInitializerTests {
|
||||||
@Test
|
@Test
|
||||||
public void testCloudFoundry() {
|
public void testCloudFoundry() {
|
||||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
|
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
EnvironmentTestUtils.addEnvironment(context, "spring.config.name:foo", "PORT:8080",
|
EnvironmentTestUtils.addEnvironment(context, "spring.config.name:foo",
|
||||||
"vcap.application.name:bar", "vcap.application.instance_index:2");
|
"PORT:8080", "vcap.application.name:bar",
|
||||||
|
"vcap.application.instance_index:2");
|
||||||
this.initializer.initialize(context);
|
this.initializer.initialize(context);
|
||||||
assertEquals("bar:2", context.getId());
|
assertEquals("bar:2", context.getId());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,8 @@ public class EnvironmentDelegateApplicationContextInitializerTests {
|
||||||
@Test
|
@Test
|
||||||
public void orderedInitialize() throws Exception {
|
public void orderedInitialize() throws Exception {
|
||||||
StaticApplicationContext context = new StaticApplicationContext();
|
StaticApplicationContext context = new StaticApplicationContext();
|
||||||
EnvironmentTestUtils.addEnvironment(context,
|
EnvironmentTestUtils.addEnvironment(context, "context.initializer.classes:"
|
||||||
"context.initializer.classes:" + MockInitB.class.getName() + ","
|
+ MockInitB.class.getName() + "," + MockInitA.class.getName());
|
||||||
+ MockInitA.class.getName());
|
|
||||||
this.initializer.initialize(context);
|
this.initializer.initialize(context);
|
||||||
assertThat(context.getBeanFactory().getSingleton("a"), equalTo((Object) "a"));
|
assertThat(context.getBeanFactory().getSingleton("a"), equalTo((Object) "a"));
|
||||||
assertThat(context.getBeanFactory().getSingleton("b"), equalTo((Object) "b"));
|
assertThat(context.getBeanFactory().getSingleton("b"), equalTo((Object) "b"));
|
||||||
|
|
@ -79,8 +78,8 @@ public class EnvironmentDelegateApplicationContextInitializerTests {
|
||||||
@Test
|
@Test
|
||||||
public void notAnInitializerClass() throws Exception {
|
public void notAnInitializerClass() throws Exception {
|
||||||
StaticApplicationContext context = new StaticApplicationContext();
|
StaticApplicationContext context = new StaticApplicationContext();
|
||||||
EnvironmentTestUtils.addEnvironment(context,
|
EnvironmentTestUtils.addEnvironment(context, "context.initializer.classes:"
|
||||||
"context.initializer.classes:" + Object.class.getName());
|
+ Object.class.getName());
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
this.thrown.expect(IllegalArgumentException.class);
|
||||||
this.initializer.initialize(context);
|
this.initializer.initialize(context);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
import org.springframework.core.env.StandardEnvironment;
|
import org.springframework.core.env.StandardEnvironment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link FileEncodingApplicationListener}.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class FileEncodingApplicationListenerTests {
|
public class FileEncodingApplicationListenerTests {
|
||||||
|
|
@ -36,7 +38,8 @@ public class FileEncodingApplicationListenerTests {
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
@Test(expected = IllegalStateException.class)
|
||||||
public void testIllegalState() {
|
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);
|
this.initializer.onApplicationEvent(this.event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,8 +51,8 @@ public class FileEncodingApplicationListenerTests {
|
||||||
@Test
|
@Test
|
||||||
public void testSunnyDayMandated() {
|
public void testSunnyDayMandated() {
|
||||||
Assume.assumeNotNull(System.getProperty("file.encoding"));
|
Assume.assumeNotNull(System.getProperty("file.encoding"));
|
||||||
EnvironmentTestUtils.addEnviroment(this.environment, "spring.mandatory_file_encoding:"
|
EnvironmentTestUtils.addEnviroment(this.environment,
|
||||||
+ System.getProperty("file.encoding"));
|
"spring.mandatory_file_encoding:" + System.getProperty("file.encoding"));
|
||||||
this.initializer.onApplicationEvent(this.event);
|
this.initializer.onApplicationEvent(this.event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,8 @@ public class LoggingApplicationListenerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOverrideConfigDoesNotExist() throws Exception {
|
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.initializer.initialize(this.context.getEnvironment(),
|
||||||
this.context.getClassLoader());
|
this.context.getClassLoader());
|
||||||
// Should not throw
|
// Should not throw
|
||||||
|
|
|
||||||
|
|
@ -184,7 +184,8 @@ public class EnableConfigurationPropertiesTests {
|
||||||
@Test
|
@Test
|
||||||
public void testCollectionPropertiesBindingFromYamlArray() {
|
public void testCollectionPropertiesBindingFromYamlArray() {
|
||||||
this.context.register(TestConfiguration.class);
|
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();
|
this.context.refresh();
|
||||||
assertEquals(2, this.context.getBean(TestProperties.class).getList().size());
|
assertEquals(2, this.context.getBean(TestProperties.class).getList().size());
|
||||||
}
|
}
|
||||||
|
|
@ -227,7 +228,8 @@ public class EnableConfigurationPropertiesTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBindingDirectlyToFileResolvedFromEnvironment() {
|
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.register(ResourceBindingProperties.class, TestConfiguration.class);
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
assertEquals(1,
|
assertEquals(1,
|
||||||
|
|
@ -317,7 +319,8 @@ public class EnableConfigurationPropertiesTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultipleExplicitTypes() throws Exception {
|
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.register(FurtherExampleConfig.class);
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
assertEquals("foo", this.context.getBean(External.class).getName());
|
assertEquals("foo", this.context.getBean(External.class).getName());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue