【发布时间】:2012-09-26 06:54:13
【问题描述】:
我在我的项目中使用 Spring 3。然后我从 JAR 文件中注入 spring bean 时遇到问题。在 JAR 文件中,有类似的类;
package test;
@Service("CommonService")
public class CommonService {
}
我已经这样用过了;
package com.java.test.app;
@Service(value = "OtherService")
public class OtherService {
@Resource(name = "CommonService")
private CommonService service;
}
在我的 spring-beans.xml 中;
<context:component-scan base-package="com.java.test.app, test">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan>
但是@Resource注解不起作用。我可以从JAR文件中注入spring bean吗?
【问题讨论】:
-
请显示您在jar文件类中定义@Resource注解的位置?
-
@Japs 我可以在我的 jar 文件类中声明“@Resource”注释吗?目前不是。
-
当然可以。您需要定义它,否则您将无法自动装配它。
标签: annotations spring-3