Spring Boot on Elastic Beanstalk worker tier

2019-04-02 10:41发布

I am trying to deploy a spring boot app into one EB worker tier but seems that EB it is not ready to manage this kind of project.

Have I to mandatory generate a .war from my spring boot app?

Thanks!

1条回答
我只想做你的唯一
2楼-- · 2019-04-02 11:43

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);
        }
    
    }
    
查看更多
登录 后发表回答