【发布时间】:2015-05-26 14:37:34
【问题描述】:
我正在学习 Spring MVC,并尝试解决 @Autowired Service 对象的问题。我有以下注释:
@Autowired
private UserServiceBLInt userService;
这是在 Controller 类的上下文中,我在使用 userService 对象时得到一个 NullPointerException。我在课堂上没有任何地方手动实例化userService 对象,因为我的理解是,要让@Autowired 工作,我必须让spring 负责创建对象。
我的怀疑是在spring配置文件中,component-scan base-package声明不正确,所以Spring不知道去哪里找类。
<context:component-scan base-package="com.app.service.**" />
UserServiceBLInt 位于com.app.service.int
具体实现在com.app.service.impl
** 表示法是否正确?
【问题讨论】:
-
向我们展示您的上下文配置以及此特定案例中涉及的类。
-
如果您怀疑“**”是罪魁祸首,为什么不尝试不使用它呢?
-
你的服务类
@Service被注释了吗? -
@rc,我用一个 * 试过了,但还没有完全删除它
-
@araknoid,接口或者实现应该用@service注解吗?
标签: java spring spring-mvc