1、banner
去掉banner,有两种方法
第一种:coding
1 2 3 4 5 |
public static void main(String[] args) { SpringApplication app = new SpringApplication(MySpringConfiguration.class); app.setBannerMode(Banner.Mode.OFF); app.run(args); } |
第二种:配置文件
1 2 3 |
spring: main: banner-mode: "off" |
2、使用SpringApplication中传入的args
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import org.springframework.boot.*; import org.springframework.beans.factory.annotation.*; import org.springframework.stereotype.*; @Component public class MyBean { @Autowired public MyBean(ApplicationArguments args) { boolean debug = args.containsOption("debug"); List<String> files = args.getNonOptionArgs(); // if run with "--debug logfile.txt" debug=true, files=["logfile.txt"] } } |
3、ApplicationRunner or CommandLineRunner
ApplicationRunner和CommandLineRunner都是接口,都提供run方法实现,且都是在SpringApplication.run()方法前调用。不同点事两者接触application arguments的范式不一样,前者通过上面提到的ApplicationArguments方式使用参数,后者通过字符串数组的方式使用参数。
1 2 3 4 5 6 7 8 9 10 11 |
import org.springframework.boot.*; import org.springframework.stereotype.*; @Component public class MyBean implements CommandLineRunner { public void run(String... args) { // Do something... } } |
4、屏蔽掉spring-boot框架的日志
在你的main函数入口处加入如下的环境变量:
1 2 3 |
static { System.setProperty("log4j.shutdownCallbackRegistry", "com.djdch.log4j.StaticShutdownCallbackRegistry"); } |
需要加入如下的依赖:
1 2 3 4 5 |
<dependency> <groupId>com.djdch.log4j</groupId> <artifactId>log4j-staticshutdown</artifactId> <version>1.1.0</version> </dependency> |
- 我的微信
- 这是我的微信扫一扫
-
- 我的微信公众号
- 我的微信公众号扫一扫
-