我有两个包A和B. 包A有一个名为inject / spring / ClientConfiguration.java的配置类,其结构类似于
@Configuration
public class ClientConfiguration {
@Bean
public ABCWrapper aBCWrapper() {
return new ABCWrapperImpl();
}
@Bean
public X.ClientConfiguration clientConfig() {
return new ClientConfiguration()
}}
A.XML
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans classpath:org/springframework/beans/factory/xml/spring-beans-4.2.xsd
http://www.springframework.org/schema/util classpath:org/springframework/beans/factory/xml/spring-util-4.2.xsd
http://www.springframework.org/schema/context classpath:org/springframework/context/config/spring-context-4.2.xsd
">
<context:component-scan base-package="com.inject.spring"/>
现在在包B中我想使用bean aBCWrapper。 所以配置是
@Configuration
@ImportResource({ "classpath*:A.xml" })
public class BConfig {
@Autowired
private com.inject.spring.ClientConfiguration abcClientConfiguration;
@Bean
public ABCPublisher aBCPublisher() {
return new ABCPublisher(abcClientConfiguration.aBCWrapper());
}
}
但我得到例外 例外是
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.inject.spring.ClientConfiguration' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
好像我犯了一个愚蠢的错误 任何帮助将不胜感激。