我试图运行我的Spring + MySQL应用程序的弹性豆柄。不管我怎么尝试,我都会得到502 Bad Gateway
。我尝试过将我的Spring端口更改为5000,但它似乎毫无帮助。
我已经尝试过在server.port=5000
中添加application.properties
。我也尝试过添加server.port=${PORT}
。
每次我eb deploy
日志显示如下:
03:08:21.096 [main] INFO t.t.TrackMyWaterChangeApplication - Starting TrackMyWaterChangeApplication v0.0.1-SNAPSHOT on ip-172-31-41-134 with PID 6105 (/var/app/current/application.jar started by webapp in /var/app/current)
03:08:21.098 [main] INFO t.t.TrackMyWaterChangeApplication - No active profile set, falling back to default profiles: default
03:08:54.024 [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Bootstrapping Spring Data repositories in DEFAULT mode.
03:08:56.577 [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 2305ms. Found 4 repository interfaces.
03:09:20.544 [main] INFO o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$c95c6ba6] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
03:09:35.665 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port(s): 5000 (http)
03:09:36.122 [main] INFO o.a.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-5000"]
03:09:36.533 [main] INFO o.a.catalina.core.StandardService - Starting service [Tomcat]
03:09:36.533 [main] INFO o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.21]
03:09:39.127 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
03:09:39.128 [main] INFO o.s.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 75522 ms
03:09:59.224 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
03:10:08.318 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
03:10:08.880 [main] INFO org.hibernate.Version - HHH000412: Hibernate Core {5.3.10.Final}
03:10:08.889 [main] INFO org.hibernate.cfg.Environment - HHH000205: Loaded properties from resource hibernate.properties: {hibernate.dialect=org.hibernate.dialect.MySQLDialect, hibernate.bytecode.use_reflection_optimizer=false}
03:10:09.268 [main] INFO o.h.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
03:10:10.046 [main] INFO org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
03:10:12.003 [main] INFO o.s.o.j.LocalContainerEntityManagerFactoryBean - Initialized JPA EntityManagerFactory for persistence unit 'default'
03:10:13.291 [main] INFO o.h.h.i.QueryTranslatorFactoryInitiator - HHH000397: Using ASTQueryTranslatorFactory
03:10:14.039 [main] INFO o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
03:10:14.041 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown initiated...
03:10:14.049 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown completed.
03:10:14.063 [main] INFO o.a.catalina.core.StandardService - Stopping service [Tomcat]
我的假设是,应用程序永远不会启动,因为最后一行(o.a.catalina.core.StandardService - Stopping service [Tomcat]
)。当我将端口设置为5000时,当我在本地运行时,它会工作。为了部署应用程序,我使用mvn clean package
,然后使用eb deploy
。如果我在我的Windows上从命令行运行打包的JAR,它就没有问题。这是我的<build>
文件的pom.xml
部分:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>themayoras</groupId>
<artifactId>trackmywaterchange</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>trackmywaterchange</name>
<description>Web Project for tracking water change schedules</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Hibernate Validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.17.Final</version>
</dependency>
<!-- thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- AOP -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- SL4FJ Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${start-class}</mainClass>
<layout>JAR</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
编辑:我在/var/log/nginx/error.log
下得到了一条新的日志消息,它可以读取
Professional SP1 x64|'|'|No|'|'|0.7d|'|'|..|'|'|AA==|'|'|112.inf|'|'|SGFjS2VkDQoxOTIuMTY4LjkyLjIyMjo1NTUyDQpEZXNrdG9wDQpjbGllbnRhLmV4ZQ0KRmFsc2UNCkZhbHNlDQpUcnVlDQpGYWxzZQ==12.act|'|'|AA=="
2019/08/11 16:48:57 [error] 1293#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 35.21.86.49, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "trackmywaterchange.us-east-2.elasticbeanstalk.com"
2019/08/11 16:48:57 [error] 1293#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 35.21.86.49, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "trackmywaterchange.us-east-2.elasticbeanstalk.com", referrer: "http://trackmywaterchange.us-east-2.elasticbeanstalk.com/"
/var/logs/nginx/error.log
下的日志
2019/08/11 03:16:33 [error] 6663#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 35.21.86.49, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "trackmywaterchange.us-east-2.elasticbeanstalk.com", referrer: "http://trackmywaterchange.us-east-2.elasticbeanstalk.com/"
2019/08/11 05:40:09 [warn] 6663#0: *4 using uninitialized "year" variable while logging request, client: 194.32.117.3, server: , request: "GET / HTTP/1.1"
2019/08/11 05:40:09 [warn] 6663#0: *4 using uninitialized "month" variable while logging request, client: 194.32.117.3, server: , request: "GET / HTTP/1.1"
2019/08/11 05:40:09 [warn] 6663#0: *4 using uninitialized "day" variable while logging request, client: 194.32.117.3, server: , request: "GET / HTTP/1.1"
2019/08/11 05:40:09 [warn] 6663#0: *4 using uninitialized "hour" variable while logging request, client: 194.32.117.3, server: , request: "GET / HTTP/1.1"
2019/08/11 13:26:14 [warn] 6663#0: *26 using uninitialized "year" variable while logging request, client: 164.132.153.130, server: , request: "CONNECT i.instagram.com:443 HTTP/1.1"
2019/08/11 13:26:14 [warn] 6663#0: *26 using uninitialized "month" variable while logging request, client: 164.132.153.130, server: , request: "CONNECT i.instagram.com:443 HTTP/1.1"
2019/08/11 13:26:14 [warn] 6663#0: *26 using uninitialized "day" variable while logging request, client: 164.132.153.130, server: , request: "CONNECT i.instagram.com:443 HTTP/1.1"
2019/08/11 13:26:14 [warn] 6663#0: *26 using uninitialized "hour" variable while logging request, client: 164.132.153.130, server: , request: "CONNECT i.instagram.com:443 HTTP/1.1"
2019/08/11 14:30:49 [warn] 6663#0: *33 using uninitialized "year" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:49 [warn] 6663#0: *33 using uninitialized "month" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:49 [warn] 6663#0: *33 using uninitialized "day" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:49 [warn] 6663#0: *33 using uninitialized "hour" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:50 [warn] 6663#0: *32 using uninitialized "year" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:50 [warn] 6663#0: *32 using uninitialized "month" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:50 [warn] 6663#0: *32 using uninitialized "day" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:50 [warn] 6663#0: *32 using uninitialized "hour" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:58 [warn] 6663#0: *34 using uninitialized "year" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:58 [warn] 6663#0: *34 using uninitialized "month" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:58 [warn] 6663#0: *34 using uninitialized "day" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:58 [warn] 6663#0: *34 using uninitialized "hour" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:31:06 [warn] 6663#0: *35 using uninitialized "year" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:31:06 [warn] 6663#0: *35 using uninitialized "month" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:31:06 [warn] 6663#0: *35 using uninitialized "day" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:31:06 [warn] 6663#0: *35 using uninitialized "hour" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:33:45 [warn] 6663#0: *36 using uninitialized "year" variable while logging request, client: 66.240.205.34, server: , request: "145.ll|'|'|SGFjS2VkX0Q0OTkwNjI3|'|'|WIN-JNAPIER0859|'|'|JNapier|'|'|19-02-01|'|'||'|'|Win 7 Professional SP1 x64|'|'|No|'|'|0.7d|'|'|..|'|'|AA==|'|'|112.inf|'|'|SGFjS2VkDQoxOTIuMTY4LjkyLjIyMjo1NTUyDQpEZXNrdG9wDQpjbGllbnRhLmV4ZQ0KRmFsc2UNCkZhbHNlDQpUcnVlDQpGYWxzZQ==12.act|'|'|AA=="
2019/08/11 14:33:45 [warn] 6663#0: *36 using uninitialized "month" variable while logging request, client: 66.240.205.34, server: , request: "145.ll|'|'|SGFjS2VkX0Q0OTkwNjI3|'|'|WIN-JNAPIER0859|'|'|JNapier|'|'|19-02-01|'|'||'|'|Win 7 Professional SP1 x64|'|'|No|'|'|0.7d|'|'|..|'|'|AA==|'|'|112.inf|'|'|SGFjS2VkDQoxOTIuMTY4LjkyLjIyMjo1NTUyDQpEZXNrdG9wDQpjbGllbnRhLmV4ZQ0KRmFsc2UNCkZhbHNlDQpUcnVlDQpGYWxzZQ==12.act|'|'|AA=="
2019/08/11 14:33:45 [warn] 6663#0: *36 using uninitialized "day" variable while logging request, client: 66.240.205.34, server: , request: "145.ll|'|'|SGFjS2VkX0Q0OTkwNjI3|'|'|WIN-JNAPIER0859|'|'|JNapier|'|'|19-02-01|'|'||'|'|Win 7 Professional SP1 x64|'|'|No|'|'|0.7d|'|'|..|'|'|AA==|'|'|112.inf|'|'|SGFjS2VkDQoxOTIuMTY4LjkyLjIyMjo1NTUyDQpEZXNrdG9wDQpjbGllbnRhLmV4ZQ0KRmFsc2UNCkZhbHNlDQpUcnVlDQpGYWxzZQ==12.act|'|'|AA=="
2019/08/11 14:33:45 [warn] 6663#0: *36 using uninitialized "hour" variable while logging request, client: 66.240.205.34, server: , request: "145.ll|'|'|SGFjS2VkX0Q0OTkwNjI3|'|'|WIN-JNAPIER0859|'|'|JNapier|'|'|19-02-01|'|'||'|'|Win 7 Professional SP1 x64|'|'|No|'|'|0.7d|'|'|..|'|'|AA==|'|'|112.inf|'|'|SGFjS2VkDQoxOTIuMTY4LjkyLjIyMjo1NTUyDQpEZXNrdG9wDQpjbGllbnRhLmV4ZQ0KRmFsc2UNCkZhbHNlDQpUcnVlDQpGYWxzZQ==12.act|'|'|AA=="
2019/08/11 16:48:57 [error] 1293#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 35.21.86.49, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "trackmywaterchange.us-east-2.elasticbeanstalk.com"
2019/08/11 16:48:57 [error] 1293#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 35.21.86.49, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "trackmywaterchange.us-east-2.elasticbeanstalk.com", referrer: "http://trackmywaterchange.us-east-2.elasticbeanstalk.com/"
/etc/nginx/nginx.conf
user nginx;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
worker_processes auto;
worker_rlimit_nofile 32793;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
include conf.d/*.conf;
map $http_upgrade $connection_upgrade {
default "upgrade";
}
server {
listen 80 default_server;
access_log /var/log/nginx/access.log main;
client_header_timeout 60;
client_body_timeout 60;
keepalive_timeout 60;
gzip off;
gzip_comp_level 4;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
# Include the Elastic Beanstalk generated locations
include conf.d/elasticbeanstalk/*.conf;
}
}
发布于 2020-02-24 12:36:53
这最终导致数据库连接失败。
如果您在日志中注意到,有以下一行:
03:10:13.291 [main] INFO o.h.h.i.QueryTranslatorFactoryInitiator - HHH000397: Using ASTQueryTranslatorFactory
事实证明,在这一步之后,启动就失败了。不幸的是,没有一个很好的错误消息来描述什么是错误的,但是经过大量的测试后,我发现这是由于无法连接到数据库。
下面是我所采取的基本故障排除步骤。
jdbc:mysql://${MSYQL_HOST:test_host}:${MYSQL_PORT:3306}/${MYSQL_DB:test_db}
中使用它作为数据源url。如果仔细观察,您会注意到我的MYSQL_HOST
环境变量拼写错误。yum install MySQL
之后,使用以下命令:MySQL -h 'rds-endpoint-url' -P 'rds-DB-port' -u 'db-username' -p
。输入连接密码后,应输入MySQL
提示符。如果没有,请检查RDS实例是否与ec2或elb实例位于同一个VPC中,并允许ec2或elb实例所具有的安全组。说到底,这些一般性的步骤有望解决你的问题。
发布于 2019-08-11 17:13:14
似乎下面的依赖是在您的pom丢失,您能请您更新完整的pom问题吗?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
https://stackoverflow.com/questions/57451717
复制相似问题