我有以下课程:
package testpackage;
class InventoryService {
....
}
package testpackage;
class TransferService {
private String localManifestPath;
@Bean
public InventoryService inventoryService() {
return new InventoryService();
}
public void setLocalManifestPath(String localManifestPath) {
this.localManifestPath = localManifestPath;
}
}
package testpackage;
@Configuration
@Import ({TransferService.class})
class AppConfig {
@AutoWired
InventoryService inventoryService;
............
}
使用上面代码自动装配到inventoryService工作完美,但我也想调用TransferService中声明的setManifestPath。为此我创建了以下TransferService.xml:
<bean id="TransferService" class="testPackage.TransferService">
<property name="localManifestPath" value="/home/edword/abcd.xml" />
</bean>
并使用@ImportResource代替@Import,但它没有自动装配InventoryService并抛出
"Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: testpackage.inventoryService".
AppInfort with @ImportResource:
@Configuration
@ImportResource ({"classpath*:/WEB-INF/*/TransferService.xml"})
class AppConfig {
@AutoWired
InventoryService inventoryService;
............
}
我知道我在做一些愚蠢的事情,但却无法自己解决这个问题。请帮我找出来。