Day06:SpringBoot配置

  • 1、pom依赖
  • starter pom
    <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
  • spring boot编译插件

<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>

  • 2、注解
  • @SpringBootApplication:开启自动配置,组合了@Configuration、@EnableAutoConfiguration、@CompnnentScan
  • 3、定制启动banner
  • 在src/main/resource下新建banner.txt
  • http://patorjk.com/software/taag生成字符,复制到txt中
  • 关闭:main函数中修改:app.setShowBanne(false);
  • 4、配置文件
  • server.context-path=/helloboot //修改路径
  • logging.file=D:/mylog/log.log //设置日志文件
  • logging.level.包名=级别 //配置日志级别
  • 4.1、使用xml配置
  • @ImportResource({"classpath:some--
  • context.xml","classpath:another-context.xml"})
  • @PropertySource指定porperties文件位置,并通过@Value注入值@Value("${book.author}")
  • 添加配置,在bean上注解@ConfigurationProperties(prefix = "author")
  • 5、profile配置:针对不同的环境的不同配置
    application-{profile}.properties
    在application.properties中设置spring.profiles.active=profilename来指定活动的profile
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容