1.@SpringBootApplication 几个常用属性
1.scanBasePackages
默认扫描的包的路径是当前包以及子包下的所有类,可以通过scanBasePackages修改扫描包路径
(如:@SpringBootApplication(scanBasePackages="com.edu.spring.springboot.bean"))
2.排除指定的类/配置类
1.exclude :根据class来排除
(如:@SpringBootApplication(exclude=Runnable.class))
2.excludeName:根据class全局名称 来排除
(如:@SpringBootApplication(excludeName="java.lang.Runnable"))
2.banner
1.SpringApplication.setBannerMode()
1.SpringApplication.setBannerMode(Banner.Mode.OFF) :关闭banner的输出
2.其他几个Mode
enum Mode {
/**
* Disable printing of the banner.
*/
OFF,
/**
* Print the banner to System.out.
*/
CONSOLE,
/**
* Print the banner to the log file.
*/
LOG
}
2.自定义banner的方法
1.文字的banner
1.在classpath下放一个banner.txt文件即可
2.使用 banner.location 配置项来指定文字banner的文件路径及名称
2.图片的banner
1.springboot支持图片的banner,图片格式支持jpg/png/gif
2.使用 banner.image.location 配置项来指定图片banner的文件路径及名称
3.使用 banner.charset 配置项来指定 banner的编码,默认UTF-8
3.获取配置项的值的3种方法
1.ConfigurableApplicationContext.getEnvironment().getProperty("key")
2.编写一个获取 配置项的类,创建 属性 在属性上 加@Value("${key}") 注解。key等于 要得到的配置项的key
3.SpringApplication.setDefaultProperties(Map<String, Object> defaultProperties) 或
SpringApplication.setDefaultProperties(Properties defaultProperties)
4.获取配置项的值优先级:
1.application.properties 文件里的配置
2.SpringApplication.setDefaultProperties()的配置
3.@Value("${key}") 注解 或 ConfigurableApplicationContext.getEnvironment().getProperty("key")的配置