问题
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