Spring Boot 核心功能
- 独立运行的spring项目
- 内嵌Servlet容器
- 提供starter简化Maven配置
- 自动配置Spring
- 准生产的应用控制
- 无代码生成和xml配置
@SpringBootApplication是一个三体结构
- @Configuration
- @EnableAutoConfiguration
- @ComponentScan
应用日志
spring-boot-starter-logging
在maven中添加依赖
<dependency>
<groupId> org.springframework.boot </groupId>
<artifactId> spring-boot-starter-logging </artifactId>
</dependency>
springboot提供的日志配置可以直接使用,如果需要对默认设定做调整,可以用一下两种方式:
- 遵循logback的约定,在classpath中使用自己定制的logback.xml配置文件
- 在文件系统的任何位置提供自己的logback.xml配置文件,然后通过kogging.config配置指向这个配置文件来启动他,比如在application.prpperties中指定
logging.config=/{some.path.you.defined}/any-logfile-name-I-like.log
log4j
在maven中添加依赖
<dependency>
<groupId> org.springframework.boot </groupId>
<artifactId> spring-boot-starter-log4j </artifactId>
</dependency>
读取application.properties属性
- 单个属性读取
使用@Value("${ }")注入 - 读取到bean中
- 在bean上添加注解@ConfigurationProperties(prefix = “前缀”)
- 在启动类上添加@EnableConfigurationProperties({类名.class})
- 在使用的地方使用@Autowired自动注入