2016-12-26 8 views
0

Я делаю свой первый проект с Spring Boot. Я получаю следующую ошибку, о которой я не знаю. Я пропустил какую-либо зависимость в файле 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 

Ниже представлены файлы конфигурации.

**//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= 

Что я упускаю в моей конфигурации?

+0

Вы не должны исключать 'spring-boot-starter-tomcat'. Удалите исключение и явное объявление 'tomcat-embed-core'. –

ответ

1

Понятно, что вы исключили spring-boot-starter-tomcat из spring-boot-starter-web и добавили org.apache.tomcat.embed:tomcat-embed-core в качестве зависимости.

В соответствии с исключением, у вас нет компонента EmbeddedServletContainerFactory. Мне кажется, что этот компонент (точный TomcatEmbeddedServletContainerFactory) создается в некоторой конфигурации в зависимости от spring-boot-starter-tomcat. Таким образом, кажется, что вам нужно оставить spring-boot-starter-tomcat, или вам нужно будет создать этот компонент самостоятельно.

+0

Спасибо за ваш ответ, Станислав. Но я все равно получаю ту же ошибку, хотя я прокомментирую исключение. – Chandan

+0

Не могли бы вы сказать, как вы его запускаете? Как автономная банка или как развертываемая война? – Stanislav

+0

Я запускаю его как отдельную банку. Я запускаю файл Application.java (показано выше) как приложение java. – Chandan

Смежные вопросы