Results 1 to 3 of 3

Thread: Another @Autowired Question

  1. #1
    Join Date
    May 2011
    Posts
    2

    Default Another @Autowired Question

    Hello

    This is my first big spring app and I need some help!

    I am using Spring 3, I have Controllers, Services and DAO all working well using annotations.

    I need to use a service outside of a Controller, I have tried using the @Component for the class then using the
    Code:
    @Autowired 
    private Service service;
    But the services are always null.

    Please help!

    Many Thanks

  2. #2
    Join Date
    Apr 2009
    Posts
    20

    Default

    Hi Smyler86,

    I need to use a service outside of a Controller,
    This is where your problem comes from. This class must be managed by spring also. (not instantiated with java new keyword)

    Be sure also to advice spring to scan the autowired property

    Code:
    <context:component-scan base-package="com.my.fist.big.spring.app.package" />
    Where com.my.fist.big.spring.app.package is the package containing the calling class
    HTH

  3. #3
    Join Date
    May 2011
    Posts
    2

    Default

    Thank you!

    That makes perfect sense!

    Was generating a new class rather that @Autowired'ing it from the controller.

    Have fixed this now, works perfectly!

    Thanks Again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •