Announcement Announcement Module
Collapse
No announcement yet.
Another @Autowired Question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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.

      Comment

      Working...
      X