1. 程式人生 > >sofa-boot(1)helloworld項目

sofa-boot(1)helloworld項目

status 2-2 code oca inf 否則 port relative bubuko

本示例參考:https://www.sofastack.tech/sofa-boot/docs/QuickStart

示例采用sofa-boot 3.1.1版本。

如下步驟:

1、進入https://start.spring.io/,生成web項目

技術分享圖片

一定要勾選下邊的web依賴,否則無法啟動,因為沒有導入tomcat。而sofaboot2.3.1版本不存在這個問題。

生成例子程序:

技術分享圖片

2、pom.xml

將pom中的

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

替換為

<parent>
        <groupId>com.alipay.sofa</groupId>
        <artifactId>sofaboot-dependencies</artifactId>
        <version>3.1.1</version>
    </parent>

接著導入健康檢查依賴

<!-- import SOFABoot Dependency healthcheck and infra -->
        <dependency>
            <groupId>com.alipay.sofa</groupId>
            <artifactId>healthcheck-sofa-boot-starter</artifactId>
        </dependency>

3、application.properties

# Application Name
spring.application.name=SOFABoot Demo
# logging path
logging.path=./logs

4、啟動SofabootHelloworldApplication.java

...
Tomcat started on port(s): 8080 (http) with context path ‘‘
...

5、查看

查看version

瀏覽器輸入:http://localhost:8080/actuator/versions

[
    {
        "GroupId": "com.alipay.sofa",
        
"Doc-Url": "http://www.sofastack.tech/sofa-boot/docs/Home", "ArtifactId": "healthcheck-sofa-boot-starter", "Commit-Time": "2018-12-29T16:53:31+0800", "Commit-Id": "fffd3b47c629cc02b944b11d8fe68684afdb7b9f", "Version": "3.1.1", "Build-Time": "2019-02-18T09:53:30+0800" }, { "GroupId": "com.alipay.sofa", "Doc-Url": "http://www.sofastack.tech/sofa-boot/docs/Home", "ArtifactId": "infra-sofa-boot-starter", "Commit-Time": "2018-12-29T16:53:31+0800", "Commit-Id": "fffd3b47c629cc02b944b11d8fe68684afdb7b9f", "Version": "3.1.1", "Build-Time": "2019-02-18T09:52:12+0800" } ]

瀏覽器輸入:http://localhost:8080/actuator/readiness

{
    "status": "UP",
    "details": {
        "SOFABootReadinessHealthCheckInfo": {
            "status": "UP"
        },
        "diskSpace": {
            "status": "UP",
            "details": {
                "total": 78650093568,
                "free": 6799233024,
                "threshold": 10485760
            }
        }
    }
}

日誌:

技術分享圖片

sofa-boot(1)helloworld項目