【发布时间】:2017-08-09 05:59:14
【问题描述】:
我有一个非常标准的 Spring Boot 应用程序(带有一个位于标准 /src/main/resources 文件夹中的 application.properties 属性文件),我将其作为“胖 JAR”部署在 AWS Elastic Beanstalk 上。它工作得很好,但是在服务器上上传图像存在问题。经过一番调查,似乎需要调整 NGINX 配置(将client_max_body_size 增加到某个值,以便它可以接受高达10MB 的上传),因此我在/src/main/resources 下添加了一个.ebextensions 文件夹,其中包含一个文件以下内容(取自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 文件非常小,目前包含以下内容:
...
<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>
提前致谢!
更新 1
@Lorena 当我将<resources> ... XML 插入到我的pom.xml 中然后启动服务器时,它会崩溃并显示以下内容:-
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 解决了这个问题,所以很遗憾这不起作用。
更新 2
上一节中描述的问题似乎是指向.ebextentions 的新<resources> 覆盖了以下定义的<resources> 块:-
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
为了让一切正常工作,我将其复制并附加到末尾,如下所示:-
<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>
感谢大家的帮助!
【问题讨论】:
-
您是否尝试在 pom 中告诉它应该将文件夹移动到根目录? Like this
-
那是作为 WAR 部署的 - 我正在部署为胖 JAR,因此很容易从命令行运行。
-
您可以使用 Build Helper Maven 插件,而不是复制
<resources>部分:stackoverflow.com/a/64911750/283136
标签: spring-boot amazon-elastic-beanstalk spring-boot-maven-plugin