【问题标题】:Hosting spring boot app托管 Spring Boot 应用程序
【发布时间】:2018-09-05 20:54:21
【问题描述】:

我无法将我的 Spring Boot 应用程序托管到 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();
    }

}

豆茎日志

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

【问题讨论】:

  • 你至少应该描述你遇到的问题/错误。
  • 停止。混合版本。您正在混合来自 spring boot 1.5.2 和 1.5.9 的 jar,从不混合框架的版本。还要删除 spring-boot-starter-data-jpa 中已经包含的 persistence-api 依赖项,并且您包含的是与您通过`spring-boot-starter-data-jpa 获得的休眠版本不兼容的旧版本。
  • @M.Deinum 这应该是一个答案。
  • 我更新了 pom.xml 并构建了一个新的 jar。我仍然遇到同样的错误。可能是什么原因?
  • 我做错了什么?

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


【解决方案1】:

您的pom.xml 中有几处错误

  1. Spring Boot 1.5.2 和 1.5.9 的混合版本(从不混合框架的版本)。
  2. 在您使用 JPA 2.0 提供程序时包含 JPA 1.0 API
  3. 通常 AWS BeanStalk 希望您的应用程序在端口 5000 上运行。

对于 1,删除冲突依赖项中的 &lt;version&gt; 标记和/或将 Spring Boot 的版本更改为匹配的版本。

删除 JPA 1.0 API。

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

【讨论】:

    猜你喜欢
    • 2015-12-15
    • 2019-06-19
    • 1970-01-01
    • 2020-04-28
    • 2021-11-22
    • 2018-02-25
    • 1970-01-01
    • 2018-01-13
    • 2019-04-29
    相关资源
    最近更新 更多