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

▼魔方 西西 提交于 2020-02-05 05:31:05

问题


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 ?


回答1:


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



来源:https://stackoverflow.com/questions/40355105/not-able-to-inject-properties-file-into-spring-mvc-4-3-using-propertysource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!