gpt4 book ai didi

spring-boot - JAR 中的 Spring Boot + Elastic Beanstalk .ebextensions

转载 作者:行者123 更新时间:2023-12-04 03:25:46 33 4
gpt4 key购买 nike

我有一个非常标准的 Spring Boot 应用程序(带有位于标准 application.properties 文件夹中的 /src/main/resources 属性文件),我将其作为“胖 JAR”部署在 AWS Elastic Beanstalk 上。它工作得很好,但在服务器上上传图像存在问题。经过一些调查,似乎需要调整 NGINX 配置(将 client_max_body_size 增加到某些内容,以便它可以接受上传到 10MB ),因此我添加了一个 .ebextensions文件夹下 /src/main/resources具有以下内容的文件(取自 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

上一节描述的问题似乎是新的 <resources>指向 .ebextentions覆盖了 <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>

感谢大家的帮助!

最佳答案

Lorena Salamanca 提出的解决方案 Spring Boot + Elastic Beanstalk .ebextensions in JAR对我不起作用...:\

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

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

<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解压spring boot生成的最终jar,复制根目录下的.ebextensions,再次用同名压缩(jar)。经过测试并在生产中工作:)

关于spring-boot - JAR 中的 Spring Boot + Elastic Beanstalk .ebextensions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42861558/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com