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生成字符,復(fù)制到txt中
  • 關(guān)閉:main函數(shù)中修改:app.setShowBanne(false);
  • 4、配置文件
  • server.context-path=/helloboot //修改路徑
  • logging.file=D:/mylog/log.log //設(shè)置日志文件
  • 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配置:針對不同的環(huán)境的不同配置
    application-{profile}.properties
    在application.properties中設(shè)置spring.profiles.active=profilename來指定活動的profile
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容