0%

SpringBoot使用技巧

[TOC]

测试模板

在Application类中写好一个模板,其他测试类继承即可

1
2
3
4
5
@SpringBootTest
@RunWith(SpringRunner.class)
public class XXXApplicationTests {

}

启动日志美化

1
2
3
4
5
6
7
8
9
10
11
12
13
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {

private static final Logger LOG = LoggerFactory.getLogger(EurekaApplication.class);

public static void main(String[] args) {
SpringApplication app = new SpringApplication(EurekaApplication.class);
Environment env = app.run(args).getEnvironment();
LOG.info("启动成功!!");
LOG.info("Eureka地址: \thttp://127.0.0.1:{}", env.getProperty("server.port"));
}
}