我在我的数据源配置文件中使用 @PropertySource
来获取位于类路径上的属性文件 . 以下是我的项目结构 .
我相信我可以通过两种方式做到:
- 通过在
src
文件夹中创建包并将其添加到那里 . 由于src
文件夹已包含在eclipse的类路径中,因此以下应该可以正常工作 .
@PropertySources({@PropertySource(“classpath:com / spring / property / general.properties”),@ PropertySource(“classpath:com / spring / property / hibernate.properties”)})
- 第二种方法是创建一个
resources
文件夹并将其添加到类路径中,以下应该可以工作
@PropertySources({@PropertySource(“classpath:general.properties”),@ PropertySource(“classpath:hibernate.properties”)})
就我而言,两者都不起作用 . 作为一个中级java开发人员,这仍然让我困惑 . 谁能引导我朝着正确的方向前进以及我们如何在 生产环境 环境中为Spring配置类路径资源 .
EDIT :我已将项目结构更改为包含 src/java/resources
中的属性文件,我可以在构建路径中看到 resources
文件夹 . Spring 天还没有找到 .properties
.
1 回答
对于在Spring 4中使用
.properties
文件时遇到问题的任何人,请查看下面的线程以使您的设置与OP的设置相匹配 . 除了配置中的空格外,安装程序都很好 .Not able to inject .properties file into Spring MVC 4.3 using @PropertySource