如果spring bean在jar文件中使用了注释,我怎么能在我的类中加载我的bean实例?从Jar中加载带注释的弹簧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;
}
在弹簧的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>
你在使用什么服务器容器,如何打包jar,你在哪里放置jar? –
你可以提供异常跟踪吗? – sgpalit
你能解决这个问题吗?我面临着类似的问题 – CuriousCoder