java - 访问资源文件夹中的文件
问题描述
我正在开发一个 Spring Boot 应用程序,我想将 application.yml 中的一个参数(jndi.path)的值设置为资源文件夹中文件的路径。根据环境不同,路径也不同。
在我的 application.yml 中,我有这样的东西:
spring:
profiles: local
jndi:
path: file:C/path/to/myRessource/dev
spring:
profiles: rct
jndi:
path: file:C/path/to/myRessource/rct
dev
并且rct
是资源文件夹中的文件夹。唯一可行的方法是设置绝对路径。
(原谅我的英语)
解决方案
在资源中创建一个属性文件(config.properties)并在此文件中提供此配置文件值,并在 yml 文件中使用占位符,如下所示:
profile=rct/dev
并在 yml 文件中使用如下:
spring:
profiles: ${profile}
jndi:
path: file:C/path/to/myRessource/rct
您必须在 yml 中添加的另一项更改是提供属性文件的详细信息,可以通过这种方式完成。
config:
config-file-path: config.properties
推荐阅读
- html - XSD 文件中的标记验证
- vba - 如何将 TreeView 控件中的节点设置为粗体 (Access 2013)
- sql - 从多行计算持续时间并分组
- python - Python 即时压缩库
- java - 从当前格林威治标准时间到格林威治标准时间晚上 9 点获取差异
- spring-boot - Spring Boot 手动提交事务
- hibernate - 与 JPA 存储库一起使用时 SQL 语句不起作用
- python - 需要帮助来加速此代码 - Python 和 numpy
- ubuntu-16.04 - 在 cloud-config 中使用 Jinja 模板“ssh-rsa {{ v1.public_ssh_keys }}”会给出警告“找不到 text/jinja2 类型支持的子处理程序”
- swift - iPhone Xs 中的“主线程检查器:在后台线程上调用 UI API”错误,在模拟器中工作正常