问题描述
我迁移我们目前从JSF 1.2到JSF 2的解决方案,因为我需要用我使用JSF 2注解新的视图范围。这迫使我注入使用JSF @ManagedProperty注解来替代Spring的@Autowired的Spring 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
之前,它是这样的:
@Autowired private OneService oneService
而现在它就像:
@ManagedProperty(value="#{oneServiceImpl}")
private OneService oneService
你知道,如果有一种方法,而无需注明bean的名字来注释托管属性?
Do you know if is there a way to annotate the managed properties without needing to state their bean name?
谢谢!
推荐答案
没有,没有。 JSF利用防爆pression语言(EL)来确定你的名字是指哪一类。利用一种称为他以字符串传递类,除$ p $点,使适当的参考。类 SpringBeanFacesELResolver 提供了两个框架之间的集成截取请求并将它传递给Spring上下文,它处理提供ManagedBeans,谁然后将其传递到JSF自己ELResolver所需的依赖关系。所以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 bean的3成一个JSF 2托管bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!