JAR 中的 Spring Boot + Elastic Beanstalk .ebextensions

2024-03-11

我有一个非常标准的 Spring Boot 应用程序(带有application.properties属性文件位于标准/src/main/resources文件夹),我将其作为“fat JAR”部署在 AWS Elastic Beanstalk 上。它工作得很好,但在服务器上上传图像存在问题。经过一番调查后,似乎 NGINX 配置需要调整(增加client_max_body_size到某物,以便它可以接受最多上传10MB),因此我添加了一个.ebextensions下的文件夹/src/main/resources具有以下内容的文件(取自这个答案 https://stackoverflow.com/questions/18908426/increasing-client-max-body-size-in-nginx-conf-on-aws-elastic-beanstalk): -

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>

提前致谢!


Update 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 可以解决该问题,但不幸的是,这不起作用。


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

感谢大家的帮助!


这是一个使其适用于 JAR 的 pom 片段:

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

它的工作方式与将 .ebextensions 移至 .war 文件中的根目录 http://codingexplained.com/coding/java/moving-ebextensions-root-war-file

实际上我将示例上传到了这里repo https://github.com/imTachu/moving-ebextensions-jar。只需做一个mvn package

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

JAR 中的 Spring Boot + Elastic Beanstalk .ebextensions 的相关文章

随机推荐

  • 用于生成自定义 IntelliJ toString 方法的 Velocity 模板

    鉴于班级 public class TestClass private static List
  • 显示文件的属性页并导航到选项卡

    在我的软件中 我需要显示文件的属性对话框并导航到该属性对话框中的特定选项卡 请告诉我如何使用 C 实现这一点 或者 是否可以用自定义属性对话框替换默认属性对话框 private bool properties string Filename
  • Javascript 从怪异模式切换到标准模式

    有没有办法使用 Javascript 将怪异模式的页面切换到标准模式 例如 假设我有以下包含 html 的页面 我已经尝试过以下方法 以及js js中的以下内容 document open document write document c
  • Laravel Blade 循环中未定义的变量 $loop

    根据最新的 laravel Blade 文档 https laravel com docs 5 3 blade https laravel com docs 5 3 blade请参阅 循环 我可以 使用循环变量来获取有关循环 的有价值的信息
  • 为什么 Homebrew 说“没有 git 存储库”?

    Running brew config gives HOMEBREW VERSION gt 1 0 0 no git repository 为什么会发生这种情况 我可以做什么来修复它 HOMEBREW VERSION gt 1 0 0 no
  • 在Golang中实现XSS防护

    我正在使用 Golang 构建 API Rest 我有一个包含很多字段 超过 100 个 的结构 因此我使用以下命令将来自客户端的值分配给该结构gorilla schema效果很好 现在 我想避免用户在任何字符串字段中插入 Javascri
  • android.intent.action.MY_PACKAGE_REPLACED 不工作

    我似乎无法理解这一点 也看不到它在 Logcat 中发送 从审查未收到 ACTION MY PACKAGE REPLACED https stackoverflow com questions 12666734 action my pack
  • Android浮动操作按钮隐藏在底部导航栏后面

    Android 编程新手 现在正在苦苦挣扎 我正在使用 android studio 的默认 导航抽屉活动 最重要的是 我添加了一个底部栏https github com roughike BottomBar 但是 添加后我的 FAB 已隐
  • 自动展开并给予 SearchView 焦点

    我正在开发一个应用程序 用户在其中按下 搜索 图标ActionBar and a SearchView在屏幕顶部可见 我的问题是SearchView既不处于焦点也不展开 因此用户必须按搜索按钮Searchview使其展开并带出键盘 这应该如
  • __cplusplus 指令在各种编译器中是如何定义的?

    我的编译器将其扩展为 199711L 这意味着什么 我读到 cplusplus gt 199711L 表示 C 11 这个宏可能有哪些扩展 它意味着什么 199711L 代表年 1997 月 11 即 1997 年 11 月 委员会批准该标
  • 我的 AWS 策略有什么问题?

    我正在尝试向程序化 IAM 用户授予对单个存储桶的访问权限 我设置了以下策略并将其附加到用户 Version 2012 10 17 Statement Effect Allow Action s3 ListBucket Resource a
  • Android - Google Maps api v2 - 禁用缩放控制

    如何禁用 Google 地图上的 放大 按钮 我尝试寻找类似的命令 map getUiSettings setZoomControlsEnabled true SOMETHING但什么都不存在 我想把创建自己的缩放按钮作为最后的手段 UPD
  • AngularJS - 从自定义过滤器中的控制器访问 $scope

    我有一个controller与各种 scopes 我需要在自定义过滤器中访问这些 scopes 之一 app controller AppController function scope scope var1 Some data1 sco
  • 为 numpy 安装 lapack

    运行 Ubuntu 11 10 python2 7 从源代码构建 numpy 并安装它 但是当我去安装它时 我得到 ImportError usr lib liblapack so 3gf undefined symbol ATL chem
  • 如何修复 Flash 安全错误 #2048

    我在 flash 2048 中遇到错误 我能找到的所有内容都表明这是一项安全预防措施 因为文件不在同一域中 我们有一个在 Rackspace 云服务器上运行的网站 现在正尝试使用云文件 CDN 来加速我们在网站上使用的产品轮换工具 您可以使
  • 如何验证用作反向代理的 Squid 是否正常工作?

    我们希望减少其中一台 Web 服务器的负载 并且正在使用配置为反向代理的鱿鱼运行一些测试 配置在下面的备注中 http port 80 accel defaultsite original server com cache peer ori
  • 用于查找名称以给定值开头的属性的 XPath

    使用这个 xml div a div div b div div c div div d div div f div div g div 我们只想找到 div a div div b div div c div 哪些节点具有属性 其中该属性
  • 为什么使用粘贴创建的文件名中有一个空格?

    我试图使用 R 编写一个文件 为了区分每个文件 我尝试每次在函数中添加不同的后缀 例如 counts lt function counts file name lt substr counts file 1 5 file lt paste
  • 在快速分配任务时

    将 Objective C 代码转换为 Swift 的正确方法是什么 while size inputdata readWithByteArray buf 1 我需要类似的 从这里 https stackoverflow com a 256
  • JAR 中的 Spring Boot + Elastic Beanstalk .ebextensions

    我有一个非常标准的 Spring Boot 应用程序 带有application properties属性文件位于标准 src main resources文件夹 我将其作为 fat JAR 部署在 AWS Elastic Beanstal