Java Camel-restdsl(2.14.0)和stringbean

Java Camel-restdsl(2.14.0)和stringbean,java,spring,rest,apache-camel,Java,Spring,Rest,Apache Camel,我目前正在尝试Apache Camel 2.14.0版本的新版本。作为这篇文章的标题,我和一个字符串bean发生了冲突。让我们看看哪里出了问题 下面是一个有效的XML文件,简化为一个测试用例。它只定义一个字符串bean和一个包含rest端点和由rest端点调用的单个路由的Camel上下文 ${headers.words} 要加载和测试此驼峰上下文,我使用以下测试用例: import org.apache.camel.CamelContext; 导入org.springframework.co

我目前正在尝试Apache Camel 2.14.0版本的新版本。作为这篇文章的标题,我和一个字符串bean发生了冲突。让我们看看哪里出了问题

下面是一个有效的XML文件,简化为一个测试用例。它只定义一个字符串bean和一个包含rest端点和由rest端点调用的单个路由的Camel上下文


${headers.words}
要加载和测试此驼峰上下文,我使用以下测试用例:

import org.apache.camel.CamelContext;
导入org.springframework.context.support.FileSystemXmlApplicationContext;
公开课考试{
@org.junit.Test
public void testT()引发异常{
final FileSystemXmlApplicationContext bean=新的FileSystemXmlApplicationContext(“src/test/resources/camelContext.xml”);
最终CamelContext=bean.getBean(“CamelContext”,CamelContext.class);
context.start();
螺纹屈服强度();
睡眠(60万);
}
}
它当前导致以下错误:

org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: Failed to create route route2 at: >>> RestBinding <<< in route: Route(route2)[[From[rest:get:/rest-api/:/{words}/?produces=a... because of Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "file" ne contient pas ObjectFactory.class ou jaxb.index

org.apache.camel.runtimecameleexception:org.apache.camel.FailedToCreateRouteException:无法在:>>>RestBinding创建路由路由2我认为出现此问题的原因是,您为单元测试加载Spring和camel上下文的机制。考虑使用.< /P>
我用这个范例重写了这个测试,一切都很好

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/META-INF/spring/camel-context.xml" })
public class Test extends CamelTestSupport {
    @org.junit.Test
    public void testT() throws Exception {
        CloseableHttpClient httpClient = HttpClientBuilder.create().build();

        CloseableHttpResponse response = httpClient.execute(new HttpGet(
                        "http://localhost:5117/rest-api/hello"));
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals("\"hello\"", new BufferedReader(new InputStreamReader(response.getEntity()
                        .getContent(), StandardCharsets.UTF_8)).readLine());

    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder()
        {
            @Override
            public void configure() throws Exception {
                from("direct:words").transform().simple("${headers.words}");
            }
        };
    }
}

多亏了一位队友,我终于明白了错误

问题来自camel上下文中“java.lang.String”bean的定义。 放

<bean id="source" class="java.lang.String">
    <constructor-arg type="java.lang.String" value="file:/opt/a/directory/data/audio" />
</bean>
我对这种情况的理解是,如果定义了任何
java.lang.String
对象,则
JAXBContext
将其用作工厂标识符。他们可能会寻找一个通常总是为空的
@autowiredstring
属性。 将“源”bean替换为将我的sting封装在属性中的bean可以解决这个问题


意外的副作用被发现

谢谢你的工作!这并不能解决我的问题,但我学到了很多关于骆驼测试的使用。我还向Camel邮件列表提出了这个问题,他们认为问题来自jaxb版本冲突。
[main] JaxbDataFormat INFO Creating JAXBContext with contextPath: file:/opt/a/directory/data/audio and ApplicationContextClassLoader: sun.misc.Launcher$AppClassLoader@3485def8