如何使用@Autowired注入一些对象并将它们与JSF集成

时间:2016-01-26 23:39:09

标签: spring jsf service javabeans autowired

我正在尝试将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获取someService的null;它没有注入任何价值。 这是给我们的错误:

javax.servlet.ServletException:JBAS011048:Nologróconsitirla 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

1 个答案:

答案 0 :(得分:-1)

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

相关问题