当前位置: 首页 > 知识库问答 >
问题:

配置刷新在路由声明中不起作用

翟俊远
2023-03-14

我使用的是Spring-Cloud的配置服务器。我希望刷新应用程序的配置,而不必重新启动它。

这是我的场景:

1)application.yml中的单个配置,存储在git中

job:
 demo:
  testMessage: 'My ID is 123'
@RefreshScope
@Component
@RestController
public class DemoController {

  @Value("${job.demo.testMessage}")
  String testMessage;

  @RequestMapping(value = "/", produces = "application/json")
  public List<String> index() {
      List<String> env = Arrays.asList(
            "config 1 is: " + testMessage
      );
      return env;
  }
}
@RefreshScope
@Slf4j
@Setter
@Component
@ConfigurationProperties(prefix = "job.demo")
public class DemoFlow {

    private String testMessage;

    @Bean
    public IntegrationFlow putDemoModelFlow() {
        return IntegrationFlows.from(Http.inboundChannelAdapter("/demoFlow"))
            .handle(new DemoHandler())
            .handle(m -> log.info("[LOGGING DEMO] {}" , m.getPayload()))
            .get();
    }

    private class DemoHandler implements GenericHandler {

        @Override
        public String handle(Object payload, Map headers) {
            return new StringBuilder().append(testMessage)
                .append(" ").toString();
        }
    }
}
job:
 demo:
  testMessage: 'My ID is 789'

5)运行刷新

curl -d{} http://localhost:8002/refresh

在对controller的rest调用中,一切正常,配置被更新。

["config 1 is: My ID is 789"]

但是在对集成流的rest调用中,配置没有更新:

[LOGGING DEMO] My ID is 123

共有1个答案

谷泳
2023-03-14

我不认为将@configuration类放入@refreshScope会将其中声明的bean放入该作用域。

此外,IntegrationFlow@bean在内部生成许多bean,它们肯定不会放在这个范围内。您不应该尝试“刷新”集成流,这可能会导致运行时问题。

相反,您应该将该属性放在与流不同的类中,并将其注入到DemoHandler@bean中。

 类似资料:
  • 问题内容: 我期待在Stackoverflow上看到这个问题,但是没有。显然,我是唯一出现此问题的人,在我看来这很普遍。 我正在执行一个基本项目,但是即使到目前为止我所做的一切似乎都是正确的,但路线似乎也不起作用。 我的文件中有这段html : 这是我的: 现在,当我刚访问页面时,这就是我从URL中获得的内容: http:// localhost:8000 / admin#!/ 当我单击按钮时,得

  • 问题内容: 我已经按照教程在我的应用程序中实现了路由 http://docs.angularjs.org/tutorial/step_07 我无法在IE7中使用我的版本,花了一段时间尝试找出我错过/做错的事情后,我注意到该示例不起作用。 http://angular.github.com/angular- phonecat/step-7/app/ 有人知道如何使它工作吗? 问题答案: 好的,我遇到

  • 由于以下错误(npm 3.10.10,webpack 3.8.1),我无法使用vue routes get。如何解决这个问题 编译失败。 ./node_modules/babel loader/lib/node_modules/vue loader/lib/selector.js?type=script 我使用简单的网页包 Quotes.vue Quote.vue new-quote.vue Ap

  • 每个路由可以有不同的属性; 一些常见的属性是: path - 应用程序在特定路由上时在浏览器中显示的URL component - 当应用程序在特定路由上时要呈现的组件 pathMatch - 默认为’prefix’的可选属性。 确定是匹配完整的网址还是仅匹配开头。 当定义一个具有空路径字符串的路径设置pathMatch为’full’时,否则它将匹配所有路径。 children - 表示此路由的子

  • 我刚刚开始学习laravel,我正在使用MAMP。我在这个url上有一个表单:http://localhost:8888/laravel-site/my new app/public/ducks但当我提交表单时,它会将我带到此url:http://localhost:8888/ducks不会停留在我期望的地方。 routes.php文件包含以下内容: 在我的生活中。htaccess文件我有这个:

  • 我已经尝试使用Config Server实现spring外部配置。当应用程序启动时,它第一次工作得很好,但对属性文件的任何更改都不会反映出来。我试图使用/refreshendpoint来动态刷新我的属性,但它似乎不起作用。在这方面的任何帮助都将是非常有帮助的。 我尝试向localhost:8080/refresh发帖,但得到404错误响应。 下面是我的应用程序类的代码 和bootstrap.pro