cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odyssey045 <>
Subject Spring + cxf, the injected bean in the service is not persisted.Get NPE
Date Fri, 10 Jun 2011 11:46:44 GMT
I have a simple REST service class which looks something like this...
The DAO over here is being injected by spring. I am able to see the dao
member property being set when the container loads up.

Unfortunately when i access this particular property at a later point of
time, it turns out to be null (its initial value)

To test this out, i tried changing a value of a normal "int" when the
injection of the bean happened.. I find that when i access this value of int
while the web service is being processed, it displays the initial value of
"3" instead of the modified value of "5" which is set in setCategoryDAO. 

public class CategoryService {

    public CategoryService() {
        System.out.println("Lets see when i am getting called");
    CategoryDao categoryDAO = null;
    int a = 3;
    public CategoryDao getCategoryDAO() {
        return categoryDAO;
    //TODO with spring
    public void setCategoryDAO(CategoryDao categoryDAO) {
        System.out.println("Will this ever get called!!");
        a= 5; // value modified
        this.categoryDAO = categoryDAO;
        if (this.categoryDAO  == null) 
            System.out.println("THIS IS NULL ");
            System.out.println("Why is it not
/** This is being printed **/
    public Category getCategory(@PathParam("id") String id) {
        System.out.println("The id to fetch is "+id);
        System.out.println("The value of a is "+a); // a = 3 over here!
        CategoryDao cdao = getCategoryDAO();   
        if (this.categoryDAO == null) 
            System.out.println("THIS IS NULL"); /** This is being printed
            System.out.println("Why is it not working?");
        Category cat = this.categoryDAO.getCategory(id);
        return cat;
Why is this happening? And is there a way i can retain its state across
various requests? I tried setting the bean scope to "session". But it doesnt

View this message in context:
Sent from the cxf-user mailing list archive at

View raw message