JSF2托管bean批注+范围+注入混乱 [英] JSF2 managed bean annotation + scope + injection confusion

查看:85
本文介绍了JSF2托管bean批注+范围+注入混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现这种理想主义:

I would like to achieve this idealism :

  1. 对于JSF Bean容器只有一种实现,例如仅使用Spring或Weld,而不能同时使用两者.目前,我在后端使用Spring,所以我更喜欢Spring.
  2. 只有1个注释,可以在@ ManagedBean,@ Named和@Model之间进行选择
  3. 要能够使用所有受支持的范围,例如@ RequestScoped,@ SessionScoped,@ ViewScoped,@ FlashScoped,甚至还有@ConversationScoped
  4. 可以使用@Inject或@Autowired向JSF Bean注入spring-managed服务(后端服务)

到目前为止,我一直没有找到实现这些目标的最佳组合,因为据我所知,如果我错了,请纠正我,:

So far i've been finding no best combination to achieve these because as far as i know, please correct me if i am wrong, :

  1. @ManagedBean不能注入spring服务吗?
  2. @Named可以使用@Inject注入spring服务,但是@Named使用Weld.我可以只使用spring来管理@Named而不是Weld吗?
  3. @Named不支持@ViewScoped和FlashScope吗?

请分享您的想法和经验.

Please share your thoughts and experiences.

谢谢:-)

找到了一个有趣的页面描述如何用Spring替代Jboss Weld作为JSR 299 CDI实现.因此,基本上,问题2已得到回答.由于我现在可以注入spring服务,因此也间接回答了1号.

Found an interesting page that describes how to replace Jboss Weld with Spring as the JSR 299 CDI implementation. So basically, the question number 2 is answered. Number 1 is also answered indirectly since i can now inject spring services.

但是,第3个问题仍然存在.如果可以在@Named中使用@ViewScoped和Flash Scope,我会发现非常有用,例如

But still, the number 3 question remains. I would find very helpful if i can use the @ViewScoped and Flash Scope in the @Named, something like this article. Flash scope implementation has yet to be seen, but the closest one i can get so far is this page.

希望,将焊接替换为spring作为jsr 299实现仍将使我能够使用@ConversationScoped.

Hopefully, replacing weld with spring as the jsr 299 implementation will still enable me to use @ConversationScoped.

现在要测试一下,祝我好运:-)

Gotta test things now, wish me luck :-)

成功地使用Spring 3而不是焊接来进行@Named @Inject.重要的是在faces-config.xml中设置el-resolver.

Successfully make use of Spring 3 instead of weld to do the @Named, @Inject. The important thing is to set the el-resolver in the faces-config.xml.

AFAIK,Spring 3当前​​尚不支持CDI,因此bye2 @ConversationScoped.

AFAIK, Spring 3 currently doesnt support CDI yet, so bye2 @ConversationScoped.

对于作用域,我仍然必须使用@Scope("request")或@Scope("session"),但是如果我更喜欢@RequestScoped(javax.enterprise.context.RequestScoped)和@SessionScoped,我可以本文.

For the scoping, i must still use @Scope("request") or @Scope("session"), but if i prefer the @RequestScoped (javax.enterprise.context.RequestScoped) and @SessionScoped, i can make use of the bridge provided from this article.

但是,仍然存在一个问题,如何在Scope("view")-beans之间传递对象. 祝我好运!

One problem remain though, how to pass objects between Scope("view")-beans .. Wish me luck !

啊..终于完成了.. 使用JSF2提供的Flash传递变量确实像魔术一样. 我不需要第三方实现.

Ahhh .. finally done .. Passing the variables using Flash provided by JSF2 really works like magic. I dont need an 3rd party implementation for that.

因此,基本上,我可以不用焊接,但可以使用弹簧,只要有可用的通用范围(包括视图范围),dan就可以使用Flash对象在bean之间传递.

So basically, i can do without weld, but with spring, with the common scopes available, including the view scope, dan can pass between beans using the flash object.

缺少的一件事是对话范围,这对我来说不是一个主要问题. 希望未来的春天能够支持这个对话范围.

One thing missing is the conversation scope, which isnt a major problem to me yet. Hopefully the future spring can support this conversation scope.

干杯:-)

推荐答案

焊接(实际上,或多或少地发明了JSR-299上下文和依赖注入(也称为Java EE 6 CDI)来代替Spring在Java EE 6环境中.我建议使用Java EE 6 CDI代替Spring.当Java EE 6开箱即用时,为什么要使用第3方框架?

Weld (actually, the reference implementation of JSR-299 Context and Dependency Injection, also known as Java EE 6 CDI) was less or more invented to supplant Spring in Java EE 6 environments. I would suggest to use Java EE 6 CDI instead of Spring. Why would you use a 3rd party framework when Java EE 6 provides the same functionality out the box?

如果Spring后端确实无法更改,那么我建议您坚持使用它,不要与Java EE 6 CDI批注混合使用,以免造成混乱和维护麻烦.

If the Spring backend really cannot be changed, then I'd suggest to stick to it and not to intermix with Java EE 6 CDI annotations to save yourself from confusions and maintenance headache.

这篇关于JSF2托管bean批注+范围+注入混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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