简体   繁体   English

托管Spring Boot应用

[英]Hosting spring boot app

I could not host my spring boot app to Amazon Web Services: Elastic Beanstalk. 我无法将我的Spring Boot应用托管到Amazon Web Services:Elastic Beanstalk。 I did follow some video tutorials and stack overflow posts. 我确实遵循了一些视频教程和堆栈溢出帖子。 still helpless. 仍然无奈。 I want to host my war file to AWS and run it successfully. 我想将我的war文件托管到AWS并成功运行。 Here is my pom.xml and other stuff. 这是我的pom.xml和其他内容。 it works well in the local. 它在本地效果很好。 but after deploying to aws it does not work. 但部署到AWS后无法正常工作。 the health status shown is severe. 显示的健康状况很严重。

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

Main Class 主班

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

New Error 新错误

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

There are a couple of things wrong in your pom.xml pom.xml错误

  1. mixing version of Spring Boot 1.5.2 and 1.5.9 (never mix versions of a framework). Spring Boot 1.5.2和1.5.9的混合版本(切勿混合使用框架版本)。
  2. Inclusion JPA 1.0 API whereas you use a JPA 2.0 provider 包含JPA 1.0 API,而您使用的是JPA 2.0提供程序
  3. Generally AWS BeanStalk want your app to run on port 5000. 通常,AWS BeanStalk希望您的应用程序在端口5000上运行。

For 1 remove the <version> tag in your conflicting dependency and/or change the version of Spring Boot to the matching version. 对于1,删除冲突的依赖项中的<version>标记和/或将Spring Boot的版本更改为匹配的版本。

Remove the JPA 1.0 API. 删除JPA 1.0 API。

AWS expects your application to run on port 5000. Either specify this in the application.properties to be the port or specify a environment variable SERVER_PORT with value 5000 in your AWS environment. AWS希望您的应用程序在端口5000上运行。或者在application.properties中将其指定为端口,或者在您的AWS环境中指定值为5000的环境变量SERVER_PORT See Deploying a Spring Boot Application on AWS and especially the section on how to specify the port. 请参阅在AWS上部署Spring Boot应用程序 ,尤其是有关如何指定端口的部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM