-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2.7版本与spring cloud euerka bean创建冲突 #449
Comments
与archaius冲突 |
Thanks, it's a bug and be resolved in 2.7.1 |
@mercyblitz 您好,我的项目中,需要对接别人的feign接口sdk,同时我自己项目提供dubbo接口,但是在引入别人的feign sdk时,启动却报了类似的错误,
版本: 请问是同一个bug吗,还是说我的配置问题 |
我也遇到这个问题了 |
If your Spring Boot/Cloud 2 applications met with this issue , like below:
Please add these code for your application to resolve this issue:
spring.main.allow-bean-definition-overriding = true
// Bugfix code to resolve Environment Beans conflict
@Primary
@Bean(name = BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME)
public PropertyResolver dubboScanBasePackagesPropertyResolver(ConfigurableEnvironment environment) {
ConfigurableEnvironment propertyResolver = new AbstractEnvironment() {
protected void customizePropertySources(MutablePropertySources propertySources) {
Map<String, Object> dubboScanProperties = PropertySourcesUtils.getSubProperties(environment, DUBBO_SCAN_PREFIX);
propertySources.addLast(new MapPropertySource("dubboScanProperties", dubboScanProperties));
}
};
ConfigurationPropertySources.attach(propertyResolver);
return new DelegatingPropertyResolver(propertyResolver);
}
private static class DelegatingPropertyResolver implements PropertyResolver {
private final PropertyResolver delegate;
DelegatingPropertyResolver(PropertyResolver delegate) {
Assert.notNull(delegate, "The delegate of PropertyResolver must not be null");
this.delegate = delegate;
}
@Override
public boolean containsProperty(String key) {
return delegate.containsProperty(key);
}
@Override
@Nullable
public String getProperty(String key) {
return delegate.getProperty(key);
}
@Override
public String getProperty(String key, String defaultValue) {
return delegate.getProperty(key, defaultValue);
}
@Override
@Nullable
public <T> T getProperty(String key, Class<T> targetType) {
return delegate.getProperty(key, targetType);
}
@Override
public <T> T getProperty(String key, Class<T> targetType, T defaultValue) {
return delegate.getProperty(key, targetType, defaultValue);
}
@Override
public String getRequiredProperty(String key) throws IllegalStateException {
return delegate.getRequiredProperty(key);
}
@Override
public <T> T getRequiredProperty(String key, Class<T> targetType) throws IllegalStateException {
return delegate.getRequiredProperty(key, targetType);
}
@Override
public String resolvePlaceholders(String text) {
return delegate.resolvePlaceholders(text);
}
@Override
public String resolveRequiredPlaceholders(String text) throws IllegalArgumentException {
return delegate.resolveRequiredPlaceholders(text);
}
} |
to resolve this problem ,i add @primary annotation on dubboScanBasePackagesPropertyResolver() method, eg: |
@sohu234 Thanks for your code, I have updated my bugfix code. |
各位好.我使用上述的两种方式.还是有如何的错误提示,现在不知如何是好? dubbo版本2.7.0 |
Please attach your error messages, it works in my side. |
According to the above method, I can't solve my problem. @primary is not woking I debug at @primary function, That not entry my debug point @SpringBootApplication
@EnableDiscoveryClient
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
} dubbo:
registry:
address: zk1.test1.akucun.com,zk2.test1.akucun.com,zk3.test1.akucun.com
port: 2181
protocol: zookeeper
application:
name: ddc-datacenter-dubbo
server:
port: 8085
eureka:
client:
proxy-user-name: merchant
proxy-password: 123456
service-url:
defaultZone: http://${eureka.client.proxy-user-name}:${eureka.client.proxy-password}@172.19.1.233:8080/eureka/
spring:
application:
name: ddc-datecenter-dubbo
main:
allow-bean-definition-overriding: true <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!-- Dubbo Spring Boot Starter -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.7.0</version>
</dependency>
<!-- Apache Dubbo -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
This is my config @Configuration
public class ConfigBean {
// Bugfix code to resolve Environment Beans conflict
@Primary
@Bean(name = BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME)
public PropertyResolver dubboScanBasePackagesPropertyResolver(ConfigurableEnvironment environment) {
ConfigurableEnvironment propertyResolver = new AbstractEnvironment() {
protected void customizePropertySources(MutablePropertySources propertySources) {
Map<String, Object> dubboScanProperties = PropertySourcesUtils.getSubProperties(environment, DUBBO_SCAN_PREFIX);
propertySources.addLast(new MapPropertySource("dubboScanProperties", dubboScanProperties));
}
};
ConfigurationPropertySources.attach(propertyResolver);
return new DelegatingPropertyResolver(propertyResolver);
}
private static class DelegatingPropertyResolver implements PropertyResolver {
private final PropertyResolver delegate;
DelegatingPropertyResolver(PropertyResolver delegate) {
Assert.notNull(delegate, "The delegate of PropertyResolver must not be null");
this.delegate = delegate;
}
@Override
public boolean containsProperty(String key) {
return delegate.containsProperty(key);
}
@Override
@Nullable
public String getProperty(String key) {
return delegate.getProperty(key);
}
@Override
public String getProperty(String key, String defaultValue) {
return delegate.getProperty(key, defaultValue);
}
@Override
@Nullable
public <T> T getProperty(String key, Class<T> targetType) {
return delegate.getProperty(key, targetType);
}
@Override
public <T> T getProperty(String key, Class<T> targetType, T defaultValue) {
return delegate.getProperty(key, targetType, defaultValue);
}
@Override
public String getRequiredProperty(String key) throws IllegalStateException {
return delegate.getRequiredProperty(key);
}
@Override
public <T> T getRequiredProperty(String key, Class<T> targetType) throws IllegalStateException {
return delegate.getRequiredProperty(key, targetType);
}
@Override
public String resolvePlaceholders(String text) {
return delegate.resolvePlaceholders(text);
}
@Override
public String resolveRequiredPlaceholders(String text) throws IllegalArgumentException {
return delegate.resolveRequiredPlaceholders(text);
}
}
} |
错误日志:
Field propertyResolver in org.springframework.cloud.netflix.eureka.EurekaClientConfigBean required a single bean, but 2 were found:
- dubboScanBasePackagesPropertyResolver: defined by method 'dubboScanBasePackagesPropertyResolver' in class path resource [org/apache/dubbo/spring/boot/autoconfigure/DubboRelaxedBinding2AutoConfiguration.class]
- environment: a programmatically registered singleton
org.apache.dubbo.spring.boot.autoconfigure.DubboRelaxedBinding2AutoConfiguration
org.springframework.cloud.netflix.eureka.EurekaClientConfigBean
The text was updated successfully, but these errors were encountered: