我使用的类不是我的 @Controller 直接使用,当我尝试使用 @Autowired 在那一类中的属性定义为 @Service 财产是 null . 但是 @自动售货机 具有相同标记的将在内部工作 @控制器 .
@Controller
@Autowired
@Service
null
@自动售货机
@控制器
示例代码:
@Service public class UsernameValidator implements Validator { @Autowired private UserDao userDao; // code here when used, userDao is always null }
如果您的 applicationContext.xml :
applicationContext.xml
<context:component-scan base-package="com.yourproject" />