spring自动装配失败但appcontext解析bean
我对春天有以下问题。我有一个网络应用程序和一个域项目。域项目包含一个 StudentService,应通过自动装配将其注入到 Web 应用程序的类中。我已将 和 添加到 appcontext.xml 中。
这是来自web应用程序的类:
@Component
public class JSONToDomainObjects
{
@Autowired
private StudentService studentService;
private void bindSubmissionValuesToDomainObjects(Integer userKey) throws Exception
{
Student student = studentService.getStudentBySlNumber(userKey);
}
}
然后是studentservice:
@Service
public class StudentService
{
..
}
所以一旦我启动我的应用程序,我就会看到studentService为空,但是当我获取appcontext并调用方法getBean(“studentService”)时,会返回一个studentservice实例。我用的是spring 3.0.5。有人知道自动装配失败的原因吗?
干杯,
迈克尔
i have the following issue with spring. I have a webapp and a domain project. the domain project contains a studentService which should be injected through autowiring in a class of the webapp. I've added and to the appcontext.xml.
this is the class from the webapp:
@Component
public class JSONToDomainObjects
{
@Autowired
private StudentService studentService;
private void bindSubmissionValuesToDomainObjects(Integer userKey) throws Exception
{
Student student = studentService.getStudentBySlNumber(userKey);
}
}
then the studentservice:
@Service
public class StudentService
{
..
}
So once I startup my app I see that the studentService is null, but when I get the appcontext and invoke the method getBean("studentService") than a studentservice instance is returned. I use spring 3.0.5. Does anybody have a clue why the autowiring fails?
cheers,
Michael
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不在测试类中也使用依赖注入呢?像这样的东西:
Why don't you use dependency injection in your testclasses as well? Something like this:
您是否在 appcontext.xml 中使用
?Are you using
<context:annotation-config/>
in your appcontext.xml?