Spring managed bean subclass can't access protected service from superclass

181 views Asked by At

I have a web app that uses Spring + jsf.

I put the exact case in the code below:

@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!
    }
}

And

@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!
    }
}

Every other thing is working as expected.

Why is it working like this?

0

There are 0 answers