Spring无法使用@PropertySource

时间:2016-10-25 06:31:44

标签: java eclipse spring classpath

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

enter image description here

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

  1. src文件夹中创建一个包并将其添加到那里。由于src文件夹已包含在eclipse的类路径中,因此以下内容应该可以正常工作。
  2.   

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

    1. 第二种方法是创建一个resources文件夹并将其添加到类路径中,以下内容可以正常工作
    2.   

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

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

      修改: 我已将项目结构更改为在src/java/resources中包含属性文件,我可以在构建路径中看到resources文件夹。春天还没有找到.properties

      enter image description here

1 个答案:

答案 0 :(得分:1)

对于在Spring 4+中使用.properties文件时遇到问题的任何人,请查看下面的主题以使您的设置与OP的设置相匹配。除了配置中的空格外,安装程序都很好。

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

相关问题