一.配置檔案的生效順序,會對值進行覆寫
1. @TestPropertySource 注解
2. 指令行參數
3. Java系統屬性(System.getProperties())
4. 作業系統環境變量
5. 隻有在random.*裡包含的屬性會産生一個RandomValuePropertySource
6. 在打包的jar外的應用程式配置檔案(通過
java -jar demo.jar --spring.config.location=/path/test_evn.properties
)
7. 在打包的jar内的應用程式配置檔案(application.properties,包含YAML和profile變量)
8. 在@Configuration類上的@PropertySource注解
9. 預設屬性(使用SpringApplication.setDefaultProperties指定)
是以,正對6和7的情況,我們一般在應用程式外部放置配置yml檔案,防止每次釋出時被篡改哦!
nohup java -jar service-1.0.0.jar > service-1.0.0.log 2>&1 &
詳情可以參考:http://www.cnblogs.com/softidea/p/5759180.html
二.配置随機值
roncoo.secret=${random.value}
roncoo.number=${random.int}
roncoo.bignumber=${random.long}
roncoo.number.less.than.ten=${random.int(10)}
roncoo.number.in.range=${random.int[1024,65536]}
讀取使用注解: @Value(value = "${roncoo.secret}")
注:出現黃點提示,是要提示配置中繼資料,可以不配置
三.屬性占位符
當application.properties裡的值被使用時,它們會被存在的Environment過濾,是以你能夠引用先前定義的值(比如,系統屬性)。
roncoo.name=www.roncoo.com
roncoo.desc=${roncoo.name} is a domain name
四.Application屬性檔案,按優先級排序,位置高的将覆寫位置低的
1. 目前目錄下的一個/config子目錄
2. 目前目錄
3. 一個classpath下的/config包
4. classpath根路徑(root)
這個清單是按優先級排序的(清單中位置高的将覆寫位置低的)
五. 配置應用端口和其他配置的介紹
#端口配置:
server.port=8090
#時間格式化
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
#時區設定
spring.jackson.time-zone=Asia/Chongqing
六. 使用YAML代替Properties
注意寫法:冒号後要加個空格
常用的啟動項目的shell腳本:
start.sh
#!/bin/sh
rm -f tpid
nohup java -jar service-1.0.0.jar --spring.profiles.active=application.yml > service-1.0.0.log 2>&1 &
echo $! > tpid
stop.sh
#!/bin/sh
tpid=`cat tpid | awk '{print $1}'`
tpid=`ps -aef | grep $tpid | awk '{print $2}' |grep $tpid`
if [ ${tpid} ]; then
kill -9 $tpid
fi
check.sh
#!/bin/sh
tpid=`cat tpid | awk '{print $1}'`
tpid=`ps -aef | grep $tpid | awk '{print $2}' |grep $tpid`
if [ ${tpid} ]; then
echo App is running.
else
echo App is NOT running.
fi
kill.sh
#!/bin/sh
# kill -9 `ps -ef|grep 項目名稱|awk '{print $2}'`
kill -9 `ps -ef|grep demo|awk '{print $2}'`