Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么camel上下文无法解析Spring boot胖jar中的路由?_Java_Jar_Spring Boot_Apache Camel_Executable Jar - Fatal编程技术网

Java 为什么camel上下文无法解析Spring boot胖jar中的路由?

Java 为什么camel上下文无法解析Spring boot胖jar中的路由?,java,jar,spring-boot,apache-camel,executable-jar,Java,Jar,Spring Boot,Apache Camel,Executable Jar,以下是spring boot fat jar camel项目的结构: /opt/java/spring/boot/fat/jar/camel/project/ ├─ menus.json ├─ proxy.json └─ chorke─boot─launch-1.0.00-SNAPSHOT.jar! ├─ META-INF/ ├─ org/springframework/boot/loader/ ├─ com/chorke/

以下是spring boot fat jar camel项目的结构:

/opt/java/spring/boot/fat/jar/camel/project/
    ├─ menus.json
    ├─ proxy.json
    └─ chorke─boot─launch-1.0.00-SNAPSHOT.jar!
        ├─ META-INF/
        ├─ org/springframework/boot/loader/
        ├─ com/chorke/boot/launch/
        ├─ application.properties
        ├─ application.yml
        ├─ log4j.xml
        └─ lib/
            ├─ annotations-2.0.0.jar
            ├─ camel-core-2.15.2.jar
            ├─ camel-hl7-2.15.2.jar
            ├─ camel-mina2-2.15.2.jar
            ├─ camel-spring-2.15.2.jar
            ├─ camel-spring-javaconfig-2.15.2.jar
            ├─ chorke-boot-jproxy-1.0.00-SNAPSHOT.jar!
            │   ├─ META-INF/
            │   │   ├─ camel/
            │   │   │   └─ applicationContext-camel.xml
            │   │   └─ property/
            │   └─ com/chorke/boot/jproxy/
            │
            ├─ chorke-boot-webapp-1.0.00-SNAPSHOT.jar
            ├─ chorke-comn-spring-1.0.00-SNAPSHOT.jar
            ├─ commons-collections-3.2.1.jar
            ├─ spring-context-4.1.6.RELEASE.jar
            ├─ spring-core-4.1.6.RELEASE.jar
            ├─ spring-webmvc-4.1.6.RELEASE.jar
            ├─ ..more..more..and..more..jar
            ├─ tomcat-embed-core-8.0.23.jar
            └─ zuul-core-1.0.28.jar
路线如下:

package com.chorke.boot.jproxy.route;

import org.apache.camel.builder.RouteBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ProxyRoute extends RouteBuilder {

    private static final Logger log =LoggerFactory.getLogger(ProxyRoute.class);

    @Override
    public void configure() throws Exception {

        from("mina2:tcp://0.0.0.0:22210?codec=#hl7codec&sync=true").process(new Processor() {
            public void process(Exchange exchange) throws Exception {
                String body = exchange.getIn().getBody(String.class);
                log.info("Port-Forwarded body:\n {}", body);
            }
        }).to("mina2:tcp://192.168.0.10:22210?codec=#hl7codec&sync=true").end();

        from("mina2:tcp://0.0.0.0:22211?codec=#hl7codec&sync=true").process(new Processor() {
            public void process(Exchange exchange) throws Exception {
                String body = exchange.getIn().getBody(String.class);
                log.info("Port-Forwarded body:\n {}", body);
            }
        }).to("mina2:tcp://192.168.0.11:22211?codec=#hl7codec&sync=true").end();

    }
}
以下是驼峰上下文配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:camel="http://camel.apache.org/schema/spring"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

    <bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
        <property name="locations">
            <list>
                <value>classpath:/META-INF/property/mina2.properties</value>
            </list>
        </property>
    </bean>

    <camel:camelContext id="camelContext">
        <camel:packageScan>
            <camel:package>com.chorke.boot</camel:package>
            <camel:includes>**.route.*</camel:includes>
        </camel:packageScan>
    </camel:camelContext>

</beans>

类路径:/META-INF/property/mina2.properties
com.chorke.boot
**.路线*
在制作脂肪罐之前,这些骆驼路线可以很好地工作。当Spring bootmakefat jar归档时,camel包扫描程序无法动态解析这些路由。是spring boot的缺陷还是驼峰软件包扫描器关于胖jar文件的限制


对于这种情况,您有什么解决方案吗

spring fatjar使用不同的类加载来使用它,因此不受支持/工作

您可以使用spring componentScan而不是packageScan,并使用spring
@Component
注释声明路由生成器类

请参阅下面的“使用上下文扫描”部分: