相關注解
spring boot通常有一個名爲== xxxApplication的類,入口類中有一個main方法, 在main方法中使用SpringApplication.run(xxxApplication.class,args)啓動springboot應用的項目==。
@RestController: 就是@Controller+@ResponseBody組合,支持RESTful訪問方 式,返回結果都是json字符串。
@SpringBootApplication 註解等價於:
@Configuration 項目啓動時自動配置spring 和 springmvc 初始搭建
@EnableAutoConfiguration 自動與項目中集成的第三方技術進行集成
@ComponentScan 掃描入口類所在子包以及子包後代包中註解
配置文件的拆分
說明: 在實際開發過程中生產環境和測試環境有可能是不一樣的 因此將生產中的配置和測試中的配置拆分開,是非常必要的在springboot中也提供了配置文件拆分的方式. 這裏以生產中項名名稱不一致爲例:
生產中項目名爲: cmfz
測試中項目名爲: springboot
端口同時爲: 8080
拆分如下:
#主配置文件:
application.yml #用來書寫相同的的配置
server:
port: 8080 #生產和測試爲同一個端口
spring:
profiles:
active: prod #激活拆分的那個配置文件
#生產配置文件:
application-pord.yml
server:
context-path: /cmfz
#測試配置文件:
application-dev.yml
server:
context-path: /springboot