I meant to say you declared it twice

On Fri, Jun 10, 2011 at 3:47 PM, Sergey Beryozkin <[email protected]> wrote:
> Looks like you have declared CategoryService, check beans.xml and jaxrs.xml
>
> Sergey
>
> On Fri, Jun 10, 2011 at 12:46 PM, odyssey045 <[email protected]> 
> wrote:
>> 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.
>>
>> @Path("/categoryservice")
>> @Produces("application/xml")
>> 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 ");
>>        else
>>            System.out.println("Why is it not
>> working?"+this.categoryDAO.getCategory("001").getCategoryName());
>> /** This is being printed **/
>>    }
>>    @GET
>>    @Path("/category/{id}")
>>    @Consumes("application/xml")
>>    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
>> **/
>>        else
>>            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
>> work.
>>
>> --
>> View this message in context: 
>> http://cxf.547215.n5.nabble.com/Spring-cxf-the-injected-bean-in-the-service-is-not-persisted-Get-NPE-tp4475916p4475916.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
>

Reply via email to