我一直面临在Pivotal Cloud Web Foundry中部署Spring启动应用程序的问题。我一直收到这个错误:
2018-01-29T22:18:50.84-0500 [HEALTH/0] ERR Failed to make HTTP request to '/' on port 8080: connection refused
2018-01-29T22:18:50.84-0500 [CELL/0] ERR Timed out after 15s: health check never passed.
的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>com.stargate.transferfund</groupId>
<artifactId>TransferFund</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>TransferFund</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<startClass>org.springframework.boot.SpringApplication</startClass>
<maven.test.skip>true</maven.test.skip>
</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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- marked the embedded servlet container as provided -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- JMS related dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
控制器类
@Controller
public class TestController {
@RequestMapping(value="/", method=RequestMethod.GET)
public ResponseEntity sayHello() {
return new ResponseEntity("Hello world", HttpStatus.ACCEPTED);
}
}
应用
@SpringBootApplication
public class TransferFundApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(TransferFundApplication.class, args);
}
/**
* Used when run as WAR
*/
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(TransferFundApplication.class);
}
}
manifest.yml
---
applications:
- name: target
path: target/TransferFund-0.0.1-SNAPSHOT.jar
health-check-type: http
buildpack: https://github.com/cloudfoundry/java-buildpack.git
看起来由于某些原因未检测到端口8080。我尝试将health-check-type更改为process和port。当我将其更改为进程时,它可以正常工作,但终端不再可访问。需要一些帮助来解决问题
答案 0 :(得分:0)
请在添加以下执行器依赖项后尝试:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
还要将以下内容添加到manifest.yml:
health-check-http-endpoint: /info
health-check-type: http
我认为这应该可以解决问题。