0
我有一個Spring Boot + Apache Camel項目,效果出色。我剛剛添加了一個新的bean,但我希望它的實現是特定於配置文件的。我創建了春天測試,以驗證它,它工作正常,但是當我跑我得到以下堆棧跟蹤服務器:@Profile駱駝的春季註釋
Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: MyFancyBean at org.apache.camel.component.bean.RegistryBean.getBean(RegistryBean.java:94) at org.apache.camel.model.language.MethodCallExpression.createExpression(MethodCallExpression.java:196) at org.apache.camel.model.language.MethodCallExpression.createPredicate(MethodCallExpression.java:210) at org.apache.camel.model.language.ExpressionDefinition.createPredicate(ExpressionDefinition.java:148) at org.apache.camel.model.ValidateDefinition.createProcessor(ValidateDefinition.java:63) at org.apache.camel.model.ValidateDefinition.createProcessor(ValidateDefinition.java:35) at org.apache.camel.model.ProcessorDefinition.makeProcessorImpl(ProcessorDefinition.java:545) at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:506) at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:222) at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1068)
我有一個接口和兩個實現:
public interface MyFancyBean { ... }
public class FooFancyBean implements MyFancyBean { ... }
public class NonFooFancyBean implements MyFancyBean { ... }
根據在配置文件中,正確的bean被實例化了:
@Configuration
public class AppConfig {
@Bean
@Profile("foo")
MyFancyBean fooBean() {
return new FooFancyBean();
}
@Bean
@Profile("!foo")
MyFancyBean nonFooBean() {
return new NonFooFancyBean();
}
}
我已經驗證了這個方法有幾種方法。首先,一對夫婦測試:
@ActiveProfiles("anything-but-foo")
@RunWith(SpringJUnit4ClassRunner.class)
@ComponentScan(basePackages = {"com.example", "com.jtv.spring.boot"})
@EnableAutoConfiguration
@Component
public class NonFooBean_SpringTest {
@Autowired
private MyFancyBean bean;
@Test
// ... here "bean" is instantiated as "NonFooFancyBean"
所以測試的工作。
此外,當我啓動我的應用程序時,根據配置文件調用上面的@Configuration類中正確的bean。
但駱駝仍然生氣,並在啓動時說「NoSuchBeanException」。
FWIW,這裏是我如何引用豆:
@Component
public class MyCamelRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
// [...]
from("direct:processStuff").
validate().method("MyFancyBean").
process("MyProcessor");
}
}
如何讓駱駝兌現這個配置?
(不允許回答我的問題,兩天......那是什麼呢?) – inanutshellus
呵呵.. 橡皮鴨。 – Pytry