spring boot 简单学习记录

Spring Boot 核心功能
  1. 独立运行的spring项目
  2. 内嵌Servlet容器
  3. 提供starter简化Maven配置
  4. 自动配置Spring
  5. 准生产的应用控制
  6. 无代码生成和xml配置
@SpringBootApplication是一个三体结构
  1. @Configuration
  2. @EnableAutoConfiguration
  3. @ComponentScan

应用日志

spring-boot-starter-logging

在maven中添加依赖

<dependency>
    <groupId> org.springframework.boot </groupId>
    <artifactId> spring-boot-starter-logging </artifactId>
</dependency>

springboot提供的日志配置可以直接使用,如果需要对默认设定做调整,可以用一下两种方式:

  1. 遵循logback的约定,在classpath中使用自己定制的logback.xml配置文件
  2. 在文件系统的任何位置提供自己的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属性
  1. 单个属性读取
    使用@Value("${ }")注入
  2. 读取到bean中
    1. 在bean上添加注解@ConfigurationProperties(prefix = “前缀”)
    2. 在启动类上添加@EnableConfigurationProperties({类名.class})
    3. 在使用的地方使用@Autowired自动注入

待续*******************

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值