JAR中的Spring Boot + Elastic Beanstalk .ebextensions [英] Spring Boot + Elastic Beanstalk .ebextensions in JAR

查看:86
本文介绍了JAR中的Spring Boot + Elastic Beanstalk .ebextensions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常标准的Spring Boot应用程序(位于标准/src/main/resources 文件夹中的 application.properties 属性文件)AWS Elastic Beanstalk作为胖JAR".它工作得很好,但是在服务器上上传图像存在问题.经过一番调查后,似乎需要调整NGINX配置(将 client_max_body_size 增加到某种程度,以便它可以接受最大为 10MB 的上载),因此我添加了.ebextensions 文件夹位于/src/main/resources 下,其中包含以下内容(取自

I have a very standard Spring Boot application (with a application.properties properties file located in standard /src/main/resources folder) which I'm deploying on AWS Elastic Beanstalk as a "fat JAR". It works quite nicely but there is an issue with image uploading on the server. After some investigation it seems that the NGINX configuration needs to be tweaked (increase client_max_body_size to something so it can accept uploads up to 10MB) and therefore I have added an .ebextensions folder under /src/main/resources with a 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;

但是,当我在构建中运行 mvn 时,它没有在根文件夹中创建 .ebextensions ,我想知道什么是最佳解决方案.我的 pom.xml 文件非常小,当前包含以下内容:

However, when I run mvn on my build it doesn't create .ebextensions in the root folder and I'm wondering what is the best solution for this. My pom.xml file is 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>

提前谢谢!

@Lorena,当我插入< resources>... XML放入我的 pom.xml 中,然后启动服务器,它崩溃并显示以下内容:-

@Lorena when I insert <resources> ... XML into my pom.xml and then start the server it crashes out 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] o.s.boot.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] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

再次删除XML可以解决此问题,很不幸,这将无法正常工作.

Removing the XML again fixes the issue so unfortunately this won't work.

上一部分中描述的问题似乎是指向 .ebextentions 的新< resources> 覆盖了< resources> 块,定义在:-

The issues described in the previous section seemed to be that the new <resources> pointing to the .ebextentions was overridding 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>

要使所有功能正常工作,我将其复制并添加到末尾,如下所示:-

To get everything working I copied it across and appended 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>

感谢大家的帮助!

推荐答案

Lorena Salamanca提出的解决方案

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

我的解决方案适用于Spring 1.5.3.RELEASE

My solution works with Spring 1.5.3.RELEASE

在项目的根目录中添加.ebextensions,并在插件"部分的末尾添加以下代码段:

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>

此插件使用ant解压缩由春季启动生成的最终jar,在根目录中复制.ebextensions并再次使用相同的名称压缩(jar).经过测试并在生产中工作:)

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

这篇关于JAR中的Spring Boot + Elastic Beanstalk .ebextensions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆