newbie
newbie

Reputation: 24625

Is it possible to use Spring 3 @Autowired annotation inside @Service?

I'm using class that is not called by my @Controller directly and when I try to use @Autowired propeprty in that class what is defined as @Service, property is null. But @Autowired with same markup will work inside @Controller.

Example code:

@Service
public class UsernameValidator implements Validator {

    @Autowired private UserDao userDao;

    // code here when used, userDao is always null

}

Upvotes: 1

Views: 1524

Answers (1)

Bozho
Bozho

Reputation: 597006

This should work perfectly fine, if you have the following in your applicationContext.xml:

<context:component-scan  base-package="com.yourproject" />

Upvotes: 1

Related Questions