【问题标题】:Not able to inject .properties file into Spring MVC 4.3 using @PropertySource无法使用 @PropertySource 将 .properties 文件注入 Spring MVC 4.3
【发布时间】:2016-11-01 06:27:51
【问题描述】:

我想使用.properties 文件使用Environment@PropertySources 读取mysql 和hibernate 属性,但我在下面遇到错误

java.io.FileNotFoundException: 类路径资源 [/com/properties/persistence/mysqldb.properties] 无法打开,因为它不存在

这是我的项目结构

PersistenceConfig.java

@Configuration
@EnableJpaRepositories(basePackages="com.hp.model.repository")
@EnableTransactionManagement
@PropertySources({
@PropertySource("classpath: /com/properties/persistence/mysqldb.properties"),
@PropertySource("classpath: /com/properties/persistence/hibernate.properties")})
public class PersistenceConfig {

@Autowired
Environment env;
.......

我检查了我的构建路径,src/main/resources 位于类路径中,如下所示

任何线索我错过了什么?

【问题讨论】:

  • 删除空格。 classpath:com/properties/persistence/mysqldb.properties.
  • @M.Deinum 空格导致了问题。设置没有问题。谢谢

标签: java spring spring-mvc properties


【解决方案1】:

正如@Deinum 指出的,您需要从classpath:com/properties/persistence/mysqldb.properties 中删除空格

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-13
    • 1970-01-01
    • 2017-01-17
    • 1970-01-01
    • 2019-03-14
    • 1970-01-01
    • 1970-01-01
    • 2014-02-11
    相关资源
    最近更新 更多