Giter Site home page Giter Site logo

为什么ssm项目中使用@ApolloConfigChangeListener不能实时收到更新配置变化,而springboot项目可以呢 about apollo-use-cases HOT 9 OPEN

apolloconfig avatar apolloconfig commented on June 25, 2024
为什么ssm项目中使用@ApolloConfigChangeListener不能实时收到更新配置变化,而springboot项目可以呢

from apollo-use-cases.

Comments (9)

nobodyiam avatar nobodyiam commented on June 25, 2024

参考下 apollo-demo

from apollo-use-cases.

ls417316172 avatar ls417316172 commented on June 25, 2024

@nobodyiam 我将apollo-demo中的关于实时监听代码放到spring 的项目,还是不能实时接收到变化更新的推送变更,只能在源码设计的每5分钟轮询拉取的时候才能获取到,请您帮忙解答,谢谢

from apollo-use-cases.

klboke avatar klboke commented on June 25, 2024

@ls417316172 监听器所在的bean需要被spring管理才行,你检查下是否没有被spring管理

from apollo-use-cases.

ls417316172 avatar ls417316172 commented on June 25, 2024

@klboke 如下是我写的监听器代码:

@lazy(false)
@component
public class ConfigTest {

@ApolloConfigChangeListener
public void onChangeGlobal(ConfigChangeEvent changeEvent) {
    for (String key : changeEvent.changedKeys()) {
        ConfigChange change = changeEvent.getChange(key);
        System.err.println("==========application:" + key);

    }
}

}
我验证从ApplicationContext中可以获取监听器类,但是,配置管理页面对 其中的key修改时,监听器不能实时获取到,只能在过5分钟才能获取到,请你给解释,我同样的代码写在springboot的项目就可以实时获取到

from apollo-use-cases.

klboke avatar klboke commented on June 25, 2024

确认在spring里有ConfigTest这个实例了么,我这边是可以实时生效的

from apollo-use-cases.

ls417316172 avatar ls417316172 commented on June 25, 2024

@klboke 发您的代码段我看看呢

from apollo-use-cases.

ls417316172 avatar ls417316172 commented on June 25, 2024

@klboke 以下是获取ConfigTest实力对象的验证代码(随便写了个测试类):

@RestController
@RequestMapping("/a/sys/register")
public class testConfigTest implements ApplicationContextAware {
private ApplicationContext applicationContext;

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    this.applicationContext = applicationContext;
}

/**
 * 测试是否在spring容器中
 */
@RequestMapping("123")
public void test123() {
    System.out.println("application容器实体类:"+applicationContext.getBean(ConfigTest.class));
}

}
结果:application容器实体类:com.datangwealth.common.config.ConfigTest@714824d6
您看一下是否有问题,谢谢

from apollo-use-cases.

ls417316172 avatar ls417316172 commented on June 25, 2024

@klboke 我的微信号就是我的github账号(ls417316172),如果您有时间我希望加您一下微信,进行更深层次的学习和验证,谢谢

from apollo-use-cases.

klboke avatar klboke commented on June 25, 2024

我用的是apollo项目里的demo测试的

from apollo-use-cases.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.