将 Spring 3 bean 注入 JSF 2 托管 bean 的干净方法?

发布于 2024-12-12 17:22:59 字数 391 浏览 2 评论 0原文

我正在将当前的解决方案从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

离鸿 2024-12-19 17:22:59

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.

风流物 2024-12-19 17:22:59

您仍然可以将 Spring 与 JSF 2 一起使用。只需创建一个自定义 Spring 范围,然后将其用作 bean 的视图范围。

@Named @Scope("view")
public class MyBean {

    @Inject
    private MyManagedProperty oneService;

    //...

}

在这里窃取视图范围的实现: 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.

@Named @Scope("view")
public class MyBean {

    @Inject
    private MyManagedProperty oneService;

    //...

}

Steal the implementation of the View scope here: http://cagataycivici.wordpress.com/2010/02/17/port-jsf-2-0s-viewscope-to-spring-3-0/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文