如何获得春天MessageContext
来自 Java 类?
我应该使用一些@Resource
or @Autowire
注射context
var 到类,或者,例如,使用一些全局上下文 SpringContext 或其他一些以获得MessageContext
.
什么是方法?
如果我理解正确的话您正在将 Spring Webflow 与 JSF 一起使用并且需要访问 Webflow消息上下文 http://docs.spring.io/spring-webflow/docs/current/api/org/springframework/webflow/execution/RequestContextHolder.html从 JSF 内部动作监听器 http://download.oracle.com/docs/cd/E17802_01/j2ee/javaee/javaserverfaces/2.0/docs/api/javax/faces/event/ActionListener.html?
如果是这样,您可以随时使用请求上下文持有者 http://static.springsource.org/spring-webflow/docs/2.0.x/javadoc-api/org/springframework/webflow/execution/RequestContextHolder.html(注意使用 Webflow 中的一个,因为 Spring MVC 有它自己的!),但它使用ThreadLocal
所以它不太优雅:
MessageContext messageContext =
RequestContextHolder.getRequestContext().getMessageContext();
您不能使用标准 DI,因为MessageContext
根据每个请求创建FlowExecutor
在每个流程开始或恢复时,使用MessageSource
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)