基本上我有兩個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的新手,這是我們生產代碼的一部分。我不知道如何提取出來。 –