托管春季启动应用程序

时间:2018-03-27 12:36:36

标签: java xml amazon-web-services spring-boot amazon-elastic-beanstalk

我无法将我的Spring启动应用程序托管到Amazon Web Services:Elastic Beanstalk。我确实关注了一些视频教程和堆栈溢出帖子。还是无奈。我想将我的war文件托管到AWS并成功运行它。这是我的pom.xml和其他东西。它在当地运作良好。但在部署到aws后它无法正常工作。显示的健康状况很严重。

Error Page Screenshot

POM.XML

   <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>
    <groupId>com.cloudsofts.cloudschool</groupId>
    <artifactId>CloudSchool</artifactId>
    <version>1.0.0</version>
    <name>Cloud School</name>
    <description>School Management Software</description>


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
    </parent>
    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</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-security</artifactId>
        </dependency>

        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.7.0</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

    </dependencies>

</project>

application.properties

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url-base=jdbc:mysql://cloudschool.cw86hx95lpfe.us-east-1.rds.amazonaws.com
spring.datasource.url=${spring.datasource.url-base}/cloud_school

spring.datasource.username=[username]
spring.datasource.password=[password]
spring.datasource.tomcat.max-wait=20000
spring.datasource.tomcat.max-active=50
spring.datasource.tomcat.max-idle=20
spring.datasource.tomcat.min-idle=1

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
spring.jpa.properties.hibernate.id.new_generator_mappings = true
spring.jpa.properties.hibernate.format_sql = true

logging.level.org.hibernate.tool.hbm2ddl: DEBUG  
logging.level.org.hibernate.type: TRACE 

server.port:80

spring.jpa.generate-ddl=true 
spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata
spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create
spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=cloud_school.sql


logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE


googleAppscript.translate.url = https://script.google.com/macros/s/AKfycbxu0351TyszGL6fAU9KHVYeR7jsaUMkm6v5fUCfI9eu_kFgLRgA/exec

主要类

package com.cloudsofts.cloudschool;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan
public class CloudSchoolStarter extends SpringBootServletInitializer {

    public static void main(String[] args) {

    SpringApplication.run(CloudSchoolStarter.class, args);

    }

    @Bean
    public PasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder();
    }

}

Beanstalk日志

-------------------------------------
/var/log/tomcat8/localhost.2018-03-27.log
-------------------------------------
27-Mar-2018 12:21:36.066 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log 2 Spring WebApplicationInitializers detected on classpath
27-Mar-2018 12:21:47.458 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Initializing Spring embedded WebApplicationContext


-------------------------------------
/var/log/httpd/elasticbeanstalk-access_log
-------------------------------------
172.31.27.16 (172.31.27.16) - - [27/Mar/2018:12:23:23 +0000] "GET / HTTP/1.1" 404 - "-" "ELB-HealthChecker/1.0"
172.31.91.28 (172.31.91.28) - - [27/Mar/2018:12:23:23 +0000] "GET / HTTP/1.1" 404 - "-" "ELB-HealthChecker/1.0"
172.31.27.16 (172.31.27.16) - - [27/Mar/2018:12:23:32 +0000] "GET / HTTP/1.1" 404 - "-" "ELB-HealthChecker/1.0"



-------------------------------------
/var/log/tomcat8/catalina.2018-03-27.log
-------------------------------------
27-Mar-2018 12:21:29.021 WARNING [localhost-startStop-1] org.apache.catalina.webresources.Cache.getResource Unable to add the resource at [/WEB-INF/classes/com/cloudsofts/cloudschool] to the cache for web application [] because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache
27-Mar-2018 12:21:29.025 WARNING [localhost-startStop-1] org.apache.catalina.webresources.Cache.getResource Unable to add the resource at [/WEB-INF/classes/com/cloudsofts/cloudschool/translate] to the cache for web application [] because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache


org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:753)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:729)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1129)
    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1871)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/cloudsofts/cloudschool/multitenant/config/HibernateConfig.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
    at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:151)
    at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:131)
    at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:86)
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    ... 10 more
Caused by: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
    at org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor.getValidationMode(PersistenceUnitInfoDescriptor.java:88)

新错误

------------------------------------
/var/log/nginx/error.log
-------------------------------------
2018/03/27 15:41:56 [error] 29286#0: *22 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.29.42, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.2.252"
2018/03/27 15:41:56 [error] 29286#0: *24 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.11.79, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.2.252"
2018/03/27 15:42:05 [error] 29286#0: *22 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.29.42, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.2.252"
2018/03/27 15:42:06 [error] 29286#0: *24 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.11.79, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.2.252"
2018/03/27 15:42:15 [error] 29286#0: *22 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.29.42, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.2.252"
2018/03/27 15:42:16 [error] 29286#0: *24 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.11.79, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.2.252"
2018/03/27 15:42:25 [error] 29286#0: *22 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.29.42, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.2.252"
2018/03/27 15:42:26 [error] 29286#0: *24 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.11.79, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.2.252"
2018/03/27 15:42:35 [error] 29286#0: *22 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.29.42, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.2.252"
2018/03/27 15:42:36 [error] 29286#0: *24 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.11.79, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.2.252"
2018/03/27 15:42:45 [error] 29286#0: *22 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.29.42, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.2.252"
2018/03/27 15:42:46 [error] 29286#0: *24 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.11.79, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.2.252"
2018/03/27 15:42:55 [error] 29286#0: *22 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.29.42, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.2.252"
2018/03/27 15:42:56 [error] 29286#0: *24 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.11.79, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.2.252"
2018/03/27 15:43:05 [error] 29286#0: *22 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.29.42, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.2.252"
2018/03/27 15:43:06 [error] 29286#0: *24 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.11.79, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.2.252"
2018/03/27 15:43:15 [error] 29286#0: *22 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.29.42, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.2.252"
2018/03/27 15:43:16 [error] 29286#0: *24 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.11.79, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "172.31.2.252"

1 个答案:

答案 0 :(得分:0)

pom.xml

中有一些问题
  1. 混合版本的Spring Boot 1.5.2和1.5.9(从不混合版本的框架)。
  2. 包含JPA 1.0 API,而您使用JPA 2.0提供程序
  3. 通常,AWS BeanStalk希望您的应用在端口5000上运行。
  4. For 1删除冲突依赖项中的<version>标记和/或将Spring Boot的版本更改为匹配版本。

    删除JPA 1.0 API。

    AWS希望您的应用程序在端口5000上运行。要么在application.properties中将其指定为端口,要么在AWS环境中指定值为SERVER_PORT的环境变量5000。请参阅Deploying a Spring Boot Application on AWS,尤其是有关如何指定端口的部分。