I tried union Spring 3(MVC) with JSF 2. I have some experience in Spring and JSF, but never tried to join them before. In the end I have 2 files
@ManagedBean(name = "userBean")
@Scope
@Component
public class someBean {
@Autowired
private TestService testService;
public void printString() {
System.out.println(testService.getString());
}
}
and
@ManagedBean(name = "studentBean")
@Scope
@Component
public class StudentBean {
@Autowired
private TestService testService;
public void printString() {
System.out.println(testService.getString());
}
}
For these file I have right configuration for spring, jsf, and web.xml. And have .xhtml page where I start printString() for 'someBean' and for 'StudentBean'. I have the NPE in first case and 'some string' in the console in second case. The reason is simple - different bean names in the Spring context and JSF. all problems finished after
@Component => @Component("userBean")
public class someBean {
In the debug I saw that
private TestService testService;
@Autowired
public void setTestService(TestService testservice) {
this.testService = testService;
}
When JSF bean is creating testService sets not null, but it is null during JSF lifecycle when
public void pringString() {
testService.blah();
}
testService is null. It is what I can't understand. Has someone deep knowledge the Spring and JSF to describe this situation in details?