基本上我有两个bean实现相同的接口。一个是配置文件“默认”,另一个是“整合”。创建bean时出错,因为它是一个接口?
public interface SomeClientIfc { ... }
@Component
@Profile(value={"functional", "integration"})
public class StubSomeNIOClient implements SomeClientIfc {...}
public class SomeNIOClient implements SomeClientIfc {...}
@Configuration
@Profile("default")
public class SomeClientConfiguration {
@Bean
public SomeClientIfc someClient() {
...
SomeNIOClient someClient = new SomeNIOClient(numberOfParititions, controllerHosts, maxBufferReadSize,
connectionPoolSize);
return someClient;
}
}
在督促代码是
@Autowired
public SomeUserResolver(..., SomeClientIfc someClient) {...}
到目前为止好,我也看到了存根豆被称为在集成测试。然后,我想在我的集成测试注入一些测试数据存根豆:
@ContextConfiguration(locations = {"/configProperties.xml", "/integrationTests.xml", ...})
@ActiveProfiles("integration")
public class SomeTestBase {
@Autowired
private SomeClientIfc someClientIfc;
}
但是,在运行测试时,我得到错误信息
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'someClientIfc': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.audiencescience.some.client.SomeClientIfc]: Specified class is an interface
我甚至试图与StubSomeNIOClient更换SomeClientIfc但即使StubSomeNIOClient不是接口,仍然会得到相同的消息。
代码,我不能重现此。请提供[MCVE]。 –
对不起,我是Spring的新手,这是我们生产代码的一部分。我不知道如何提取出来。 –