java - 无法使用 @PropertySource 将 .properties 文件注入(inject) Spring MVC 4.3

标签 java spring spring-mvc properties

我想使用.properties使用Environment读取mysql和hibernate属性的文件和@PropertySources但我在下面收到错误

java.io.FileNotFoundException: class path resource [ /com/properties/persistence/mysqldb.properties] cannot be opened because it does not exist

这是我的项目结构

enter image description here

持久化配置.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

知道我缺少什么吗?

最佳答案

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

关于java - 无法使用 @PropertySource 将 .properties 文件注入(inject) Spring MVC 4.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40355105/

相关文章:

java - 在 Spring 反序列化期间忽略字段?

java - 文本字段事件、规则等

Java反转字符串的方法

java - 泽西 + Spring + hibernate

java - 如何在spring boot中测试文件上传?

java - Spring Boot 在无效的 If-Modified-Since 值上抛出异常

java - Unity3D : APK file missing

java - 通过扫描仪读取日期类型的字段

java - Spring 4.x OSGI 支持

java - Spring Boot 在 web.xml 中启用 <async-supported>