2 回答

TA貢獻1794條經驗 獲得超8個贊
你可以試試:
在 [tomcat-server-folder]/bin 中創建名為“config”的文件夾
在 config 文件夾中創建 db.properties 文件。([tomcat-server-folder]/bin/config/db.properties)
只需在 Tomcat 的 bin 目錄中創建包含以下內容的文件 setenv.sh:
JAVA_OPTS="$JAVA_OPTS -Dspring.config.name=db"
或者您可以配置文件的特定位置:
JAVA_OPTS="$JAVA_OPTS -Dspring.config.location=/opt/app/default.properties,/opt/app/db.properties"

TA貢獻1900條經驗 獲得超5個贊
在 SpringBootServletInitializer 中配置來不及,必須在 spring 應用運行前設置屬性
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
System.setProperty("spring.config.name", "db");
SpringApplication.run(MyApplication.class, args);
}
}
添加回答
舉報