Skip to content
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

Using druid sdk, then updating the nacos configuration item annotated with @RefreshCope result in error: "Unable to set value for property oracle" #6330

Open
wentfar opened this issue Jan 20, 2025 · 0 comments

Comments

@wentfar
Copy link

wentfar commented Jan 20, 2025

Database Type

oracle

Database Version

19c

Druid Version

1.1.24

JDK Version

jdk1.8

Error SQL

Not involved

#https://github.com/alibaba/nacos/issues/13053

Testcase Code

Describe the bug
A clear and concise description of what the bug is.

I have a springboot application that uses druid components and nacos components. Duird-related configurations are configured in the properties and nacos. Druid is configured with multiple data sources. Resources directory is like this:

  • bootstrap.properties
spring.application.name=cp-unify-compliance
spring.cloud.nacos.config.enabled=${NACOS_ENABLED:false}  
spring.cloud.nacos.config.server-addr=${NACOS_SERVER_URL:nacos.infrastructure}  
spring.cloud.nacos.config.file-extension=properties  
spring.cloud.nacos.config.namespace=${NACOS_NAMESPACE:release}

spring.cloud.nacos.config.group=cp 
spring.cloud.nacos.config.refresh-enabled=true  
spring.cloud.nacos.config.username=${NACOS_USERNAME:nacos}  
spring.cloud.nacos.config.password=${NACOS_PASSWORD:nacos}  
spring.cloud.nacos.config.extension-configs[0].data-id=common.properties 
spring.cloud.nacos.config.extension-configs[0].group=cp 

  • nacos config like this:
data ID: cp-unify-compliance.properties
group: cp
配置内容:
...
preTrade.bondInquiry.pricePercent.deviationThreshold.block=0.02
...

  • application.properties
spring.profiles.include=mybatis,druid,tracer,ob .... 

  • application-druid.properties
spring.datasource.druid.filter.config.enabled=true
spring.datasource.druid.connect-properties.config.decrypt=true
spring.datasource.druid.connect-properties.config.decrypt.key=${spring.datasource.druid.pub-key}
spring.datasource.druid.initial-size=1
spring.datasource.druid.max-active=5
  • application-ob.properties
\# mysql tenant 
spring.datasource.druid.ob.driver-class-name=com.alipay.oceanbase.jdbc.Driver 
spring.datasource.druid.ob.url=  
spring.datasource.druid.ob.username=  
spring.datasource.druid.ob.password=  
pring.datasource.druid.ob.filter.config.enabled=flase  
spring.datasource.druid.ob.connect-properties.config.decrypt=false  
spring.datasource.druid.ob.initial-size=2  
spring.datasource.druid.ob.max-active=30  
spring.datasource.druid.ob.min-idle=5  
spring.datasource.druid.ob.max-wait=60000  
\# oracle tenant  
spring.datasource.druid.ob1.driver-class-name=com.alipay.oceanbase.jdbc.Driver  
spring.datasource.druid.ob1.url=  
spring.datasource.druid.ob1.username=  
spring.datasource.druid.ob1.password=  
spring.datasource.druid.ob1.filter.config.enabled=flase  
spring.datasource.druid.ob1.connect-properties.config.decrypt=false  
spring.datasource.druid.ob1.initial-size=2  
spring.datasource.druid.ob1.max-active=30  
spring.datasource.druid.ob1.min-idle=5  
spring.datasource.druid.ob1.max-wait=60000  
spring.datasource.druid.ob1.test-while-idle=true  
spring.datasource.druid.ob1.test-on-borrow=true 
spring.datasource.druid.ob1.validation-query=SELECT 1 FROM DUAL  
spring.datasource.druid.ob1.oracle=true
  • code fragment is like this,(using @RefreshScode)
@Configuration
@Data
@RefreshScope
public class SuspiciousTradeCheckConfig implements RiskConfig {
    
    private Logger logger = LoggerFactory.getLogger(SuspiciousTradeCheckConfig.class);
    
    @Value("${preTrade.bondInquiry.statisticCaliber.period}")
    private String bondInquiryStatisticCaliberPeriod;
    
    @Value("${preTrade.bondInquiry.price.deviationThreshold.block}")
    private String bondInquiryPriceDeviationThreshold;
    @Value("${preTrade.bondInquiry.pricePercent.deviationThreshold.block:0.01}")
    private String bondInquiryPriceDeviationThresholdPercent = "0.01";
    
}

one of the datasource config is as below:

@Configuration
@MapperScan(basePackages = {"com.citics.am.cp.compliance.ob1mapper",
        "com.citics.am.cp.compliance.data.ob1respository",
        "com.citics.am.cp.compliance.report.ob1repository"}, sqlSessionFactoryRef = "ob1SqlSessionFactory")
public class ObOraDataSourceConfig {
    
    @Bean(name = "ob1DataSource")
    @ConfigurationProperties(prefix = "spring.datasource.druid.ob1")
    public DataSource ob1DateSource() {
        return DataSourceBuilder.create().type(DruidDataSource.class).build();
    }
    
    @Bean(name = "ob1SqlSessionFactory")
    public SqlSessionFactory ob1SqlSessionFactory(@Qualifier("ob1DataSource") DataSource datasource)
            throws Exception {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(datasource);
        bean.setMapperLocations(resolveMapperLocations());
        Interceptor interceptor = new PageInterceptor();
        Properties properties = new Properties();
        properties.setProperty("helperDialect", "oracle");
        properties.setProperty("offsetAsPageNum", "true");
        properties.setProperty("rowBoundsWithCount", "true");
        properties.setProperty("reasonable", "false");
        interceptor.setProperties(properties);
        bean.setPlugins(new Interceptor[] {interceptor});
        bean.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);
        return bean.getObject();
    }
    
    @Bean(name = "ob1TransactionManager")
    public DataSourceTransactionManager ob1TransactionManager(@Qualifier("ob1DataSource") DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }
    
    @Bean(name = "ob1SqlSessionTemplate")
    public SqlSessionTemplate ob1SqlSessionTemplate(@Qualifier("ob1SqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
        return new SqlSessionTemplate(sqlSessionFactory);
    }
    
    @Bean(name = "ob1JdbcTemplate")
    public JdbcTemplate ob1JdbcTemplate(@Qualifier("ob1DataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
    
    public Resource[] resolveMapperLocations() {
        ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
        List<String> mapperLocations = new ArrayList<>();
        mapperLocations.add("classpath*:com/citics/am/cp/compliance/ob1mapper/*.xml");
        mapperLocations.add("classpath*:com/citics/am/cp/compliance/data/ob1respository/*.xml");
        mapperLocations.add("classpath*:com/citics/am/cp/compliance/report/ob1repository/*.xml");
        List<Resource> resources = new ArrayList();
        if (mapperLocations != null) {
            for (String mapperLocation : mapperLocations) {
                try {
                    Resource[] mappers = resourceResolver.getResources(mapperLocation);
                    resources.addAll(Arrays.asList(mappers));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return resources.toArray(new Resource[resources.size()]);
    }
    
}

when modify the configuration item, such as: preTrade.bondInquiry.pricePercent.deviationThreshold.block=0.02

Error log appears on the console。 The log is as below, it seems that: nacos try to update druid properties, but druid doesn't allow the change.

org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.datasource.druid.ob1' to javax.sql.DataSource
	at org.springframework.boot.context.properties.bind.Binder.handleBindError(Binder.java:363)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:323)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:308)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:238)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:225)
	at org.springframework.boot.context.properties.ConfigurationPropertiesBinder.bind(ConfigurationPropertiesBinder.java:90)
	at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.bind(ConfigurationPropertiesBindingPostProcessor.java:89)
	at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:78)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:415)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1791)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:406)
	at org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder.rebind(ConfigurationPropertiesRebinder.java:108)
	at org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder.rebind(ConfigurationPropertiesRebinder.java:84)
	at org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder.onApplicationEvent(ConfigurationPropertiesRebinder.java:142)
	at org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder.onApplicationEvent(ConfigurationPropertiesRebinder.java:51)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361)
	at org.springframework.cloud.context.refresh.ContextRefresher.refreshEnvironment(ContextRefresher.java:96)
	at org.springframework.cloud.context.refresh.ContextRefresher.refresh(ContextRefresher.java:85)
	at org.springframework.cloud.endpoint.event.RefreshEventListener.handle(RefreshEventListener.java:72)
	at org.springframework.cloud.endpoint.event.RefreshEventListener.onApplicationEvent(RefreshEventListener.java:61)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361)
	at com.alibaba.cloud.nacos.refresh.NacosContextRefresher$1.innerReceive(NacosContextRefresher.java:133)
	at com.alibaba.nacos.api.config.listener.AbstractSharedListener.receiveConfigInfo(AbstractSharedListener.java:40)
	at com.alibaba.nacos.client.config.impl.CacheData$1.run(CacheData.java:312)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:750)
Caused by: java.lang.IllegalStateException: Unable to set value for property oracle
	at org.springframework.boot.context.properties.bind.JavaBeanBinder$BeanProperty.setValue(JavaBeanBinder.java:360)
	at org.springframework.boot.context.properties.bind.JavaBeanBinder.bind(JavaBeanBinder.java:101)
	at org.springframework.boot.context.properties.bind.JavaBeanBinder.bind(JavaBeanBinder.java:83)
	at org.springframework.boot.context.properties.bind.JavaBeanBinder.bind(JavaBeanBinder.java:59)
	at org.springframework.boot.context.properties.bind.Binder.lambda$bindDataObject$5(Binder.java:451)
	at org.springframework.boot.context.properties.bind.Binder$Context.withIncreasedDepth(Binder.java:571)
	at org.springframework.boot.context.properties.bind.Binder$Context.withDataObject(Binder.java:557)
	at org.springframework.boot.context.properties.bind.Binder$Context.access$300(Binder.java:512)
	at org.springframework.boot.context.properties.bind.Binder.bindDataObject(Binder.java:449)
	at org.springframework.boot.context.properties.bind.Binder.bindObject(Binder.java:390)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:319)
	... 35 common frames omitted
Caused by: java.lang.reflect.InvocationTargetException: null
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.boot.context.properties.bind.JavaBeanBinder$BeanProperty.setValue(JavaBeanBinder.java:357)
	... 45 common frames omitted
Caused by: java.lang.IllegalStateException: null
	at com.alibaba.druid.pool.DruidAbstractDataSource.setOracle(DruidAbstractDataSource.java:337)
	... 50 common frames omitted

The druid code fragement is like this :

public abstract class DruidAbstractDataSource extends WrapperAdapter implements DruidAbstractDataSourceMBean, DataSource, DataSourceProxy, Serializable {


    public boolean isOracle() {
        return isOracle;
    }

    public void setOracle(boolean isOracle) {
        if (inited) {
            throw new IllegalStateException();  // here throws the  exception 
        }
        this.isOracle = isOracle;
    }
	
}

Expected behavior
A clear and concise description of what you expected to happen.

No error log, don't update the druid configuration???

Actually behavior
A clear and concise description of what you actually to happen.

error log appears.

How to Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See errors

Desktop (please complete the following information):
OS: [Centos]
Version [e.g. nacos-server xxx, nacos-client 2.0.3,spring-boot-starter 2.3.9,spring-cloud-starter-alibaba-nacos-config 2.2.7 , druid-spring-boot-starter 1.1.24]
Module [e.g. naming/config]
SDK [e.g. original, spring-cloud-starter-alibaba-nacos-config, druid-spring-boot-starter]

Additional context
Add any other context about the problem here.

Stacktrace Info

org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.datasource.druid.ob1' to javax.sql.DataSource
	at org.springframework.boot.context.properties.bind.Binder.handleBindError(Binder.java:363)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:323)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:308)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:238)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:225)
	at org.springframework.boot.context.properties.ConfigurationPropertiesBinder.bind(ConfigurationPropertiesBinder.java:90)
	at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.bind(ConfigurationPropertiesBindingPostProcessor.java:89)
	at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:78)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:415)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1791)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:406)
	at org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder.rebind(ConfigurationPropertiesRebinder.java:108)
	at org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder.rebind(ConfigurationPropertiesRebinder.java:84)
	at org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder.onApplicationEvent(ConfigurationPropertiesRebinder.java:142)
	at org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder.onApplicationEvent(ConfigurationPropertiesRebinder.java:51)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361)
	at org.springframework.cloud.context.refresh.ContextRefresher.refreshEnvironment(ContextRefresher.java:96)
	at org.springframework.cloud.context.refresh.ContextRefresher.refresh(ContextRefresher.java:85)
	at org.springframework.cloud.endpoint.event.RefreshEventListener.handle(RefreshEventListener.java:72)
	at org.springframework.cloud.endpoint.event.RefreshEventListener.onApplicationEvent(RefreshEventListener.java:61)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361)
	at com.alibaba.cloud.nacos.refresh.NacosContextRefresher$1.innerReceive(NacosContextRefresher.java:133)
	at com.alibaba.nacos.api.config.listener.AbstractSharedListener.receiveConfigInfo(AbstractSharedListener.java:40)
	at com.alibaba.nacos.client.config.impl.CacheData$1.run(CacheData.java:312)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:750)
Caused by: java.lang.IllegalStateException: Unable to set value for property oracle
	at org.springframework.boot.context.properties.bind.JavaBeanBinder$BeanProperty.setValue(JavaBeanBinder.java:360)
	at org.springframework.boot.context.properties.bind.JavaBeanBinder.bind(JavaBeanBinder.java:101)
	at org.springframework.boot.context.properties.bind.JavaBeanBinder.bind(JavaBeanBinder.java:83)
	at org.springframework.boot.context.properties.bind.JavaBeanBinder.bind(JavaBeanBinder.java:59)
	at org.springframework.boot.context.properties.bind.Binder.lambda$bindDataObject$5(Binder.java:451)
	at org.springframework.boot.context.properties.bind.Binder$Context.withIncreasedDepth(Binder.java:571)
	at org.springframework.boot.context.properties.bind.Binder$Context.withDataObject(Binder.java:557)
	at org.springframework.boot.context.properties.bind.Binder$Context.access$300(Binder.java:512)
	at org.springframework.boot.context.properties.bind.Binder.bindDataObject(Binder.java:449)
	at org.springframework.boot.context.properties.bind.Binder.bindObject(Binder.java:390)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:319)
	... 35 common frames omitted
Caused by: java.lang.reflect.InvocationTargetException: null
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.boot.context.properties.bind.JavaBeanBinder$BeanProperty.setValue(JavaBeanBinder.java:357)
	... 45 common frames omitted
Caused by: java.lang.IllegalStateException: null
	at com.alibaba.druid.pool.DruidAbstractDataSource.setOracle(DruidAbstractDataSource.java:337)
	... 50 common frames omitted

Error Info

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant