[英]How to change Spring Boot properties default path in Tomcat development environment
我需要使用两个*.properties
文件来确定Spring Boot应用程序服务器的配置。 如何设置第二个配置路径?
我使用spring-boot-starter-parent
版本1.5.10
和类似的*.properties
文件:
spring.datasource.url=url
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialec
spring.jpa.properties.hibernate.current_session_context_class=
org.springframewok.orm.hibernate4.SpringSessionContext
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.maximum-pool-size=10
spring.datasource.hikari.idle-timeout=30000
现在,我需要处理另一个属性文件中的数据库信息。
编辑:请注意,我需要将第二个属性文件放到WEB-INF
文件夹中的WAR文件之外。
(1)在开发模式和生产环境之间切换时,这是最佳做法。
版本1.5.10.RELEASE
参考: https : 1.5.10.RELEASE
更具体地说,您创建3个文件
通用属性的application.properties
。
仅在概要文件dev
使用的属性的application-dev.properties
仅在概要文件production
使用的属性的application-production.properties
(注意:在命名方面有约定)
点profile在application.properties
中使用的行有spring.profiles.active=dev
(开发中)或spring.profiles.active=production
(生产中)
(2)
请注意,我需要将第二个属性文件放在WAR文件之外的WEB-INF文件夹中。
假设您的文件是foo.properties
。 它在WAR文件外, 没有Spring属性文件的性质 。 因此,Spring Framework / Spring Boot无法自动读取它。 您必须编写几行Java代码来读取foo.properties
的内容,然后手动分配给配置(请参阅示例配置类 )
您可以使用@PropertySource
访问多个属性文件
请遵循以下stackoverflow线程。 https://stackoverflow.com/a/47178674/7538821
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.