I have created a new web project from scratch using JSF 2.3 and Weld as CDI implementation running on Tomcat 9. This works all fine. Now I would like to add a dependency to a service library (Spring 4 + Hibernate 5) which implements e.g. the user authentication against a database. This is all existing code, so it cannot be modified. I have already read many articles, but unfortunately no one really helped me. I am facing the issue that I do not know how to inject the Spring-Bean (4.3.12.RELEASE) into a JSF-CDI managed bean.
@Named
@RequestScoped
public class AuthenticationController extends AbstractBean {
@Inject
transient private IUserService _springUserService;
@PostConstruct
public void postConstruct() {
// _springUserService is null
}
}
The service implementation class is annotated as
@Repository(IUserService.BEAN_NAME)
public class UserService implements IUserService {
//...
}
In web.xml
I have configured the spring context loader:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring-config-domain.xml
</param-value>
</context-param>
And in faces-config.xml
I have configured the Spring-EL-Resolver
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
- So which annotation do I need to have the Spring Bean injected?
- Am I missing any additional configuration for CDI in order to have it finding the Spring bean?
Thanks in advance and best regards!