我想使用.properties
使用Environment
读取mysql和hibernate属性的文件和@PropertySources
但我在下面收到错误
java.io.FileNotFoundException: class path resource [ /com/properties/persistence/mysqldb.properties] cannot be opened because it does not exist
这是我的项目结构
持久化配置.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
位于类路径上,如下所示
知道我缺少什么吗?
最佳答案
正如@Deinum指出的,您需要从classpath:com/properties/persistence/mysqldb.properties
中删除空格
关于java - 无法使用 @PropertySource 将 .properties 文件注入(inject) Spring MVC 4.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40355105/