Polish
This commit is contained in:
parent
5c1f700c3a
commit
891dd5a0f6
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
@ -33,9 +34,10 @@ import org.springframework.context.annotation.Conditional;
|
|||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@Conditional(OnEnabledHealthIndicatorCondition.class)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE, ElementType.METHOD })
|
||||
@Documented
|
||||
@Conditional(OnEnabledHealthIndicatorCondition.class)
|
||||
public @interface ConditionalOnEnablednHealthIndicator {
|
||||
|
||||
/**
|
||||
|
|
|
@ -66,4 +66,5 @@ class LinksEnhancer {
|
|||
resource.add(linkTo(type).slash(fullPath).withRel(rel));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,37 +28,38 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
|
|||
* {@link Condition} that checks if a health indicator is enabled.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
*/
|
||||
class OnEnabledHealthIndicatorCondition extends SpringBootCondition {
|
||||
|
||||
@Override
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||
AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(metadata
|
||||
.getAnnotationAttributes(ConditionalOnEnablednHealthIndicator.class.getName()));
|
||||
private static final String ANNOTATION_CLASS = ConditionalOnEnablednHealthIndicator.class
|
||||
.getName();
|
||||
|
||||
@Override
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
||||
AnnotatedTypeMetadata metadata) {
|
||||
AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(metadata
|
||||
.getAnnotationAttributes(ANNOTATION_CLASS));
|
||||
String endpointName = annotationAttributes.getString("value");
|
||||
ConditionOutcome outcome = determineHealthIndicatorOutcome(endpointName, context);
|
||||
ConditionOutcome outcome = getHealthIndicatorOutcome(context, endpointName);
|
||||
if (outcome != null) {
|
||||
return outcome;
|
||||
}
|
||||
return determineDefaultIndicatorsOutcome(context);
|
||||
return getDefaultIndicatorsOutcome(context);
|
||||
}
|
||||
|
||||
private ConditionOutcome determineHealthIndicatorOutcome(String endpointName,
|
||||
ConditionContext context) {
|
||||
private ConditionOutcome getHealthIndicatorOutcome(ConditionContext context,
|
||||
String endpointName) {
|
||||
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
|
||||
context.getEnvironment(), "management.health." + endpointName + ".");
|
||||
if (resolver.containsProperty("enabled")) {
|
||||
boolean match = resolver.getProperty("enabled", Boolean.class,
|
||||
true);
|
||||
return new ConditionOutcome(match, "The health indicator " + endpointName +
|
||||
" is " + (match ? "enabled" : "disabled"));
|
||||
boolean match = resolver.getProperty("enabled", Boolean.class, true);
|
||||
return new ConditionOutcome(match, "The health indicator " + endpointName
|
||||
+ " is " + (match ? "enabled" : "disabled"));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private ConditionOutcome determineDefaultIndicatorsOutcome(ConditionContext context) {
|
||||
private ConditionOutcome getDefaultIndicatorsOutcome(ConditionContext context) {
|
||||
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
|
||||
context.getEnvironment(), "management.health.defaults.");
|
||||
boolean match = Boolean.valueOf(resolver.getProperty("enabled", "true"));
|
||||
|
|
|
@ -36,10 +36,6 @@ public class SimpleInMemoryRepository<T> {
|
|||
|
||||
private final ConcurrentMap<String, Object> locks = new ConcurrentReferenceHashMap<String, Object>();
|
||||
|
||||
public interface Callback<T> {
|
||||
T modify(T current);
|
||||
}
|
||||
|
||||
public T update(String name, Callback<T> callback) {
|
||||
Object lock = this.locks.putIfAbsent(name, new Object());
|
||||
if (lock == null) {
|
||||
|
@ -101,4 +97,8 @@ public class SimpleInMemoryRepository<T> {
|
|||
return this.values;
|
||||
}
|
||||
|
||||
public interface Callback<T> {
|
||||
T modify(T current);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.After;
|
||||
|
@ -105,16 +106,15 @@ public class HealthIndicatorAutoConfigurationTests {
|
|||
@Test
|
||||
public void defaultHealthIndicatorsDisabledWithCustomOne() {
|
||||
this.context.register(CustomHealthIndicator.class,
|
||||
HealthIndicatorAutoConfiguration.class,
|
||||
ManagementServerProperties.class);
|
||||
HealthIndicatorAutoConfiguration.class, ManagementServerProperties.class);
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"management.health.defaults.enabled:false");
|
||||
this.context.refresh();
|
||||
Map<String, HealthIndicator> beans = this.context
|
||||
.getBeansOfType(HealthIndicator.class);
|
||||
assertEquals(1, beans.size());
|
||||
assertSame(this.context.getBean("customHealthIndicator"), beans.values().
|
||||
iterator().next());
|
||||
assertSame(this.context.getBean("customHealthIndicator"), beans.values()
|
||||
.iterator().next());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -445,6 +445,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -135,11 +135,13 @@ public class JolokiaAutoConfigurationTests {
|
|||
|
||||
@Configuration
|
||||
protected static class EndpointsConfig extends Config {
|
||||
|
||||
@Bean
|
||||
public EndpointHandlerMapping endpointHandlerMapping(
|
||||
Collection<? extends MvcEndpoint> endpoints) {
|
||||
return new EndpointHandlerMapping(endpoints);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
|
|
@ -318,7 +318,7 @@ public class RabbitProperties {
|
|||
private Integer transactionSize;
|
||||
|
||||
public boolean isAutoStartup() {
|
||||
return autoStartup;
|
||||
return this.autoStartup;
|
||||
}
|
||||
|
||||
public void setAutoStartup(boolean autoStartup) {
|
||||
|
|
|
@ -86,7 +86,8 @@ enum DatabaseDriver {
|
|||
/**
|
||||
* SQL Server
|
||||
*/
|
||||
SQLSERVER("com.microsoft.sqlserver.jdbc.SQLServerDriver", "com.microsoft.sqlserver.jdbc.SQLServerXADataSource");
|
||||
SQLSERVER("com.microsoft.sqlserver.jdbc.SQLServerDriver",
|
||||
"com.microsoft.sqlserver.jdbc.SQLServerXADataSource");
|
||||
|
||||
private final String driverClassName;
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ public class JmsProperties {
|
|||
}
|
||||
|
||||
public Listener getListener() {
|
||||
return listener;
|
||||
return this.listener;
|
||||
}
|
||||
|
||||
public static class Listener {
|
||||
|
@ -69,8 +69,8 @@ public class JmsProperties {
|
|||
private boolean autoStartup = true;
|
||||
|
||||
/**
|
||||
* Acknowledge mode of the container. By default, the listener is
|
||||
* transacted with automatic acknowledgment.
|
||||
* Acknowledge mode of the container. By default, the listener is transacted with
|
||||
* automatic acknowledgment.
|
||||
*/
|
||||
private AcknowledgeMode acknowledgeMode;
|
||||
|
||||
|
@ -85,7 +85,7 @@ public class JmsProperties {
|
|||
private Integer maxConcurrency;
|
||||
|
||||
public boolean isAutoStartup() {
|
||||
return autoStartup;
|
||||
return this.autoStartup;
|
||||
}
|
||||
|
||||
public void setAutoStartup(boolean autoStartup) {
|
||||
|
@ -93,7 +93,7 @@ public class JmsProperties {
|
|||
}
|
||||
|
||||
public AcknowledgeMode getAcknowledgeMode() {
|
||||
return acknowledgeMode;
|
||||
return this.acknowledgeMode;
|
||||
}
|
||||
|
||||
public void setAcknowledgeMode(AcknowledgeMode acknowledgeMode) {
|
||||
|
@ -120,16 +120,17 @@ public class JmsProperties {
|
|||
if (this.concurrency == null) {
|
||||
return (this.maxConcurrency != null ? "1-" + this.maxConcurrency : null);
|
||||
}
|
||||
return (this.maxConcurrency != null ? this.concurrency + "-" +
|
||||
this.maxConcurrency : String.valueOf(this.concurrency));
|
||||
return (this.maxConcurrency != null ? this.concurrency + "-"
|
||||
+ this.maxConcurrency : String.valueOf(this.concurrency));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate the acknowledge modes defined on the {@link javax.jms.Session}.
|
||||
*
|
||||
* <p>{@link javax.jms.Session#SESSION_TRANSACTED} is not defined as we take
|
||||
* care of this already via a call to {@code setSessionTransacted}.
|
||||
* <p>
|
||||
* {@link javax.jms.Session#SESSION_TRANSACTED} is not defined as we take care of this
|
||||
* already via a call to {@code setSessionTransacted}.
|
||||
*/
|
||||
public enum AcknowledgeMode {
|
||||
|
||||
|
@ -140,8 +141,8 @@ public class JmsProperties {
|
|||
AUTO(1),
|
||||
|
||||
/**
|
||||
* Messages are acknowledged once the message listener implementation has
|
||||
* called {@link javax.jms.Message#acknowledge()}. This mode gives the application
|
||||
* Messages are acknowledged once the message listener implementation has called
|
||||
* {@link javax.jms.Message#acknowledge()}. This mode gives the application
|
||||
* (rather than the JMS provider) complete control over message acknowledgement.
|
||||
*/
|
||||
CLIENT(2),
|
||||
|
@ -160,7 +161,7 @@ public class JmsProperties {
|
|||
}
|
||||
|
||||
public int getMode() {
|
||||
return mode;
|
||||
return this.mode;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,9 +74,9 @@ public class ThymeleafProperties {
|
|||
private boolean cache = true;
|
||||
|
||||
/**
|
||||
* Order of the template resolver in the chain. By default, the template resolver
|
||||
* is first in the chain. Order start at 1 and should only be set if you have
|
||||
* defined additional "TemplateResolver" beans.
|
||||
* Order of the template resolver in the chain. By default, the template resolver is
|
||||
* first in the chain. Order start at 1 and should only be set if you have defined
|
||||
* additional "TemplateResolver" beans.
|
||||
*/
|
||||
private Integer templateResolverOrder;
|
||||
|
||||
|
@ -160,7 +160,7 @@ public class ThymeleafProperties {
|
|||
}
|
||||
|
||||
public Integer getTemplateResolverOrder() {
|
||||
return templateResolverOrder;
|
||||
return this.templateResolverOrder;
|
||||
}
|
||||
|
||||
public void setTemplateResolverOrder(Integer templateResolverOrder) {
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.junit.After;
|
|||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.amqp.core.AcknowledgeMode;
|
||||
import org.springframework.amqp.core.AmqpAdmin;
|
||||
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
|
||||
|
@ -189,8 +188,7 @@ public class RabbitAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void testRabbitListenerContainerFactoryWithCustomSettings() {
|
||||
load(TestConfiguration.class,
|
||||
"spring.rabbitmq.listener.autoStartup:false",
|
||||
load(TestConfiguration.class, "spring.rabbitmq.listener.autoStartup:false",
|
||||
"spring.rabbitmq.listener.acknowledgeMode:manual",
|
||||
"spring.rabbitmq.listener.concurrency:5",
|
||||
"spring.rabbitmq.listener.maxConcurrency:10",
|
||||
|
@ -201,8 +199,7 @@ public class RabbitAutoConfigurationTests {
|
|||
SimpleRabbitListenerContainerFactory.class);
|
||||
DirectFieldAccessor dfa = new DirectFieldAccessor(rabbitListenerContainerFactory);
|
||||
assertEquals(false, dfa.getPropertyValue("autoStartup"));
|
||||
assertEquals(AcknowledgeMode.MANUAL,
|
||||
dfa.getPropertyValue("acknowledgeMode"));
|
||||
assertEquals(AcknowledgeMode.MANUAL, dfa.getPropertyValue("acknowledgeMode"));
|
||||
assertEquals(5, dfa.getPropertyValue("concurrentConsumers"));
|
||||
assertEquals(10, dfa.getPropertyValue("maxConcurrentConsumers"));
|
||||
assertEquals(40, dfa.getPropertyValue("prefetchCount"));
|
||||
|
|
|
@ -76,7 +76,7 @@ import static org.mockito.Mockito.mock;
|
|||
*/
|
||||
public class JacksonAutoConfigurationTests {
|
||||
|
||||
AnnotationConfigApplicationContext context;
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
@ -411,8 +411,8 @@ public class JacksonAutoConfigurationTests {
|
|||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.jackson.date-format:zzzz");
|
||||
this.context.refresh();
|
||||
ObjectMapper objectMapper = this.context
|
||||
.getBean(Jackson2ObjectMapperBuilder.class).build();
|
||||
ObjectMapper objectMapper = this.context.getBean(
|
||||
Jackson2ObjectMapperBuilder.class).build();
|
||||
|
||||
DateTime dateTime = new DateTime(1436966242231L, DateTimeZone.UTC);
|
||||
assertEquals("\"Koordinierte Universalzeit\"",
|
||||
|
|
|
@ -146,8 +146,7 @@ public class JmsAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void testJmsListenerContainerFactoryWithCustomSettings() {
|
||||
load(EnableJmsConfiguration.class,
|
||||
"spring.jms.listener.autoStartup=false",
|
||||
load(EnableJmsConfiguration.class, "spring.jms.listener.autoStartup=false",
|
||||
"spring.jms.listener.acknowledgeMode=client",
|
||||
"spring.jms.listener.concurrency=2",
|
||||
"spring.jms.listener.maxConcurrency=10");
|
||||
|
@ -155,10 +154,11 @@ public class JmsAutoConfigurationTests {
|
|||
.getBean("jmsListenerContainerFactory", JmsListenerContainerFactory.class);
|
||||
assertEquals(DefaultJmsListenerContainerFactory.class,
|
||||
jmsListenerContainerFactory.getClass());
|
||||
DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory)
|
||||
jmsListenerContainerFactory).createListenerContainer(mock(JmsListenerEndpoint.class));
|
||||
DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory) jmsListenerContainerFactory)
|
||||
.createListenerContainer(mock(JmsListenerEndpoint.class));
|
||||
assertEquals(false, listenerContainer.isAutoStartup());
|
||||
assertEquals(Session.CLIENT_ACKNOWLEDGE, listenerContainer.getSessionAcknowledgeMode());
|
||||
assertEquals(Session.CLIENT_ACKNOWLEDGE,
|
||||
listenerContainer.getSessionAcknowledgeMode());
|
||||
assertEquals(2, listenerContainer.getConcurrentConsumers());
|
||||
assertEquals(10, listenerContainer.getMaxConcurrentConsumers());
|
||||
}
|
||||
|
|
|
@ -16,9 +16,6 @@
|
|||
|
||||
package org.springframework.boot.autoconfigure.security.oauth2;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -94,6 +91,9 @@ import org.springframework.web.client.RestTemplate;
|
|||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
/**
|
||||
* Verify Spring Security OAuth2 auto-configuration secures end points properly, accepts
|
||||
* environmental overrides, and also backs off in the presence of other
|
||||
|
|
|
@ -181,6 +181,7 @@ public class BasicErrorControllerIntegrationTests {
|
|||
public NoReasonExpectedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1476,7 +1476,6 @@ respectively.
|
|||
|
||||
[[howto-use-exposing-spring-data-repositories-rest-endpoint]]
|
||||
=== Expose Spring Data repositories as REST endpoint
|
||||
|
||||
Spring Data REST can expose the `Repository` implementations as REST endpoints for you as
|
||||
long as Spring MVC has been enabled for the application.
|
||||
|
||||
|
|
|
@ -781,7 +781,6 @@ annotations to your `@ConfigurationProperties` class:
|
|||
}
|
||||
----
|
||||
|
||||
|
||||
In order to validate values of nested properties, you must annotate the associated field
|
||||
as `@Valid` to trigger its validation. For example, building upon the above
|
||||
`ConnectionSettings` example:
|
||||
|
|
|
@ -23,13 +23,11 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
|
|
@ -34,7 +34,7 @@ public class SampleProperties {
|
|||
private Integer port = 8080;
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
return this.host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
|
@ -42,10 +42,11 @@ public class SampleProperties {
|
|||
}
|
||||
|
||||
public Integer getPort() {
|
||||
return port;
|
||||
return this.port;
|
||||
}
|
||||
|
||||
public void setPort(Integer port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,10 +35,9 @@ public class SamplePropertiesValidator implements Validator {
|
|||
public void validate(Object o, Errors errors) {
|
||||
ValidationUtils.rejectIfEmpty(errors, "host", "host.empty");
|
||||
ValidationUtils.rejectIfEmpty(errors, "port", "port.empty");
|
||||
|
||||
SampleProperties properties = (SampleProperties) o;
|
||||
if (properties.getHost() != null &&
|
||||
!pattern.matcher(properties.getHost()).matches()) {
|
||||
if (properties.getHost() != null
|
||||
&& !this.pattern.matcher(properties.getHost()).matches()) {
|
||||
errors.rejectValue("host", "Invalid host");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,8 +52,8 @@ public class SamplePropertyValidationApplication {
|
|||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new SpringApplicationBuilder(SamplePropertyValidationApplication.class)
|
||||
.profiles("app").run(args);
|
||||
new SpringApplicationBuilder(SamplePropertyValidationApplication.class).profiles(
|
||||
"app").run(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import org.junit.After;
|
|||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.test.EnvironmentTestUtils;
|
||||
|
@ -43,16 +42,15 @@ public class SamplePropertyValidationApplicationTests {
|
|||
|
||||
@After
|
||||
public void closeContext() {
|
||||
context.close();
|
||||
this.context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindValidProperties() {
|
||||
this.context.register(SamplePropertyValidationApplication.class);
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"sample.host:192.168.0.1", "sample.port:9090");
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "sample.host:192.168.0.1",
|
||||
"sample.port:9090");
|
||||
this.context.refresh();
|
||||
|
||||
SampleProperties properties = this.context.getBean(SampleProperties.class);
|
||||
assertEquals("192.168.0.1", properties.getHost());
|
||||
assertEquals(Integer.valueOf(9090), properties.getPort());
|
||||
|
@ -61,32 +59,29 @@ public class SamplePropertyValidationApplicationTests {
|
|||
@Test
|
||||
public void bindInvalidHost() {
|
||||
this.context.register(SamplePropertyValidationApplication.class);
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"sample.host:xxxxxx", "sample.port:9090");
|
||||
|
||||
thrown.expect(BeanCreationException.class);
|
||||
thrown.expectMessage("xxxxxx");
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "sample.host:xxxxxx",
|
||||
"sample.port:9090");
|
||||
this.thrown.expect(BeanCreationException.class);
|
||||
this.thrown.expectMessage("xxxxxx");
|
||||
this.context.refresh();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindNullHost() {
|
||||
this.context.register(SamplePropertyValidationApplication.class);
|
||||
|
||||
thrown.expect(BeanCreationException.class);
|
||||
thrown.expectMessage("null");
|
||||
thrown.expectMessage("host");
|
||||
this.thrown.expect(BeanCreationException.class);
|
||||
this.thrown.expectMessage("null");
|
||||
this.thrown.expectMessage("host");
|
||||
this.context.refresh();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validatorOnlyCalledOnSupportedClass() {
|
||||
this.context.register(SamplePropertyValidationApplication.class);
|
||||
this.context.register(ServerProperties.class); // our validator will not apply here
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"sample.host:192.168.0.1", "sample.port:9090");
|
||||
this.context.register(ServerProperties.class); // our validator will not apply
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "sample.host:192.168.0.1",
|
||||
"sample.port:9090");
|
||||
this.context.refresh();
|
||||
|
||||
SampleProperties properties = this.context.getBean(SampleProperties.class);
|
||||
assertEquals("192.168.0.1", properties.getHost());
|
||||
assertEquals(Integer.valueOf(9090), properties.getPort());
|
||||
|
|
|
@ -101,33 +101,8 @@ public class LaunchedURLClassLoader extends URLClassLoader {
|
|||
if (this.rootClassLoader == null) {
|
||||
return findResources(name);
|
||||
}
|
||||
|
||||
final Enumeration<URL> rootResources = this.rootClassLoader.getResources(name);
|
||||
final Enumeration<URL> localResources = findResources(name);
|
||||
|
||||
return new Enumeration<URL>() {
|
||||
|
||||
@Override
|
||||
public boolean hasMoreElements() {
|
||||
try {
|
||||
Handler.setUseFastConnectionExceptions(true);
|
||||
return rootResources.hasMoreElements()
|
||||
|| localResources.hasMoreElements();
|
||||
}
|
||||
finally {
|
||||
Handler.setUseFastConnectionExceptions(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL nextElement() {
|
||||
if (rootResources.hasMoreElements()) {
|
||||
return rootResources.nextElement();
|
||||
}
|
||||
return localResources.nextElement();
|
||||
}
|
||||
|
||||
};
|
||||
return new ResourceEnumeration(this.rootClassLoader.getResources(name),
|
||||
findResources(name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -267,4 +242,41 @@ public class LaunchedURLClassLoader extends URLClassLoader {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Enumeration} implementation used for {@code getResources()}.
|
||||
*/
|
||||
private static class ResourceEnumeration implements Enumeration<URL> {
|
||||
|
||||
private final Enumeration<URL> rootResources;
|
||||
|
||||
private final Enumeration<URL> localResources;
|
||||
|
||||
public ResourceEnumeration(Enumeration<URL> rootResources,
|
||||
Enumeration<URL> localResources) {
|
||||
this.rootResources = rootResources;
|
||||
this.localResources = localResources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMoreElements() {
|
||||
try {
|
||||
Handler.setUseFastConnectionExceptions(true);
|
||||
return this.rootResources.hasMoreElements()
|
||||
|| this.localResources.hasMoreElements();
|
||||
}
|
||||
finally {
|
||||
Handler.setUseFastConnectionExceptions(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL nextElement() {
|
||||
if (this.rootResources.hasMoreElements()) {
|
||||
return this.rootResources.nextElement();
|
||||
}
|
||||
return this.localResources.nextElement();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -355,11 +355,11 @@ public class RelaxedDataBinderTests {
|
|||
bind(target, "nested.foo: bar.key\n" + "nested[bar.key].spam: bucket\n"
|
||||
+ "nested[bar.key].value: 123\nnested[bar.key].foo: crap");
|
||||
assertEquals(2, target.getNested().size());
|
||||
Map<String, Object> nestedMap = (Map<String, Object>) target.getNested().get("bar.key");
|
||||
Map<String, Object> nestedMap = (Map<String, Object>) target.getNested().get(
|
||||
"bar.key");
|
||||
assertNotNull("nested map should be registered with 'bar.key'", nestedMap);
|
||||
assertEquals(3, nestedMap.size());
|
||||
assertEquals("123",
|
||||
nestedMap.get("value"));
|
||||
assertEquals("123", nestedMap.get("value"));
|
||||
assertEquals("bar.key", target.getNested().get("foo"));
|
||||
assertFalse(target.getNested().containsValue(target.getNested()));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue