奋斗的小同志 2025-01-14 10:04 采纳率: 0%
浏览 118
已结题

DruidDataSource一直closing

springboot集成seata,nacos更改配置文件导致 DruidDataSource一直closing,NacosPropertySourceBuilder反复监听,一直循环

 <spring-cloud-alibaba-dependencies.version>2021.0.4.0</spring-cloud-alibaba-dependencies.version>
        <spring-boot-dependencies.version>2.6.11</spring-boot-dependencies.version>
        <spring-cloud-dependencies.version>2021.0.4</spring-cloud-dependencies.version>

集成seata1.5.2
nacos动态管理配置文件,修改后,控制提示,

[user-center:192.168.1.206:7000] 2025-01-14 08:31:16.222 INFO 33068 [-] [nacos.client.cachedata.internal.notifier] com.alibaba.druid.pool.DruidDataSource   {dataSource-2} closing ...
[user-center:192.168.1.206:7000] 2025-01-14 08:31:20.526 WARN 33068 [-] [nacos.client.cachedata.internal.notifier] c.a.c.n.c.NacosPropertySourceBuilder     Ignore the empty nacos configuration and get it based on dataId[user-center] & group[DEFAULT_GROUP]
[user-center:192.168.1.206:7000] 2025-01-14 08:31:20.539 WARN 33068 [-] [nacos.client.cachedata.internal.notifier] c.a.c.n.c.NacosPropertySourceBuilder     Ignore the empty nacos configuration and get it based on dataId[user-center-labour.yml] & group[DEFAULT_GROUP]
[user-center:192.168.1.206:7000] 2025-01-14 08:31:20.539 INFO 33068 [-] [nacos.client.cachedata.internal.notifier] b.c.PropertySourceBootstrapConfiguration Located property source: [BootstrapPropertySource {name='bootstrapProperties-user-center-labour.yml,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-user-center.yml,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-user-center,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-saas_common.yml,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-common.yml,DEFAULT_GROUP'}]
[user-center:192.168.1.206:7000] 2025-01-14 08:31:20.586 INFO 33068 [-] [nacos.client.cachedata.internal.notifier] o.s.boot.SpringApplication               The following 1 profile is active: "labour"
[user-center:192.168.1.206:7000] 2025-01-14 08:31:20.628 INFO 33068 [-] [nacos.client.cachedata.internal.notifier] o.s.boot.SpringApplication               Started application in 1.399 seconds (JVM running for 33463.133)
[user-center:192.168.1.206:7000] 2025-01-14 08:31:21.270 INFO 33068 [-] [nacos.client.cachedata.internal.notifier] com.alibaba.druid.pool.DruidDataSource   {dataSource-2} closing ...

seata配置

@Configuration
@PropertySource(factory = YamlPropertySourceFactory.class, value = "classpath:saas-seata.yml")
public class SeataConfiguration {



    @Bean
    @ConfigurationProperties(prefix = "spring.datasource.druid")
    public DruidDataSource druidDataSource() {
        return DruidDataSourceBuilder.create().build();
    }



    @Primary
    @Bean
    public DataSourceProxy dataSourceProxy(DruidDataSource druidDataSource) {
        return new DataSourceProxy(druidDataSource);
    }

}



 <!-- seata-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>druid</artifactId>
                    <groupId>com.alibaba</groupId>
                </exclusion>
            </exclusions>
        </dependency>

启动时候 @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})

不集成seata,则正常日志

[uaa-server:192.168.1.206:8000] 2025-01-14 09:02:04.927 WARN 42556 [-] [nacos.client.cachedata.internal.notifier] c.a.c.n.c.NacosPropertySourceBuilder     Ignore the empty nacos configuration and get it based on dataId[uaa-server] & group[DEFAULT_GROUP]
[uaa-server:192.168.1.206:8000] 2025-01-14 09:02:04.968 WARN 42556 [-] [nacos.client.cachedata.internal.notifier] c.a.c.n.c.NacosPropertySourceBuilder     Ignore the empty nacos configuration and get it based on dataId[uaa-server-labour.yml] & group[DEFAULT_GROUP]
[uaa-server:192.168.1.206:8000] 2025-01-14 09:02:04.968 INFO 42556 [-] [nacos.client.cachedata.internal.notifier] b.c.PropertySourceBootstrapConfiguration Located property source: [BootstrapPropertySource {name='bootstrapProperties-uaa-server-labour.yml,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-uaa-server.yml,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-uaa-server,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-saas_common.yml,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-common.yml,DEFAULT_GROUP'}]
[uaa-server:192.168.1.206:8000] 2025-01-14 09:02:05.047 INFO 42556 [-] [nacos.client.cachedata.internal.notifier] o.s.boot.SpringApplication               The following 1 profile is active: "labour"
[uaa-server:192.168.1.206:8000] 2025-01-14 09:02:05.064 INFO 42556 [-] [nacos.client.cachedata.internal.notifier] o.s.boot.SpringApplication               Started application in 1.917 seconds (JVM running for 36283.472)
[uaa-server:192.168.1.206:8000] 2025-01-14 09:02:05.939 INFO 42556 [-] [nacos.client.cachedata.internal.notifier] com.alibaba.druid.pool.DruidDataSource   {dataSource-1} closing ...
[uaa-server:192.168.1.206:8000] 2025-01-14 09:02:06.600 INFO 42556 [-] [nacos.client.cachedata.internal.notifier] o.s.c.e.event.RefreshEventListener       Refresh keys changed: 

  • 写回答

37条回答 默认 最新

  • 道友老李 JWE233286一种基于机器视觉的水表指针读数识别及修正的方法 专利发明者 2025-01-14 10:05
    关注
    让【道友老李】来帮你解答,本回答参考gpt编写,并整理提供,如果还有疑问可以点击头像关注私信或评论。
    如果答案让您满意,请采纳、关注,非常感谢!
    根据你提供的情况,可能是因为修改Nacos配置文件导致DruidDataSource一直在关闭和重新创建,然后NacosPropertySourceBuilder不断监听和重新加载配置,导致了循环的问题。 解决方案可以尝试以下几点:
    1. 检查Nacos配置文件是否正确,确保配置文件内容正确,不要出现空的或错误的配置项,以及不要修改频繁。
    2. 检查DruidDataSource的配置是否正确,可能是因为配置不正确导致了DataSource的频繁关闭和重新创建。
    3. 可以尝试更新Spring Cloud Alibaba的依赖版本到最新,可能已经修复了相关的Bug。
    4. 考虑使用Spring Cloud Config替代Nacos作为配置中心,看是否能解决这个问题。 案例代码参考:
    @Configuration
    @PropertySource(factory = YamlPropertySourceFactory.class, value = "classpath:saas-seata.yml")
    public class SeataConfiguration {
        
        @Bean
        @ConfigurationProperties(prefix = "spring.datasource.druid")
        public DruidDataSource druidDataSource() {
            return DruidDataSourceBuilder.create().build();
        }
        
        @Primary
        @Bean
        public DataSourceProxy dataSourceProxy(DruidDataSource druidDataSource) {
            return new DataSourceProxy(druidDataSource);
        }
    }
    

    这是一个可能的解决方案,根据具体情况可能需要进一步调试和改进。

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 1月16日
  • 修改了问题 1月14日
  • 赞助了问题酬金15元 1月14日
  • 创建了问题 1月14日