我有一个使用Spring + jsf的网络应用。
我将确切的案例放在下面的代码中:
@Controller
@View("scope") // see https://cagataycivici.wordpress.com/2010/02/17/port-jsf-2-0s-viewscope-to-spring-3-0/
public BaseJsfController{
@Inject
@Getter //using lombok
protected MyCommonSpringSerivce commonSpringService;
@Getter
protected MyObject myVar;
@PostConsturct
public void init(){
myVar = ... // some value
System.out.println(commonSpringService); // works fine!
}
}
并且
@Controller
@View("scope")
public MyJsfController extends BaseJsfController{
@Inject
protected MySomeSpringSerivce someSpringService;
@Override
public void init(){
super.init();
System.out.println(myVar); // works fine!
System.out.println(commonSpringService); // works fine!
System.out.println(someSpringService); // works fine!
}
public void someJsfAction(){
System.out.println(myVar); // prints null!
System.out.println(commonSpringService); // prints null!
System.out.println(someSpringService); // works fine!
// however
System.out.println(getMyVar()); // works fine!
System.out.println(getCommonSpringService()); // works fine!
}
}
其他所有事情都按预期工作。
为什么这样工作?