【问题标题】:Springboot war project with tomcat and external application properties?具有tomcat和外部应用程序属性的Spring Boot战争项目?
【发布时间】:2019-07-30 13:03:39
【问题描述】:

我们如何提供一个外部 application.properties、datasource.properties 文件以及在外部 tomcat 上运行的 war 项目?有没有办法在 tomcat 配置中提供这些文件路径作为 vm 参数。如果使用上述配置,是否可以从这些文件中获取值作为 @Value 注释?

【问题讨论】:

标签: java tomcat


【解决方案1】:

有一个PropertySourcesPlaceholderConfigurer

 <bean name="propertySourcesPlaceholderConfigurer" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
    <property name="ignoreResourceNotFound" value="true" />
    <property name="location" value="file:${conf.dir}/app.properties" />
</bean>

conf.dir 可以通过 JVM 参数传递它,例如 -Dconf.dir=yourconfigFilePath

并像下面这样使用

<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="${dataSource.driverClassName}" />
<property name="url" value="${dataSource.url}" />
...

文件 app.properties

dataSource.driverClassName=org.apache.derby.jdbc.ClientDriver
dataSource.url=jdbc:derby://localhost:1527/dbpath 

【讨论】:

    猜你喜欢
    • 2021-01-23
    • 1970-01-01
    • 2016-03-23
    • 2022-11-10
    • 2018-07-05
    • 2015-06-19
    • 2019-03-21
    • 2015-10-28
    • 2015-10-03
    相关资源
    最近更新 更多