我們可以通過修改該配置檔案來對一些預設配置的配置值進行修改。
server:重啟專案,啟動日誌可以看到:tomcat started on port(s): 8888 (http) 啟動埠為8888,port: 8888
瀏覽器中訪問 http://localhost:8888 能正常訪問。
server:重啟專案,啟動日誌就可以看到:tomcat started on port(s): 8888 (http) with context path '/springboot',port: 8888servlet:
context-path: /springboot
瀏覽器中訪問 http://localhost:8888/springboot
能正常訪問。
offcn_ip:1.1.1.1offcn_port:
9999
@restcontroller訪問http://localhost:8888/springboot/getvalue,出現如圖結果:public
class
helloconfigcontroller ")
private
string offcn_ip;
@value("$")
private
string offcn_port;
public
string getvalue()
}
name: 張三
password: 123456birthday: 1997.08.22mobile: 15530499944address: 北京市
需要在實體類上增加註解@configurationproperties,並指定prrfix字首。
@data@allargsconstructor
@noargsconstructor
@configurationproperties(prefix = "userbody")
public
class
userbody
@restcontroller@enableconfigurationproperties() //@enableconfigurationproperties註解需要加在呼叫類上,或者加在啟動類上也可以。
SpringBoot 屬性配置 二
開啟頁面,alt 有提示 修改了tomcat為8888 上下文路徑 hello2 string是配置屬性 啟動瀏覽頁面 配置屬性欄位string 啟動瀏覽頁面 再配置mysql資料庫屬性 controll類 如果是多個屬性要配置,是太麻煩了,有沒有更簡單的配置呢?可以的,configurationp...
Springboot常規屬性配置
使用 value注入每個配置在實際專案中會顯得格外麻煩,因為我們的配置通常會是許多個,若使用上例的方式則要使用 value注入很多次。spring boot還提供了基於型別安全的配置方式,通過 configuratlonproperties將 properties屬性和乙個 bean及其屬性關聯,從...
SpringBoot配置屬性之MVC
主要是mvc相關的一些配置 spring.resources.cache period設定資源的快取時效,以秒為單位.spring.resources.chain.cache是否開啟快取,預設為 true spring.resources.chain.enabled是否開啟資源 handling c...