简体   繁体   中英

Spring Boot Application Error

I am doing my first project with Spring Boot. I am getting the below error which I do not have clue about.Am I missing any dependency in build.gradle shown below?I am getting the error when I am running the Application.java file.

    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.
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
        at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
        at com.bale.route.Application.main(Application.java:12) [classes/:na]
    Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:185) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
        ... 8 common frames omitted

Below are my configuration files.

    **//Application.java**

        package com.test.route;

        import org.springframework.boot.SpringApplication;

        import org.springframework.boot.autoconfigure.SpringBootApplication;
        import org.springframework.boot.builder.SpringApplicationBuilder;
        import org.springframework.boot.context.web.SpringBootServletInitializer;

        @SpringBootApplication
        public class Application extends SpringBootServletInitializer{

            public static void main(String[] args) {
                SpringApplication.run(Application.class, args);
            }
            protected SpringApplicationBuilder configure(

                    SpringApplicationBuilder application) {

                return application.sources

    (Application.class);

        }
    }

//build.gradle

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE")
        }
    }
    apply plugin: 'war'
    apply plugin: 'java'
    apply plugin: 'spring-boot'



    repositories {
        mavenCentral()
    }

    sourceCompatibility = 1.7
    targetCompatibility = 1.7

    dependencies {
         compile("org.springframework.boot:spring-boot-starter-web")
         {

            exclude module: 'spring-boot-starter-tomcat'


        }



        // tag::actuator[]
        //compile("org.springframework.boot:spring-boot-starter-actuator")
        compile("org.apache.tomcat.embed:tomcat-embed-core")
        // end::actuator[]
        // tag::tests[]
        //testCompile("org.springframework.boot:spring-boot-starter-test")
        // end::tests[]
    }

    task wrapper(type: Wrapper) {
        gradleVersion = '2.3'
    }

//application.properties

    server.servlet-path= /app
    logging.level.org.springframework=DEBUG
    spring.mvc.view.prefix=/WEB-INF/jsp/
    spring.mvc.view.suffix=.jsp
    cookie.path=
    cookie.domain=

What am I missing in my configuration?

I see, you've excluded spring-boot-starter-tomcat from spring-boot-starter-web for some reason and added org.apache.tomcat.embed:tomcat-embed-core as dependency.

According to the exception, you don't have a bean EmbeddedServletContainerFactory . It seems to me, that this bean (exact TomcatEmbeddedServletContainerFactory ) is created in some configuration within spring-boot-starter-tomcat dependency. So it seems, that you have to leave spring-boot-starter-tomcat or you will have to create this bean by your self.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM