在启动春季引导+ Apache的骆驼HTTP组件崩溃:缺少EmbeddedServletContainerFactory豆 [英] Spring Boot + Apache Camel HTTP component crashes at start: missing EmbeddedServletContainerFactory bean

查看:2304
本文介绍了在启动春季引导+ Apache的骆驼HTTP组件崩溃:缺少EmbeddedServletContainerFactory豆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是把春天引导兜风,并决定在骆驼混合,因为我需要一些神秘的头在其他地区的客户我工作的工作。设置应用程序是罚款,直到我添加了骆驼HTTP组件到我的POM,然后我得到这个初始化上:

 异常线程mainorg.springframework.context.ApplicationContextException:无法启动嵌入容器;嵌套的例外是org.springframework.context.ApplicationContextException:无法启动EmbeddedWebApplicationContext由于缺少EmbeddedServletContainerFactory豆。

我一直还没有得到从哪里开始寻找问题的第一个想法。我收集春天启动将查找类路径,并尝试丝东西了,所以那里的,从上或排序?

的东西正在采取行动阻止骆驼包的方式

的完整的日志启动这个吉斯特

下面是我的主要aplication code:

  @ComponentScan
@EnableAutoConfiguration
公共类应用{    私有静态ApplicationContext中CTX;    公共静态无效的主要(字串[] args)抛出异常{
        CTX = SpringApplication.run(Application.class,参数);        //对失控弹簧4文档
        的System.out.println(让我们检查由Spring提供引导豆:);
        的String [] = beanNames ctx.getBeanDefinitionNames();
        Arrays.sort(beanNames);
        对于(字符串beanName:beanNames){
            的System.out.println(beanName);
        }
        // ---        // FIXME:丑陋的黑客让一些POC woek,同时等待合适的骆驼/ Spring4单元测试修复。
        应用程序=新的应用程序();
        app.executeTests();    }    / **
     *开发QOL - 单元测试被打破,现在,请参阅:
     * https://issues.apache.org/jira/browse/CAMEL-7074
     * LT; P />
     *等待修复(太外行签并建立自己的骆驼)
     * /
    私人无效executeTests()抛出异常{
        testAuth();
    }    @豆
    DefaultCamelContext camelCtx()抛出异常{
        DefaultCamelContext骆驼=新DefaultCamelContext();
        camel.addRoutes(cryptsyRouteBuilder());
        camel.start();
        返回骆驼;
    }    @豆
    公共CryptsyRouteBuilder cryptsyRouteBuilder()抛出异常{
        CryptsyRouteBuilder豆=新CryptsyRouteBuilder();
        bean.setCryptsy(cryptsy());
        返回豆;
    }    @豆
    公共Cryptsy cryptsy()抛出IOException
        返回新Cryptsy();
    }    保护无效testAuth()抛出异常{
        ProducerTemplate制片= camelCtx()createProducerTemplate()。
        producer.requestBody(直接:启动,为什么,喂那里,为String.class);
    }
}

和我的POM依赖关系:

 <母体GT;
        <&的groupId GT; org.springframework.boot< /的groupId>
        <&的artifactId GT;春开机起动亲和LT; / artifactId的>
        <&版GT; 0.5.0.BUILD-快照和LT; /版本>
    < /母体GT;    <依赖和GT;
        <! - 春天 - >
        <&依赖性GT;
            <&的groupId GT; org.springframework.boot< /的groupId>
            <&的artifactId GT;春开机起动< / artifactId的>
        < /依赖性>        <&依赖性GT;
            <&的groupId GT; org.springframework.boot< /的groupId>
            <&的artifactId GT;弹簧引导启动测试< / artifactId的>
            <&范围GT;试验< /&范围GT;
        < /依赖性>        <! - <&依赖性GT; - >
            &所述;! - &所述;的groupId> org.springframework.boot&下; /的groupId&GT - →;
            &所述;! - &所述; artifactId的>弹簧引导起动致动器与所述; / artifactId的&GT - →;
        <! - < /依赖性> - >        <&依赖性GT;
            <&的groupId GT; org.springframework< /的groupId>
            <&的artifactId GT;春的Web< / artifactId的>
        < /依赖性>        <! - 骆驼 - >
        <&依赖性GT;
            <&的groupId GT; org.apache.camel< /的groupId>
            <&的artifactId GT;骆驼核心和LT; / artifactId的>
            <&版GT; $ {camel.version}< /版本>
        < /依赖性>        <&依赖性GT;
            <&的groupId GT; org.apache.camel< /的groupId>
            <&的artifactId GT;骆驼弹簧< / artifactId的>
            <&版GT; $ {camel.version}< /版本>
        < /依赖性>        <&依赖性GT;
            <&的groupId GT; org.apache.camel< /的groupId>
            <&的artifactId GT;骆驼弹簧javaconfig< / artifactId的>
            <&版GT; $ {camel.version}< /版本>
        < /依赖性>        <&依赖性GT;
            <&的groupId GT; org.apache.camel< /的groupId>
            <&的artifactId GT;骆驼石英< / artifactId的>
            <&版GT; $ {camel.version}< /版本>
        < /依赖性>        <&依赖性GT;
            <&的groupId GT; org.apache.camel< /的groupId>
            <&的artifactId GT;骆驼测试弹簧< / artifactId的>
            <&版GT; $ {camel.version}< /版本>
        < /依赖性>        <&依赖性GT;
            <&的groupId GT; org.apache.camel< /的groupId>
            <&的artifactId GT;骆驼HTTP< / artifactId的>
            <&版GT; $ {camel.version}< /版本>
        < /依赖性>        <! - 什锦 - >
        <&依赖性GT;
            <&的groupId GT;&LT com.fasterxml.jackson.core; /的groupId>
            <&的artifactId GT;杰克逊和数据绑定LT; / artifactId的>
            <&版GT; 2.3.0< /版本>
        < /依赖性>        <&依赖性GT;
            <&的groupId GT; commons- codeC< /的groupId>
            <&的artifactId GT; commons- codeC< / artifactId的>
            <&版GT; 1.9 LT; /版本>
        < /依赖性>    < /依赖和GT;
    <性状>
        <启动级> xxx.xxxx.Application< /启动级>
        < camel.version> 2.12.2< /camel.version>
    < /性状>


解决方案

唯一的例外是告诉你,春天启动认为你想建立一个Web服务器,但是找不到类路径的正确依赖关系。对于你的情况最明显的原因是,你添加的HTTP依赖性包含的Servlet API的。我不明白为什么你需要一个客户端应用程序,但只有你会知道你是否需要与否。也许你可以排除了吗?

如果你需要Servlet的依赖关系,只是想明确地告诉你没有创建一个Web应用程序,您可以设置该属性启动 spring.main.web_environment = FALSE ,或者直接使用 SpringApplication (或 SpringApplicationBuilder )API设置相同的标志。见<一href=\"https://github.com/spring-projects/spring-boot/blob/master/docs/howto.md#create-a-non-web-application\"相对=nofollow>这里的背景信息的文档。

Just taking Spring-Boot for a spin and decided to mix in Camel because I need some arcane Headers work in the rest client I am working on. Setting up the application was fine until I added the camel-http component to my POM, then I get this on init:

Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

I've havent got the first idea of where to start to look for the problem. I gather Spring Boot will look up the classpath and try to wire stuff up, so is there a way for the to block the Camel packages from being acted on or something of the sort?

Complete log of the start up in this Gist

Here's my main aplication code:

@ComponentScan
@EnableAutoConfiguration
public class Application {

    private static ApplicationContext ctx;

    public static void main(String[] args) throws Exception {
        ctx = SpringApplication.run(Application.class, args);

        //Right outta Spring 4 docs
        System.out.println("Let's inspect the beans provided by Spring Boot:");
        String[] beanNames = ctx.getBeanDefinitionNames();
        Arrays.sort(beanNames);
        for (String beanName : beanNames) {
            System.out.println(beanName);
        }
        //---

        // FIXME: ugly hack to allow some POC woek while wait for proper Camel/Spring4 unit tests fix.
        Application app = new Application();
        app.executeTests();

    }

    /**
     * Dev QOL - unit tests are broken for now, see:
     * https://issues.apache.org/jira/browse/CAMEL-7074
     * <p/>
     * Waiting for fix (Too lay to checkout and build my own Camel)
     */
    private void executeTests() throws Exception {
        testAuth();
    }

    @Bean
    DefaultCamelContext camelCtx() throws Exception {
        DefaultCamelContext camel = new DefaultCamelContext();
        camel.addRoutes(cryptsyRouteBuilder());
        camel.start();
        return camel;
    }

    @Bean
    public CryptsyRouteBuilder cryptsyRouteBuilder() throws Exception{
        CryptsyRouteBuilder bean = new CryptsyRouteBuilder();
        bean.setCryptsy(cryptsy());
        return bean;
    }

    @Bean
    public Cryptsy cryptsy() throws IOException {
        return new Cryptsy();
    }

    protected void testAuth() throws Exception {
        ProducerTemplate producer = camelCtx().createProducerTemplate();
        producer.requestBody("direct:start", "Why, hullo there", String.class);
    }


}

And my POM dependencies:

   <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>0.5.0.BUILD-SNAPSHOT</version>
    </parent>

    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!--<dependency>-->
            <!--<groupId>org.springframework.boot</groupId>-->
            <!--<artifactId>spring-boot-starter-actuator</artifactId>-->
        <!--</dependency>-->

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>

        <!-- Camel -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>${camel.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring</artifactId>
            <version>${camel.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring-javaconfig</artifactId>
            <version>${camel.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-quartz</artifactId>
            <version>${camel.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-test-spring</artifactId>
            <version>${camel.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-http</artifactId>
            <version>${camel.version}</version>
        </dependency>

        <!-- Assorted -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.3.0</version>
        </dependency>

        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.9</version>
        </dependency>

    </dependencies>


    <properties>
        <start-class>xxx.xxxx.Application</start-class>
        <camel.version>2.12.2</camel.version>
    </properties>

解决方案

The exception is telling you that Spring Boot thinks you want to build a web server, but can't find the right dependencies on the classpath. The most obvious reason for that in your case would be that the HTTP dependencies you added included Servlet APIs. I see no reason why you need that for a client app, but only you would know whether you need it or not. Maybe you can exclude it?

If you do need the Servlet dependencies and just want to explicitly tell Boot that you aren't creating a web application you can set the property spring.main.web_environment=false, or use the SpringApplication (or SpringApplicationBuilder) API directly to set the same flag. See docs here for background information.

这篇关于在启动春季引导+ Apache的骆驼HTTP组件崩溃:缺少EmbeddedServletContainerFactory豆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆