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

时间:2016-11-01 06:27:52

标签: java spring spring-mvc properties

我想使用.properties文件来使用Environment@PropertySources读取mysql和hibernate属性,但我收到错误

  

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

这是我的项目结构

enter image description here

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位于类路径上,如下所示

enter image description here

任何线索我错过了什么?

1 个答案:

答案 0 :(得分:1)

正如@Deinum指出你需要从classpath:com/properties/persistence/mysqldb.properties

中删除空格