我有一个使用Camel和Mybatis的Spring Boot应用程序。我在pom.xml中有以下mybatis依赖项:
的pom.xml
....
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-mybatis</artifactId>
<version>${camel.version}</version>
</dependency>
....
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.0.1</version>
</dependency>
....
我有以下路线:
MyRoute.java
@Component
public class MyRoute extends SpringRouteBuilder{
@Autowired
MQConnectionProperties mqConnectionProperties;
@Override
public void configure() throws Exception {
from(mqConnectionProperties.getResponseQueue())
.to("mybatis:selectLogByPrimaryKey?statementType=SelectOne")
.process(new TargetSystemProcessor())
.end()
}
}
和路线的测试:
MyRouteUnitTest.java
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {MyRouteTestConfiguration.class})
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
public class MyRouteUnitTest extends CamelTestSupport{
@Mock
MyBatisComponent mybatis;
@Autowired
MQConnectionProperties mqProps;
@Autowired
MyRouteBuilder route;
@Before
public void setup() throws Exception {
super.setUp();
context.addComponent("mybatis", mybatis);
}
@Test
public void test() throws Exception {
startCamelContext();
assertTrue(true);
stopCamelContext();
}
}
当我尝试在不将mybatis作为组件添加到上下文的情况下开始测试时,我收到此错误:
org.apache.camel.FailedToCreateRouteException: Failed to create route My_Route at: >>> To[mybatis:selectAuditLogByPrimaryKey?statementType=SelectOne] <<< in route: Route(My_Route)[[From[seda:inpu... because of Failed to resolve endpoint: mybatis://selectAuditLogByPrimaryKey?statementType=SelectOne due to: Cannot auto create component: mybatis
....
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: mybatis://selectAuditLogByPrimaryKey?statementType=SelectOne due to: Cannot auto create component: mybatis
....
Caused by: java.io.FileNotFoundException: Cannot find resource: SqlMapConfig.xml in classpath for URI: SqlMapConfig.xml
每当我将组件添加到上下文中所示的上下文时,我都会收到此错误:
org.apache.camel.FailedToCreateRouteException: Failed to create route My_Route at: >>> To[mybatis:selectAuditLogByPrimaryKey?statementType=SelectOne] <<< in route: Route(My_Route)[[From[seda:inpu... because of Failed to resolve endpoint: mybatis://selectAuditLogByPrimaryKey?statementType=SelectOne due to: No component found with scheme: mybatis
据我所知,我在pom文件中有正确的依赖关系将所有这些连接在一起,mybatis在源代码中工作正常。对于单元测试,我可以通过替换端点来解决它,但我不能为我的路由编写任何集成测试