Spring 无法使用@PropertySource 找到类路径资源

Spring not able to find classpath resource with @PropertySource

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

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

  1. 通过在 src 文件夹中创建一个包并将它们添加到那里。由于 src 文件夹已包含在 Eclipse 的类路径中,因此应该可以使用以下内容。

@PropertySources({ @PropertySource("classpath: com/spring/property/general.properties"), @PropertySource("classpath: com/spring/property/hibernate.properties") })

  1. 第二种方法是创建一个 resources 文件夹并将其添加到类路径,下面应该可以工作

@PropertySources({ @PropertySource("classpath: general.properties"), @PropertySource("classpath: hibernate.properties") })

就我而言,两者都不起作用。作为一名中级 java 开发人员,这仍然让我感到困惑。谁能指导我正确的方向。以及我们如何在生产环境中为 Spring 配置类路径资源。

编辑: 我更改了我的项目结构以在 src/java/resources 中包含属性文件,并且我可以在构建路径中看到 resources 文件夹。 spring 仍然找不到 .properties

对于在 Spring 4+ 中使用 .properties 文件时遇到问题的任何人,请查看下面的主题以将您的设置与 OP 的设置相匹配。除了配置中的空格外,设置一切正常。

Not able to inject .properties file into Spring MVC 4.3 using @PropertySource