【问题标题】:How to inject some objects with @Autowired and integrate them with JSF如何使用 @Autowired 注入一些对象并将它们与 JSF 集成
【发布时间】:2016-01-26 23:39:08
【问题描述】:

我正在尝试将 Spring 与 JSF 集成。

@ManagedBean
@ViewScoped
public class SomeBean() implements Serializable{

    @Autowired
    private SomeService someService;   // with get and set
...
    @PostConstruct
public void init() {
      FacesContextUtils
    .getRequiredWebApplicationContext(FacesContext.getCurrentInstance())
    .getAutowireCapableBeanFactory().autowireBean(this.someService);
}

}

@Service
public class SomeServiceImpl implements SomeService{

    @Autowired
    SomeDao someDao;
...
}

我总是从 bean 中获取一些服务为空;它没有注入任何价值。 这是返回给我们的错误:

javax.servlet.ServletException: JBAS011048: No logró construir la instancia del componente javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)。

谁能告诉我如何正确执行此操作。在此先感谢。

我们依赖以下链接: Spring JSF integration: how to inject a Spring component/service in JSF managed bean?

@Autowired Spring service not injected in a managed bean

【问题讨论】:

    标签: spring jsf service javabeans autowired


    【解决方案1】:

    看看this post,以便将spring与JSF集成。

    【讨论】:

    • 嗨 olexd。事实上,我已经按照您发送给我的链接中的建议实施了解决方案:Spring Annotations。我做了同样的事情,但我有一个错误是没有注入:@Autowired UserBo userBo; public void setUserBo(UserBo userBo) { this.userBo = userBo; } 公共字符串 printMsgFromSpring() { return userBo.getMessage(); } 没有抛出异常,但它的值为 null。你知道为什么会这样吗?提前致谢。
    猜你喜欢
    • 1970-01-01
    • 2019-06-22
    • 1970-01-01
    • 1970-01-01
    • 2014-07-01
    • 2021-07-18
    • 1970-01-01
    • 1970-01-01
    • 2013-11-06
    相关资源
    最近更新 更多