Spring Boot + Elastic Beanstalk.

I have a very standard Spring boot application (with the application.properties properties file located in the standard /src/main/resources folder) that I am deploying to AWS Elastic Beanstalk as a "thick JAR". It works pretty well, but there is a problem uploading images to the server. After some research, it seems that you need to configure the NGINX configuration (increase client_max_body_size by something so that it can accept orders up to 10MB ), and so I added the .ebextensions folder to /src/main/resources with the file with the following content (taken from this answer ): -

 files: "/etc/nginx/conf.d/proxy.conf": mode: "000755" owner: root group: root content: | client_max_body_size 20M; 

However, when I run mvn in my build, it does not create .ebextensions in the root folder, and I am wondering what is the best solution for this. My pom.xml file pom.xml pretty minimal and currently contains the following:

  ... <packaging>jar</packaging> .... <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>springloaded</artifactId> <version>1.2.6.RELEASE</version> </dependency> </dependencies> </plugin> 

Thanks in advance!


Update 1

@Lorena, when I insert <resources> ... XML into my pom.xml and then start the server, it crashes with the following: -

 2017-03-20 21:40:29.504 WARN 10784 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'emailApiSpringBootMail': Unsatisfied dependency expressed through field 'javaMailSender'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.mail.javamail.JavaMailSender' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 2017-03-20 21:40:29.507 INFO 10784 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat 2017-03-20 21:40:29.533 WARN 10784 --- [ main] osboot.SpringApplication : Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.annotation.ProxyCachingConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available) 2017-03-20 21:40:29.637 ERROR 10784 --- [ main] osbdLoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Field javaMailSender in com.myapp.server.api.impl.EmailApiSpringBootMail required a bean of type 'org.springframework.mail.javamail.JavaMailSender' that could not be found. - Bean method 'mailSender' not loaded because AnyNestedCondition 0 matched 2 did not; NestedCondition on MailSenderAutoConfiguration.MailSenderCondition.JndiNameProperty @ConditionalOnProperty (spring.mail.jndi-name) did not find property 'jndi-name'; NestedCondition on MailSenderAutoConfiguration.MailSenderCondition.HostProperty @ConditionalOnProperty (spring.mail.host) did not find property 'host' 

Removing XML resolves the issue again, so unfortunately this will not work.


Update 2

The problems described in the previous section seemed to have a new <resources> pointing to .ebextentions overlapping the <resources> block defined in: -

 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> 

For everything to work, I copied it and added it to the end as follows: -

  <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> 

Thank you all for your help!

+7
spring-boot elastic-beanstalk spring-boot-maven-plugin
source share
4 answers

The solution proposed by Loren Salamanca Spring Boot + Elastic Beanstalk.ebextensions in the JAR does not work for me ...: \

My solution works with Spring 1.5.3.RELEASE

Add .ebextensions to the project root directory and add this snippet to the end of 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 uses ant to unzip the final jar generated upon loading Spring, copy the .ebextensions in the root and zip (jar) again with the same name. Tested and working in production :)

0
source share

Here is a pom snippet that will make it work in the 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 works the same as moving .ebextensions for root in a .war file

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

+5
source share

The error message you get for the javaMailSender property was not found.

The resource path specified in your pom.xml overrides the default resource root path.

Therefore, JavaMailSender looks for jndi configuration or mail properties in this new resource path and cannot find it. Therefore, an 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
source share

This is actually a spring-boot jar problem. Since you are using version 1.2.6 spring-boot, which has some bugs, such as a problem with javamailsender. You need to update the spring boot version to over 1.3.0.release.

In this ticket number 3478, the problem with the mailing list is fixed for spring-boot. Thus, you can upgrade to the latest version or other versions over 1.3.0.

 <!-- 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 solves your problem.

0
source share

All Articles