将 Spring 3 bean 注入 JSF 2 托管 bean 的干净方法?
我正在将当前的解决方案从 JSF 1.2 迁移到 JSF 2。由于我需要使用新的视图范围,所以我使用 JSF 2 注释。这迫使我使用 JSF @ManagedProperty 注释而不是 Spring 的 @Autowired 注入 Spring beans
以前是这样的:
@Autowired private OneService oneService
现在是这样的:
@ManagedProperty(value="#{oneServiceImpl}")
private OneService oneService
你知道是否有一种方法可以注释托管属性而不需要声明它们的 bean姓名?
谢谢!
I'm migrating our current solution from JSF 1.2 to JSF 2. As I need to use the new View scope I'm using JSF 2 annotations. That forced me to inject the Spring beans using the JSF @ManagedProperty annotation instead of Spring's @Autowired
Before it was something like this:
@Autowired private OneService oneService
And now it's like:
@ManagedProperty(value="#{oneServiceImpl}")
private OneService oneService
Do you know if is there a way to annotate the managed properties without needing to state their bean name?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,没有。 JSF 使用表达式语言 (EL) 来确定您通过名称引用哪个类。使用名为 ELResolver 的类,他获取传递的字符串,解释并做出适当的参考。类 SpringBeanFacesELResolver 提供两个框架之间的集成,拦截请求并将其传递到 Spring 的上下文,Spring 处理提供 ManagedBeans 所需的依赖关系,然后 Spring 将其传递给 JSF 自己的EL解析器。因此 JSF 需要 bean 的名称来知道要注入什么。
No, there isn't. JSF makes use of Expression Language (EL) to determine which class you refer by name. Using a class called ELResolver he takes the String passed, interprets and makes the appropriate reference. The class SpringBeanFacesELResolver provides integration between the two frameworks intercepts the request and passing it to the context of Spring, which handles the dependencies required to provide the ManagedBeans, who then passes it to the JSF's own ELResolver. So JSF needs the name of the bean to know what to inject.
您仍然可以将 Spring 与 JSF 2 一起使用。只需创建一个自定义 Spring 范围,然后将其用作 bean 的视图范围。
在这里窃取视图范围的实现: http://cagataycivici.wordpress.com/2010/02/17/port-jsf-2-0s-viewscope-to-spring-3-0/
You can still use Spring with JSF 2. Just create a custom Spring scope which can then be used as the view scope for your beans.
Steal the implementation of the View scope here: http://cagataycivici.wordpress.com/2010/02/17/port-jsf-2-0s-viewscope-to-spring-3-0/