本示例参考: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 } } } }
日志: