无法使用 @PropertySource 将 .properties 文件注入 Spring MVC 4.3 [英] Not able to inject .properties file into Spring MVC 4.3 using @PropertySource

查看:32
本文介绍了无法使用 @PropertySource 将 .properties 文件注入 Spring MVC 4.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 .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")})公共类 PersistenceConfig {@自动连线环境环境;......

我已经检查了我的构建路径,src/main/resources 在类路径上,如下所示

知道我遗漏了什么吗?

解决方案

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

I want to use .properties file to read mysql and hibernate properties using Environment and @PropertySources but I am getting error below

java.io.FileNotFoundException: class path resource [ /com/properties/persistence/mysqldb.properties] cannot be opened because it does not exist

Here is my project strutucture

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;
.......

I have checked my build path and src/main/resources is on the classpath as shown below

Any clue what I am missing ?

解决方案

As @Deinum pointed out you will need to remove the whitespace from classpath:com/properties/persistence/mysqldb.properties

这篇关于无法使用 @PropertySource 将 .properties 文件注入 Spring MVC 4.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆