【发布时间】:2016-09-10 13:29:32
【问题描述】:
我有一个 Spring Boot 应用程序,使用 maven,jdk1.8 构建。 它使用嵌入式 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 文件
但意识到这是在迭戈,所以我尝试了
cf ssh MY-APP
然后查看日志目录——那里什么都没有,一个文件也没有。 和
cf 事件
只是说应用程序已经启动。
CloudFoundry 中的 GUI 控制台很高兴地报告它“正在运行” 我什至如何开始解决这个问题?
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 环境变量
{
"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
}
}
}
【问题讨论】:
-
如果你得到 Tomcat 的 404,那么一切都运行良好 除了你的应用程序;你的路线是如何配置的?您希望根页面是什么?
-
我没有在 Cloud Foundry 中配置任何路由。我的控制器映射到
<app-url>/abc并返回 404。 -
您不需要配置 CF 路由,但您需要显示应用程序配置的 minimal reproducible example。
-
我已经添加了我能想到的配置文件,其余是默认的,比如当我在本地运行时 Tomcat 端口是 8080,并且在推送到 CF 时我没有更改任何内容。至少我希望我的应用程序会在控制台上抛出错误,但似乎 Spring boot 甚至没有初始化(没有横幅!)。我真正想要的是一些故障排除指导,不一定是我的解决方案问题在这里。
-
使用
cf logs appname检查日志。重新启动您的应用并检查日志以查看导致此问题的原因。