Spring Boot on Elastic Beanstalk worker tier

☆樱花仙子☆ 提交于 2019-12-03 21:25:12

I have found the problem.

EB expects a .war file and Spring Boot app usually is launche by a embedded Tomcat or Jetty.

I have found the solution in this guide:

http://spring.io/guides/gs/convert-jar-to-war/

Summing up:

  1. Add tomcat dependency with provided scope in pom.xml

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    
  2. Create a class extending SpringBootServletInitializer and load the entrypoint within this class. This way, we are indicating to the servlet container how to launch the app.

    package com.proyecti.magma.conversionsworker.config.servlet;
    
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.boot.context.web.SpringBootServletInitializer;
    
    import com.proyecti.magma.conversionsworker.entrypoint.Application;
    
    public class ServletConfig extends SpringBootServletInitializer
    {
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(Application.class);
        }
    
    }
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!