繁体   English   中英

无法使用@PropertySource将.properties文件注入Spring MVC 4.3

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

我想使用.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上,如下所示

在此处输入图片说明

任何线索我想念什么?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM