如何@autowire到jsf托管bean

发布于 2024-10-07 15:47:50 字数 243 浏览 0 评论 0原文

为了使用@Autowire注解,使用该注解的对象必须来自spring上下文。

JSF 托管 bean 是由 JSF 的 IOC 而不是 Springs 创建的,因此我不能在其中使用 @Autowire ,必须使用 faces-config.xml 和托管属性。

我已经设置了一个 EL 解析器,让 spring bean 作为托管属性,我想更进一步,摆脱每次需要自动装配某些东西时进入 faces-config.xml 的需要。这可能吗?

In order to use the @Autowire annotation, the object where you use the annotation must come from the spring context.

JSF managed beans are created by JSF's IOC not Springs, therefor i cannot use @Autowire inside of them must must use faces-config.xml and managed properties.

I already setup an EL resolver that lets be have spring beans as managed properties, i want to take it one step further and get rid of the need to go into the faces-config.xml every time i need to autowire something. Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

离线来电— 2024-10-14 15:47:50

只需使用 @Controller (或 @Component)和 @Scope("request") (或 session< /code>)并添加 (如果没有的话),托管 bean 将自动被检测为 spring bean。既然你已经在使用 ELResolver,那就应该是这样了 - 你应该能够使用 @Autowired (或者更好 - @Inject,如果使用 spring 3.0)。

Just annotate your managed beans with @Controller (or @Component), and @Scope("request") (or session) and add <context:component-scan> (if you haven't), and managed beans will automatically be detected as spring beans. And since you are already using the ELResolver, that should be it - you should be able to use @Autowired (or better - @Inject, if using spring 3.0).

白馒头 2024-10-14 15:47:50

您可以使用 @ManagedProperty(#{'someBean'}) 在 jsf bean 中自动装配其他 bean

You can use @ManagedProperty(#{'someBean'}) for autowire other beans in jsf bean

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