无法在 Cloud Foundry 上部署 helloworld spring-boot 应用程序

Not able to deploy a helloworld spring-boot app on Cloud Foundry

使用 cf push helloworld-api 命令在 Cloud Foundry 上部署简单的 helloworld SpringBoot 应用程序时出现以下错误。

注意:我没有 manifest.yml 文件

错误日志:

Staging app and tracing logs...
   Downloading binary_buildpack...
   Downloading python_buildpack...
   Downloading go_buildpack...
   Downloading dotnet_core_buildpack...
   Downloading php_buildpack...
   Downloaded binary_buildpack
   Downloading hwc_buildpack...
   Downloaded go_buildpack
   Downloading staticfile_buildpack...
   Downloaded dotnet_core_buildpack
   Downloading dotnet_core_buildpack_beta...
   Downloaded dotnet_core_buildpack_beta
   Downloading java_buildpack...
   Downloaded hwc_buildpack
   Downloading ruby_buildpack...
   Downloaded staticfile_buildpack
   Downloading nodejs_buildpack...
   Downloaded java_buildpack
   Downloaded python_buildpack
   Downloaded ruby_buildpack
   Downloaded nodejs_buildpack
   Downloaded php_buildpack
   Cell 501d8bad-6db9-4f37-bcbb-bf678aeaa558 creating container for instance ef6baefc-b5e2-4bb4-9c5e-1711b4b8eb5c
   Cell 501d8bad-6db9-4f37-bcbb-bf678aeaa558 successfully created container for instance ef6baefc-b5e2-4bb4-9c5e-1711b4b8eb5c
   Downloading app package...
   Downloaded app package (85.1K)
   None of the buildpacks detected a compatible application
   Exit status 222
   Cell 501d8bad-6db9-4f37-bcbb-bf678aeaa558 stopping instance ef6baefc-b5e2-4bb4-9c5e-1711b4b8eb5c
   Cell 501d8bad-6db9-4f37-bcbb-bf678aeaa558 destroying container for instance ef6baefc-b5e2-4bb4-9c5e-1711b4b8eb5c
   Cell 501d8bad-6db9-4f37-bcbb-bf678aeaa558 successfully destroyed container for instance ef6baefc-b5e2-4bb4-9c5e-1711b4b8eb5c
Error staging application: An app was not successfully detected by any available buildpack

TIP: Use 'cf buildpacks' to see a list of supported buildpacks.
FAILED

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.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>helloworld</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.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>
    </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-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

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


</project>

HelloWorldApplication.java

@SpringBootApplication
@RestController
public class HelloworldApplication {

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

    @RequestMapping(path = "/", method = RequestMethod.GET)
    public String greet() {
        return "Hello World !";
    }

}

暂存的输出表明所有 detect 脚本 运行 用于所有已安装的 buildpack,包括 Java buildpack,但没有检测到任何能够运行 您的应用。

问题出在您的推送命令 cf push helloworld-api 上。由于您正在部署 Java 应用程序,因此您需要指定 -p path/to/my.jar。您需要它以便部署已编译的应用程序,而不是源代码。如果没有路径,cf push 默认推送当前目录,这可能是我们的源代码。 Java buildpack 只知道如何部署已编译的应用程序,它无法构建和部署您的源代码。

我遇到了同样的问题,您需要正确提供 jar 的路径。我的 jar 是在目标文件夹下创建的,所以我不得不将命令更改为

cf push springpcf -p target **target**\springpcf-0.0.1-SNAPSHOT.jar