java - Spring Boot 属性文件外部化

标签 java maven tomcat spring-boot maven-profiles

我目前有 3 个属性文件:
application.properties

spring.profiles.active=@activatedProperties@

application-develoment.properties

#DB properties:
db.driver=org.postgresql.Driver
db.url=jdbc:postgresql://localhost:5432/mydb
db.username=user
db.password=pswd

#Data source management:
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.show_sql=true
hibernate.current_session_context_class=thread

application-production.properties

#DB properties:
db.driver=org.postgresql.Driver
db.url=jdbc:postgresql://localhost:5432/myproddb
db.username=admin
db.password=admin

#Data source management:
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.show_sql=false
hibernate.current_session_context_class=thread

我的 Maven 配置文件在我的 pom.xml

中设置如下
<profiles>
    <profile>
        <id>development</id>
        <properties>
            <activatedProperties>development</activatedProperties>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <profile>
        <id>production</id>
        <properties>
            <activatedProperties>production</activatedProperties>
        </properties>
    </profile>
</profiles>

和我的 DataSourceConfig 的:注释 @PropertySource(value = "classpath:application.properties")

当我使用开发或生产配置文件编译时一切正常,但现在我想将属性文件外部化到我的 Tomcat 服务器的/conf/localhost 目录,知道如何做到这一点吗?

最佳答案

使用 Spring Cloud Config 服务器为您提供集中的、外部化的配置(以及更多)。

https://spring.io/guides/gs/centralized-configuration/

关于java - Spring Boot 属性文件外部化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46192404/

相关文章:

java - 如何获取 JComponent 的顶级容器?

java - Spring Tool Suite无法导入spring库类

java - Tomcat 6.x web.xml 默认和自定义 servlet 路由

java - Bluemix Java Liberty Web 项目 java.lang.NoClassDefFoundError : when loading third party jar

java - log4j 2配置: appenderRef. xyz.ref?

maven - 如何使用 maven-assembly-plugin 定义执行顺序

java - Spring Security 在 Controller 中使用@security 注释

performance - Web 应用程序在 Tomcat 7 中非常慢

angular - 部署在 tomcat 服务器上的 angular(v4+) 刷新时出现 404 错误

java - 向 Java 项目添加资源