Spring Boot应用程序无法在CloudFoundry

时间:2016-05-14 10:25:44

标签: spring-boot pivotal-cloud-foundry

我有一个使用maven,jdk1.8构建的Spring启动应用程序。 它使用嵌入式Tomcat和jar包装。 我使用Spring Tool Suite将应用推送到CloudFoundry。推送后,我在控制台中收到以下消息:

[CONTAINER] org.apache.jasper.servlet.TldScanner               INFO  At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 
[CONTAINER] org.apache.catalina.startup.HostConfig             INFO  Deployment of web application directory /home/vcap/app/.java-buildpack/tomcat/webapps/ROOT has finished in 724 ms
[CONTAINER] org.apache.coyote.http11.Http11NioProtocol         INFO  Starting ProtocolHandler ["http-nio-8080"]
[CONTAINER] org.apache.tomcat.util.net.NioSelectorPool         INFO  Using a shared selector for servlet write/read
[CONTAINER] org.apache.catalina.startup.Catalina               INFO  Server startup in 814 ms
healthcheck passed
Container became healthy
Exit status 0
[Application Running Check] - Application appears to be running - MY-APP   

问题是 - 没有Spring Boot横幅,没有来自我的应用程序的启动消息 - 没有。 如果我浏览URL,我只得到一个404(这意味着Tomcat正在运行!)。

我试过

  

cf files

但意识到这是在迭戈,所以我试过

  

cf ssh MY-APP

并查看日志目录 - 根本没有任何内容,而不是单个文件。 和

  

CF-事件

只是说应用程序已经启动。

CloudFoundry中的GUI控制台愉快地报告其“跑步”#39; 我怎么开始解决这个问题?

Manifest.yml

---
applications:
- name: MY-APP
memory: 1024M
host: my-app
domain: xxx.yyy.com
services:
- p-mysql
instances: 1

application.properties

spring.jpa.hibernate.ddl-auto=update
spring.datasource.url = jdbc:mysql://<ip_addr>:3306/<db_name>?user=<user_name>&password=<password>
spring.datasource.username = <username>
spring.datasource.password = <password>
spring.thymeleaf.cache: false

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

<groupId>MyAPP</groupId>
<artifactId>my-app</artifactId>
<version>0.2</version>

<name>my-app</name>
<description>Attempt2</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.0.M1</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

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

    <!--<dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency> -->

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

    <dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>bootstrap</artifactId>
        <version>3.3.4</version>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>jquery</artifactId>
        <version>2.1.4</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>

<repository>
    <id>sonatype-nexus-snapshots</id>
    <name>Sonatype Nexus Snapshots</name>
    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
</repository>

</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
    <pluginRepository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf</artifactId>
            <version>2.1.5-SNAPSHOT</version>
        </dependency>
    </dependencies>
</dependencyManagement>

主要班级

package com.sa;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MyAppApplication {

   public static void main(String[] args) {
       SpringApplication.run(MyAppApplication.class, args);
   }
}

CloudFoundry env变量

{
 "staging_env_json": {},
 "running_env_json": {},
 "system_env_json": {
 "VCAP_SERVICES": {
  "p-mysql": [
    {
      "name": "p-mysql",
      "label": "p-mysql",
      "tags": [
        "mysql",
        "relational"
      ],
      "plan": "pre-existing-plan",
      "credentials": {
        "hostname": "<ip-addr>",
        "port": 3306,
        "name": "db-name",
        "username": "<username>",
        "password": "<password>",
        "uri": "mysql://<username>:<pass>@<ip_addr>:3306/<db-name>?reconnect=true",
        "jdbcUrl": "jdbc:mysql://<ip_addr>:3306/<db-name>?user=<username>&password=<pass>"
      }
    }
  ]
}
},
"application_env_json": {
"VCAP_APPLICATION": {
  "limits": {
    "mem": 1024,
    "disk": 1024,
    "fds": 16384
  },
  "application_id": "<some string>",
  "application_version": "<some other string>",
  "application_name": "my-app",
  "application_uris": [
    "my-app.xxx.yyy.com"
  ],
  "version": "2d5fd7b0-a1c2-4039-8eed-fb6e25772dee",
  "name": "my-app",
  "space_name": "xyz",
  "space_id": "<some string>",
  "uris": [
    "my-app.xxx.yyy.com"
  ],
  "users": null
   }
 }
}

1 个答案:

答案 0 :(得分:5)

在这里犁了半天后,我发现了问题。对于不耐烦,这是由于这个问题 [spring boot和java buildpack] [1] https://github.com/spring-projects/spring-boot/issues/4897

我没有从STS推送中得到任何东西,所以我恢复了CLI。 第一, mvn clean package 然后 cf push -p PATH-to-Jar 有一整条错误消息(最后!要看的东西!),以

结尾
2016-05-14T21:22:46.71+0800 [API/0]      OUT App instance exited with guid 83ec77d4-bcc5-4b12-8430-dd0a4d140b22 payload: {"instance"=>"27dc9686-1853-4 465-745e-55e450ee94c4", "index"=>0, "reason"=>"CRASHED", 
"exit_description"=>"2 error(s) occurred:\n\n* 2 error(s) occurred:\n\n* 
Exited with status 1
\n* cancelled\n* cancelled", "crash_count"=>3, "crash_timestamp"=>1463232166690142658, "version"=>"b37907a9-f4d6-4045-987c-f7bddb5e7a5c"}

上面的链接解释了问题以及如何解决它(使用最新的java-buildpack(使用cf cli的-b开关指定),所以如果有人在将Spring启动应用程序推送到云代工厂时看到此异常,那么你知道可能是什么潜在的问题!

ERR Caused by: java.lang.IllegalArgumentException: Cannot instantiate 
interface org.springframework.context.ApplicationContextInitializer :org.cloudfoundry.reconfiguration.spring.CloudPropertySourceApplicationContextInitializer