Spring Boot + Elastic Beanstalk .ebextensions in JAR

前端 未结 5 1911
遇见更好的自我
遇见更好的自我 2021-02-13 15:44

I have a very standard Spring Boot application (with a application.properties properties file located in standard /src/main/resources folder) which I\'

相关标签:
5条回答
  • 2021-02-13 15:59

    Here is a pom snippet that'll make it work for a JAR:

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources/ebextensions</directory>
                <targetPath>.ebextensions</targetPath>
                <filtering>true</filtering>
            </resource>
            <!-- Followed is copied from `spring-boot-starter-parent.pom` -->
            <resource>
                <directory>${basedir}/src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/application*.yml</include>
                    <include>**/application*.properties</include>
                </includes>
            </resource>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
                <excludes>
                    <exclude>**/application*.yml</exclude>
                    <exclude>**/application*.properties</exclude>
                </excludes>
            </resource>
        </resources>
    </build>
    

    It just works in the same way as moving .ebextensions to root in .war file

    Actually I uploaded the sample to this repo. Just do a mvn package

    0 讨论(0)
  • 2021-02-13 15:59

    I believe in this case that standalone JAR is used, it's easier to go with Procfile-based configuration and then bundle your JAR and .ebextensions into a zip file.

    First create a file, called Procfile in the root of the project with following content:

    web: java -jar sample_app-1.0.0.jar
    

    Then create a zip file, containing the JAR and Procfile file and .ebextensions directory:

    sample_app.zip
    |
    |_.ebextensions
    |   |_ nginx
    |      |_ conf.d
    |         |_ proxy.conf
    |
    |_ sample_app-1.0.0.jar
    |_ Procfile
    
    0 讨论(0)
  • 2021-02-13 16:16

    The error message that you get is for javaMailSender property not found.

    The resources path mentioned in your pom.xml overrides the default resources root path.

    Hence JavaMailSender is looking for the jndi configuration or the mail properties under this new resources path and its not able to find it.. Hence the error.

    spring.mail.jndi-name=mail/testmail
    

    OR

    spring.mail.host=testserver.com
    spring.mail.port=25
    spring.mail.username=test
    spring.mail.password=test123
    spring.mail.protocol=smtp
    spring.mail.defaultEncoding=UTF-8
    spring.mail.properties.mail.smtp.auth=true
    spring.mail.properties.mail.smtp.auth.mechanisms=NTLM
    spring.mail.properties.mail.smtp.auth.ntlm.domain=DOMAIN
    spring.mail.properties.mail.debug=true
    
    0 讨论(0)
  • 2021-02-13 16:19

    The solution proposed by Lorena Salamanca Spring Boot + Elastic Beanstalk .ebextensions in JAR not works for me... :\

    My solution works with Spring 1.5.3.RELEASE

    Add .ebextensions in the root of your project and add this snippet at the end in the plugins section:

    <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <id>prepare</id>
                        <phase>package</phase>
                        <configuration>
                            <tasks>
                                <unzip src="${project.build.directory}/${project.build.finalName}.jar" dest="${project.build.directory}/${project.build.finalName}" />
                                <copy todir="${project.build.directory}/${project.build.finalName}/" overwrite="false">
                                    <fileset dir="./" includes=".ebextensions/**"/>
                                </copy>
                                <!-- <jar jarfile="${project.build.directory}/${project.build.finalName}.jar" basedir="${project.build.directory}/${project.build.finalName}"/>-->
                                <zip compress="false" destfile="${project.build.directory}/${project.build.finalName}.jar" basedir="${project.build.directory}/${project.build.finalName}"/>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
    

    This plugin use ant to unzip the final jar generated by spring boot, copy the .ebextensions in the root and zip (jar) again with the same name. Tested and working in production :)

    0 讨论(0)
  • 2021-02-13 16:20

    Actually it is spring-boot jar related issue. As you are using 1.2.6 version of spring-boot, which has some bugs like javamailsender issue. You need to upgrade your spring boot version more than 1.3.0.release.

    In this ticket#3478, the mailsender issue is fixed for spring-boot. So you can upgrade to latest version or others more than 1.3.0 release.

    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <version>1.3.5.RELEASE</version>
    </dependency>
    

    Hope this will solve your issue.

    0 讨论(0)
提交回复
热议问题