2010-08-04 88 views
1

我使用的是不直接由我的@Controller调用的类,当我尝试使用该类中的@Autowired propeprty时,定义为@Service,属性为null。但@Autowired具有相同的标记将在@Controller内工作。是否可以在@Service中使用Spring 3 @Autowired注释?

示例代码:

@Service 
public class UsernameValidator implements Validator { 

    @Autowired private UserDao userDao; 

    // code here when used, userDao is always null 

} 

回答

1

这应该完全正常工作,如果你有以下的applicationContext.xml

<context:component-scan base-package="com.yourproject" /> 
相关问题