- maven打包
- run后再Golas中填入complie,run
- target下就可以找到打包文件
- 运行springboot项目
java -jar ww.war --server.port=9080 - 热部署devtools
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<!--以来不会传递 -->
<optional>true</optional>
</dependency>
- 测试junit
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
//测试代码
@unWith(SpringRunner.class)
@SpringBootTest(webEnvironmet=WebEnvironment.RNDOM_PORT)//随机端口
public class BaseTest {
@Autowired
private UserService userService;
@Test
public void getUser() {
User u = userService.getUser(1);
Assert.assertNotNull(u);
}
//REST风格测试
@Autowired
private TestRestTemplate restTemplate;
@Test
public void getUserRest() {
User u = restTemplate.getForObject("/user/{id}"),User.class,1;
Assert.assertNotNull(u);
}
}
- mock测试
在接口未开发完成前,可以模拟进行测试
@MockBean
private ProductService pService;
@Test
priavte void getProduct(){
Product mproduct = new Product(1,"name","note");
//指定调用方法和返回的模拟数据
BDDMockito.given(pService.getProduct(1)).willReturn(mProduct);
Product product = pService.getProduct(1);
Assert.assertTrue(product.getId()==1);
}
- springboot监控状态actuator
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
//REST风格中复杂的约束,http监控使用,别无它用
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
<version>0.25.1.RELEASE</version>
</dependency>
//id为接口名称,enableByDefault默认启用
//Endpoint针对jmx和web监控均可用
//@JmxEndPoint支对Jmx可用,@WebEndPoint支对web可用
@Endpoint(id="dbcheck",enableByDefault=true)
public class DBEndpoint{
//@ReadOperation 代表http的get请求
//@WriteOperation 代表http的post请求,限定consumes类型
//@DeketeOperation 代表http的delete请求
@ReadOperation
public Map<String,Object> testDB(){
...
map.put("msg","数据库测试成功");
return map;
}
}
- 6.3健康指标
如监测磁盘,MongoDB,Redis,solr等服务器是否可用
//never,从不展示,默认
//when-authorized,签名后展示
//always ,每次都展示
management.endpoint.health.show-details=when-authorized
#关闭所有
management.health.defaults.enabled=false
#关闭开启单个db
management.health.db.enabled=true#
#指标的严重级别,DOWN 下线,OUT_OF_SERVICE 不再提供服务,UP 启动,UNKNOWN 未知
management.health.status.order=DOWN,OUT_OF_SERVICE,UP,UNKNOWN
- 6.4自定义健康指标
继承AbstractHealthIndicator即可
- JMX监控
java的jconsole.exe,在bin目录下
直接双击运行就会有页面显示