如果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