我对春天有以下问题。我有一个 webapp 和一个域项目。域项目包含一个 studentService,它应该通过 webapp 的类中的自动装配注入。我已将 和 添加到 appcontext.xml。
这是来自 webapp 的类:
@Component
public class JSONToDomainObjects
{
@Autowired
private StudentService studentService;
private void bindSubmissionValuesToDomainObjects(Integer userKey) throws Exception
{
Student student = studentService.getStudentBySlNumber(userKey);
}
}
然后是学生服务:
@Service
public class StudentService
{
..
}
因此,一旦我启动我的应用程序,我就会看到 studentService 为空,但是当我获取 appcontext 并调用 getBean("studentService") 方法时,就会返回一个 studentservice 实例。我使用弹簧 3.0.5。有人知道自动装配失败的原因吗?
干杯,
迈克尔