简体   繁体   English

Spring Boot应用程序错误

[英]Spring Boot Application Error

I am doing my first project with Spring Boot. 我正在用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. 我收到下面的错误,但我没有头绪。我是否在下面显示的build.gradle中缺少任何依赖关系?我在运行Application.java文件时收到错误。

    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 //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 //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. 我知道,出于某种原因,您已经从spring-boot-starter-web排除了spring-boot-starter-tomcat并添加了org.apache.tomcat.embed:tomcat-embed-core作为依赖项。

According to the exception, you don't have a bean EmbeddedServletContainerFactory . 根据异常,您没有bean EmbeddedServletContainerFactory It seems to me, that this bean (exact TomcatEmbeddedServletContainerFactory ) is created in some configuration within spring-boot-starter-tomcat dependency. 在我看来,这个bean(精确的TomcatEmbeddedServletContainerFactory )是在spring-boot-starter-tomcat依赖关系中的某些配置中创建的。 So it seems, that you have to leave spring-boot-starter-tomcat or you will have to create this bean by your self. 如此看来,您必须离开spring-boot-starter-tomcat否则您将不得不自行创建此bean。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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