alibaba / nacos

an easy-to-use dynamic service discovery, configuration and service management platform for building cloud native applications.
https://nacos.io
Apache License 2.0
30.23k stars 12.83k forks source link

SpringBoot 采用 nacos.xml 配置方式,无法动态刷新配置 #5229

Closed hahapigs closed 3 years ago

hahapigs commented 3 years ago

SpringBoot 采用 nacos.xml 配置方式,无法动态刷新配置

nacos.xml

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:nacos="http://nacos.io/schema/nacos" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://nacos.io/schema/nacos http://nacos.io/schema/nacos.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">

<context:property-placeholder location="classpath*:application.properties"/>
<context:property-placeholder location="classpath*:application-${spring.profiles.active}.properties" />

<!--开启注解-->
<nacos:annotation-driven/>
<!-- 指定nacos配置地址 -->
<nacos:global-properties server-addr="${nacos.server-addr}" />

<!-- 银联电子发票配置-->
<nacos:property-source data-id="unionpay-fapiao-conf" group-id="unionpay" auto-refreshed="true"/>

application.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">

<!-- 银联电子发票 -->
<bean id="invoiceProperty" class="cn.efw.fw.invoice.property.InvoiceProperty">
    <property name="msgSrc" value="${fapiao.msgSrc}"></property>
    <property name="md5key" value="${fapiao.md5key}"></property>
</bean>
<bean id="invoiceFactory" class="cn.efw.fw.invoice.property.InvoiceFactory">
    <property name="invoiceProperty" ref="invoiceProperty"></property>
</bean>

启动类 Application.java

@ImportResource(locations = {"classpath:spring/.xml", "classpath:spring//*.xml", "classpath:nacos/nacos.xml"})

realJackSun commented 3 years ago

这里namespace没有设置,会去默认namespace下读取数据,检查一下是和nacos服务端的命名空间不一致导致的么?

hahapigs commented 3 years ago

这里namespace没有设置,会去默认namespace下读取数据,检查一下是和nacos服务端的命名空间不一致导致的么?

不是的,默认从public下读取的,而且项目启动,都拉去到配置了,但是重新发布一个配置,工厂管理的 properties 的bean无法动态获取配置

stale[bot] commented 3 years ago

Thanks for your feedback and contribution. But the issue/pull request has not had recent activity more than 180 days. This issue/pull request will be closed if no further activity occurs 7 days later. We may solve this issue in new version. So can you upgrade to newest version and retry? If there are still issues or want to contribute again. Please create new issue or pull request again.