gpt4 book ai didi

java - 如何将带有自定义 .properties 文件的 Spring Boot 应用程序部署到 AWS ElasticBeanstalk?

转载 作者:搜寻专家 更新时间:2023-11-01 03:30:49 26 4
gpt4 key购买 nike

我有一个使用不同环境属性的 Spring Boot 应用程序。根据选定的环境,它从位于 ./resourcesapplication-{dev/stag/prod}.properties 文件中获取所需的数据。当通过 InteliJ 在本地运行以及运行创建的 .jar 文件(使用带有 bootJar 的 Gradle 创建)时,一切正常。

我已经创建了一个 AWS ElasticBeanstalk 应用程序。在该应用程序中,我创建了一个 Java 环境并在那里部署了 .jar 文件。部署时,我在日志中看到以下错误:

  .   ____          _            __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.5.RELEASE)

2019-07-12 07:47:26.773 INFO 3315 --- [ main] nl.abc.sgapi.SgApiApplication : Starting SgApiApplication on ip-172-31-29-160 with PID 3315 (/var/app/current/application.jar started by webapp in /var/app/current)
2019-07-12 07:47:26.795 INFO 3315 --- [ main] nl.abc.sgapi.SgApiApplication : The following profiles are active: dev
2019-07-12 07:47:31.392 INFO 3315 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-07-12 07:47:31.713 INFO 3315 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 301ms. Found 6 repository interfaces.
2019-07-12 07:47:33.384 INFO 3315 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$59ac5acc] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-07-12 07:47:33.518 INFO 3315 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.throttling-com.weddini.throttling.autoconfigure.ThrottlingProperties' of type [com.weddini.throttling.autoconfigure.ThrottlingProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-07-12 07:47:33.530 INFO 3315 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'com.weddini.throttling.autoconfigure.ThrottlingAutoConfiguration' of type [com.weddini.throttling.autoconfigure.ThrottlingAutoConfiguration$$EnhancerBySpringCGLIB$$16a02498] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-07-12 07:47:33.543 INFO 3315 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'throttlingEvaluator' of type [com.weddini.throttling.service.ThrottlingEvaluatorImpl] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-07-12 07:47:33.569 INFO 3315 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'throttlingService' of type [com.weddini.throttling.service.ThrottlingServiceImpl] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-07-12 07:47:33.593 INFO 3315 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.hateoas.config.HateoasConfiguration' of type [org.springframework.hateoas.config.HateoasConfiguration$$EnhancerBySpringCGLIB$$d92ca7fe] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-07-12 07:47:35.100 INFO 3315 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 5000 (http)
2019-07-12 07:47:35.224 INFO 3315 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-07-12 07:47:35.225 INFO 3315 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.19]
2019-07-12 07:47:35.515 INFO 3315 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-07-12 07:47:35.516 INFO 3315 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 8443 ms
2019-07-12 07:47:39.298 INFO 3315 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-07-12 07:47:50.424 ERROR 3315 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.

org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:292) ~[postgresql-42.2.5.jar!/:42.2.5]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) ~[postgresql-42.2.5.jar!/:42.2.5]
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195) ~[postgresql-42.2.5.jar!/:42.2.5]
at org.postgresql.Driver.makeConnection(Driver.java:454) ~[postgresql-42.2.5.jar!/:42.2.5]
at org.postgresql.Driver.connect(Driver.java:256) ~[postgresql-42.2.5.jar!/:42.2.5]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136) ~[HikariCP-3.2.0.jar!/:na]

似乎 AWS ElasticBeanstalk 无法读取 application-dev.properties 文件中的值。

这是我的 application-dev.properties 文件的样子:

spring.datasource.hikari.connectionTimeout=20000
spring.datasource.hikari.maximumPoolSize=5
spring.datasource.url=jdbc:postgresql://{REDACTED}
spring.datasource.username={REDACTED}
spring.datasource.password={REDACTED}
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
app.message=Hello from dev properties

我已经尝试将环境特定属性移动到主 application.properties 文件并创建一个 .jar。但这也不起作用。

接下来我可以尝试什么?

最佳答案

您的 Spring Boot 应用程序似乎无法连接到 PostgreSQL 数据库。我建议你 dubbel 检查用户名和密码。如果您启用了防火墙,请检查必须连接到数据库的服务器是否在白名单中。

关于java - 如何将带有自定义 .properties 文件的 Spring Boot 应用程序部署到 AWS ElasticBeanstalk?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57003039/

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