首页 > 解决方案 > 无法在 Amazon EC2 实例上运行战争文件

问题描述

我正在使用最新的 Angular 7 开发 Spring Boot 应用程序。我创建了一个构建并生成了 War 文件。

我在这个结构中配置了一个文件夹:

project-tool.war
config/application-prod.yml
config/application-dev.yml
config/application.yml
run.sh 
run.bat

在run.sh/run.bat中,这些命令写成-> java -jar project-tool.war --spring.profiles.active=prod --spring.config.location=config\application-prod.yml

我在 AWS 上创建了 Oracle 数据库实例并将配置放在 application-prod.yml 中。

然后我在 Windows 操作系统上使用 war 文件运行了这个项目,它工作正常。

我必须在 Amazon EC2 实例上运行这个 war 文件。所以我已经在 EC2 媒体实例上上传了这个文件夹。当我运行它时,它会抛出一个错误:

2019-03-02 06:50:53.489 ERROR 3082 --- [ost-startStop-1] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'securityConfiguration': Unsatisfied dependency expressed through field 'userDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsService' defined in URL [jar:file:/home/ec2-user/theProject/project-tool.war!/WEB-INF/classes!/com/myProject/security/DomainUserDetailsService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'auditLogService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'auditLogService' defined in URL [jar:file:/home/ec2-user/theProject/project-tool.war!/WEB-INF/classes!/com/myProject/service/AuditLogService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'auditLogRepository': Cannot create inner bean '(inner bean)#44dbafd9' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#44dbafd9': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: IO Error: The Network Adapter could not establish the connection
2019-03-02 06:50:53.551  WARN 3082 --- [ost-startStop-1] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [oracle.jdbc.driver.BlockSource.ThreadedCachingBlockSource.BlockReleaser] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 oracle.jdbc.driver.BlockSource$ThreadedCachingBlockSource$BlockReleaser.run(BlockSource.java:327)
2019-03-02 06:50:53.556  WARN 3082 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat

我还有另一个实例和其他项目(spring 和 angularJS)以类似的方式正常工作。但是为什么这不起作用,命令或角度有什么问题吗?

如何在 Amazon EC2 上工作?

标签: javaangularspringamazon-web-services

解决方案


您在此处读取错误堆栈跟踪的问题是数据库连接。注意核心错误信息:

初始化池失败:IO 错误:网络适配器无法建立连接

我不知道 Oracle 数据库是如何配置的,但可能您的数据库侦听器配置有问题,或者更简单地说,您的 EC2 和 Oracle 数据库实例之间的网络通信有问题,我建议您尝试查看安全组和网络配置。

问题不在于 Angular,而在于您的应用程序和数据库之间的数据库链接。


推荐阅读