如何声明和使用全局变量? [英] How to declare and use global variables?

查看:45
本文介绍了如何声明和使用全局变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制台应用程序.我想从数据库读取一些配置设置.这些设置应该存储在全局或会话变量中,以便我可以在整个应用程序中使用该变量,我该如何实施?有哪些方法?我需要使用哪些频道?以及应如何存储有效载荷?

i have a console application.i want to read some configuration settings from DB. And these settings should be stored in a global or session variable so i can use the variable through out the application , how can i implement it ? what are the ways ? which channels do i need to use ? and how payload should be stored?

推荐答案

你的意思完全不清楚,但是你可以将 Map 对象声明为 @Bean(或 <bean/>) 并在初始化期间加载它.

It's not at all clear what you mean, but you can declare a Map object as a @Bean (or <bean/>) and load it up during initialization.

然后,您可以通过 @Autowired 或通过 SpEL 在集成组件中的表达式中直接在组件中引用它:@mapBean['foo'].

You can then reference it directly in your components by @Autowired or via SpEL in expressions in integration components: @mapBean['foo'].

这篇关于如何声明和使用全局变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆