如果 spring bean 在 jar 文件中使用了注解,我如何在我的类中加载 mythe bean 实例?
在 jar 文件中
package org.java.service.test;
@Service(value = "MyService")
public class MyService {
@Resource(name = "myproperties")
private Properties properties;
}
在我的项目中
package org.java.project.test;
@Service(value = "OtherService")
public class OtherService {
@Resource(name = "MyService")
private MyService myService;
}
在 spring-beans.xml 中
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" ....>
<context:annotation-config/>
<context:component-scan base-package=org.java.service.test, org.java.project.test"/>
.....
</beans>
我也尝试如下,它不起作用
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" ....>
<context:annotation-config/>
<context:component-scan base-package="org.java.service.test"/>
<context:component-scan base-package="org.java.project.test"/>
.....
</beans>