首页 文章

Spring无法使用@PropertySource找到classpath资源

提问于
浏览
0

我在我的数据源配置文件中使用 @PropertySource 来获取位于类路径上的属性文件 . 以下是我的项目结构 .

enter image description here

我相信我可以通过两种方式做到:

  • 通过在 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 .

enter image description here

1 回答

相关问题