Upgrades to build 2.1.0.BUILD-SNAPSHOT and boot 2.1.x
Moves refresh scope proxy creation from BeanDefinitionRegistryPostProcessor to BeanPostProcessor fixes gh-400
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons-parent</artifactId>
|
||||
<version>2.0.2.BUILD-SNAPSHOT</version>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
<packaging>pom</packaging>
|
||||
<name>Spring Cloud Commons Docs</name>
|
||||
@@ -16,7 +16,7 @@
|
||||
<properties>
|
||||
<docs.main>spring-cloud-commons</docs.main>
|
||||
<main.basedir>${basedir}/..</main.basedir>
|
||||
<docs.whitelisted.branches>1.1.x,1.2.x,1.3.x</docs.whitelisted.branches>
|
||||
<docs.whitelisted.branches>1.2.x,1.3.x,2.0.x</docs.whitelisted.branches>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
4
pom.xml
4
pom.xml
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons-parent</artifactId>
|
||||
<version>2.0.2.BUILD-SNAPSHOT</version>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>Spring Cloud Commons Parent</name>
|
||||
<description>Spring Cloud Commons Parent</description>
|
||||
@@ -11,7 +11,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-build</artifactId>
|
||||
<version>2.0.3.RELEASE</version>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<scm>
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
<parent>
|
||||
<artifactId>spring-cloud-dependencies-parent</artifactId>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<version>2.0.3.RELEASE</version>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-commons-dependencies</artifactId>
|
||||
<version>2.0.2.BUILD-SNAPSHOT</version>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>spring-cloud-commons-dependencies</name>
|
||||
<description>Spring Cloud Commons Dependencies</description>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons-parent</artifactId>
|
||||
<version>2.0.2.BUILD-SNAPSHOT</version>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.springframework.cloud.client;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.client.actuator.FeaturesEndpoint;
|
||||
@@ -81,7 +82,7 @@ public class CommonsClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
protected ConfigurableApplicationContext init(String... pairs) {
|
||||
return new SpringApplicationBuilder().web(false).sources(Config.class)
|
||||
return new SpringApplicationBuilder().web(WebApplicationType.NONE).sources(Config.class)
|
||||
.properties(pairs).run();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.springframework.cloud.client.discovery;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -19,7 +20,7 @@ public class EnableDiscoveryClientMissingImplTests {
|
||||
@Test
|
||||
public void testContextFails() {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder()
|
||||
.sources(App.class).web(false).run(new String[0]);) {
|
||||
.sources(App.class).web(WebApplicationType.NONE).run(new String[0]);) {
|
||||
}
|
||||
catch (NestedRuntimeException e) {
|
||||
Throwable rootCause = e.getRootCause();
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.client.DefaultServiceInstance;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
@@ -81,7 +82,7 @@ public abstract class AbstractLoadBalancerAutoConfigurationTests {
|
||||
}
|
||||
|
||||
protected ConfigurableApplicationContext init(Class<?> config) {
|
||||
return new SpringApplicationBuilder().web(false)
|
||||
return new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties("spring.aop.proxyTargetClass=true")
|
||||
.sources(config, LoadBalancerAutoConfiguration.class).run();
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.cloud.client.loadbalancer;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.client.DefaultServiceInstance;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
@@ -89,7 +90,7 @@ public class AsyncLoadBalancerAutoConfigurationTests {
|
||||
}
|
||||
|
||||
protected ConfigurableApplicationContext init(Class<?> config) {
|
||||
return new SpringApplicationBuilder().web(false)
|
||||
return new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties("spring.aop.proxyTargetClass=true")
|
||||
.sources(config, AsyncLoadBalancerAutoConfiguration.class).run();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -62,7 +63,7 @@ public class LoadBalancerRequestFactoryConfigurationTests {
|
||||
}
|
||||
|
||||
protected ConfigurableApplicationContext init(Class<?> config) {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder().web(false)
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties("spring.aop.proxyTargetClass=true")
|
||||
.sources(config, LoadBalancerAutoConfiguration.class).run();
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@ import org.hamcrest.Matchers;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -74,7 +75,7 @@ public class AutoServiceRegistrationAutoConfigurationTests {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
context.register(list.toArray(new Class[0]));
|
||||
if (StringUtils.hasText(property)) {
|
||||
EnvironmentTestUtils.addEnvironment(context, property);
|
||||
TestPropertyValues.of(property).applyTo(context);
|
||||
}
|
||||
context.refresh();
|
||||
return context;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons-parent</artifactId>
|
||||
<version>2.0.2.BUILD-SNAPSHOT</version>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-context-integration-tests</artifactId>
|
||||
|
||||
@@ -49,6 +49,7 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestConfiguration.class)
|
||||
@SuppressWarnings("Duplicates")
|
||||
public class RefreshScopeIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons-parent</artifactId>
|
||||
<version>2.0.2.BUILD-SNAPSHOT</version>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-context</artifactId>
|
||||
|
||||
@@ -23,13 +23,14 @@ import java.util.Set;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.aop.scope.ScopedProxyUtils;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.ListableBeanFactory;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
|
||||
@@ -62,10 +63,14 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(RefreshScope.class)
|
||||
@ConditionalOnProperty(name = "spring.cloud.refresh.enabled", matchIfMissing = true)
|
||||
@ConditionalOnProperty(name = RefreshAutoConfiguration.REFRESH_SCOPE_ENABLED, matchIfMissing = true)
|
||||
@AutoConfigureBefore(HibernateJpaAutoConfiguration.class)
|
||||
public class RefreshAutoConfiguration {
|
||||
|
||||
public static final String REFRESH_SCOPE_NAME = "refresh";
|
||||
public static final String REFRESH_SCOPE_PREFIX = "spring.cloud.refresh";
|
||||
public static final String REFRESH_SCOPE_ENABLED = REFRESH_SCOPE_PREFIX + ".enabled";
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(RefreshScope.class)
|
||||
public static RefreshScope refreshScope() {
|
||||
@@ -95,7 +100,9 @@ public class RefreshAutoConfiguration {
|
||||
|
||||
@Component
|
||||
protected static class RefreshScopeBeanDefinitionEnhancer
|
||||
implements BeanDefinitionRegistryPostProcessor {
|
||||
implements BeanPostProcessor, BeanDefinitionRegistryPostProcessor {
|
||||
|
||||
private BeanDefinitionRegistry registry;
|
||||
|
||||
/**
|
||||
* Class names for beans to post process into refresh scope. Useful when you don't
|
||||
@@ -104,8 +111,6 @@ public class RefreshAutoConfiguration {
|
||||
private Set<String> refreshables = new HashSet<>(
|
||||
Arrays.asList("com.zaxxer.hikari.HikariDataSource"));
|
||||
|
||||
private Environment environment;
|
||||
|
||||
public Set<String> getRefreshable() {
|
||||
return this.refreshables;
|
||||
}
|
||||
@@ -124,29 +129,42 @@ public class RefreshAutoConfiguration {
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
|
||||
throws BeansException {
|
||||
Environment environment = beanFactory.getBean(Environment.class);
|
||||
if (environment == null) {
|
||||
environment = new StandardEnvironment();
|
||||
}
|
||||
Binder.get(environment).bind(REFRESH_SCOPE_PREFIX, Bindable.ofInstance(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
|
||||
throws BeansException {
|
||||
for (String name : registry.getBeanDefinitionNames()) {
|
||||
BeanDefinition definition = registry.getBeanDefinition(name);
|
||||
if (isApplicable(registry, name, definition)) {
|
||||
BeanDefinitionHolder holder = new BeanDefinitionHolder(definition,
|
||||
name);
|
||||
BeanDefinitionHolder proxy = ScopedProxyUtils
|
||||
.createScopedProxy(holder, registry, true);
|
||||
definition.setScope("refresh");
|
||||
registry.registerBeanDefinition(proxy.getBeanName(),
|
||||
proxy.getBeanDefinition());
|
||||
}
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
BeanDefinition definition = null;
|
||||
try {
|
||||
definition = registry.getBeanDefinition(beanName);
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException e) {
|
||||
// just ignore and move on
|
||||
return bean;
|
||||
}
|
||||
if (isApplicable(registry, beanName, definition)) {
|
||||
definition.setScope(REFRESH_SCOPE_NAME);
|
||||
ProxyFactory proxyFactory = new ProxyFactory(bean);
|
||||
return proxyFactory.getProxy();
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
private boolean isApplicable(BeanDefinitionRegistry registry, String name,
|
||||
BeanDefinition definition) {
|
||||
String scope = definition.getScope();
|
||||
if ("refresh".equals(scope)) {
|
||||
if (REFRESH_SCOPE_NAME.equals(scope)) {
|
||||
// Already refresh scoped
|
||||
return false;
|
||||
}
|
||||
@@ -158,15 +176,6 @@ public class RefreshAutoConfiguration {
|
||||
}
|
||||
}
|
||||
if (type != null) {
|
||||
if (this.environment == null && registry instanceof BeanFactory) {
|
||||
this.environment = ((BeanFactory) registry)
|
||||
.getBean(Environment.class);
|
||||
}
|
||||
if (this.environment == null) {
|
||||
this.environment = new StandardEnvironment();
|
||||
}
|
||||
Binder.get(environment).bind("spring.cloud.refresh",
|
||||
Bindable.ofInstance(this));
|
||||
return this.refreshables.contains(type);
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -69,7 +69,7 @@ public class RefreshAutoConfigurationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
|
||||
@EnableConfigurationProperties(ConfigProps.class)
|
||||
@EnableConfigurationProperties
|
||||
static class Config {
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ContextRefresherTests {
|
||||
@Test
|
||||
public void orderNewPropertiesConsistentWithNewContext() {
|
||||
try (ConfigurableApplicationContext context = SpringApplication.run(Empty.class,
|
||||
"--spring.main.webEnvironment=false", "--debug=false",
|
||||
"--spring.main.web-application-type=none", "--debug=false",
|
||||
"--spring.main.bannerMode=OFF")) {
|
||||
context.getEnvironment().setActiveProfiles("refresh");
|
||||
List<String> names = names(context.getEnvironment().getPropertySources());
|
||||
@@ -61,7 +61,7 @@ public class ContextRefresherTests {
|
||||
// Use spring.cloud.bootstrap.name to switch off the defaults (which would pick up
|
||||
// a bootstrapProperties immediately
|
||||
try (ConfigurableApplicationContext context = SpringApplication.run(Empty.class,
|
||||
"--spring.main.webEnvironment=false", "--debug=false",
|
||||
"--spring.main.web-application-type=none", "--debug=false",
|
||||
"--spring.main.bannerMode=OFF",
|
||||
"--spring.cloud.bootstrap.name=refresh")) {
|
||||
List<String> names = names(context.getEnvironment().getPropertySources());
|
||||
@@ -82,7 +82,7 @@ public class ContextRefresherTests {
|
||||
// Use spring.cloud.bootstrap.name to switch off the defaults (which would pick up
|
||||
// a bootstrapProperties immediately
|
||||
try (ConfigurableApplicationContext context = SpringApplication.run(
|
||||
ContextRefresherTests.class, "--spring.main.webEnvironment=false",
|
||||
ContextRefresherTests.class, "--spring.main.web-application-type=none",
|
||||
"--debug=false", "--spring.main.bannerMode=OFF",
|
||||
"--spring.cloud.bootstrap.name=refresh")) {
|
||||
ContextRefresher refresher = new ContextRefresher(context, scope);
|
||||
@@ -107,7 +107,7 @@ public class ContextRefresherTests {
|
||||
.get(getClass().getClassLoader());
|
||||
assertThat(system.getCount()).isEqualTo(0);
|
||||
try (ConfigurableApplicationContext context = SpringApplication.run(Empty.class,
|
||||
"--spring.main.webEnvironment=false", "--debug=false",
|
||||
"--spring.main.web-application-type=none", "--debug=false",
|
||||
"--spring.main.bannerMode=OFF",
|
||||
"--spring.cloud.bootstrap.name=refresh")) {
|
||||
assertThat(system.getCount()).isEqualTo(4);
|
||||
@@ -123,7 +123,7 @@ public class ContextRefresherTests {
|
||||
TestBootstrapConfiguration.fooSightings = new ArrayList<>();
|
||||
|
||||
try (ConfigurableApplicationContext context = SpringApplication.run(ContextRefresherTests.class,
|
||||
"--spring.main.webEnvironment=false", "--debug=false",
|
||||
"--spring.main.web-application-type=none", "--debug=false",
|
||||
"--spring.main.bannerMode=OFF",
|
||||
"--spring.cloud.bootstrap.name=refresh",
|
||||
"--test.bootstrap.foo=bar")) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons-parent</artifactId>
|
||||
<version>2.0.2.BUILD-SNAPSHOT</version>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-starter</artifactId>
|
||||
<name>spring-cloud-starter</name>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons-parent</artifactId>
|
||||
<version>2.0.2.BUILD-SNAPSHOT</version>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-test-support</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user