简体   繁体   English

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

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

I want to use .properties file to read mysql and hibernate properties using Environment and @PropertySources but I am getting error below 我想使用.properties文件使用Environment@PropertySources读取mysql和hibernate属性,但是下面出现错误

java.io.FileNotFoundException: class path resource [ /com/properties/persistence/mysqldb.properties] cannot be opened because it does not exist java.io.FileNotFoundException:类路径资源[/com/properties/persistence/mysqldb.properties]无法打开,因为它不存在

Here is my project strutucture 这是我的项目结构

在此处输入图片说明

PersistenceConfig.java 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 我已经检查了我的构建路径,并且src/main/resources在classpath上,如下所示

在此处输入图片说明

Any clue what I am missing ? 任何线索我想念什么?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用@PropertySource的Spring属性配置 - Spring properties configuration using @PropertySource 使用Spring PropertySource无法通过绝对路径找到属性文件 - Cannot find a properties file by absolute path using Spring PropertySource 如何在Spring中使用@PropertySource加载的属性文件中配置“动态键” - how to configure 'dynamic key' in properties file loaded using @PropertySource in Spring 使用@PropertySource和外部JSON文件配置Spring属性 - Spring properties configuration using @PropertySource with external JSON file SPRING MVC - 使用外部文件作为@PropertySource - SPRING MVC - Use an external file as @PropertySource 使用相应的专用“属性”文件(使用@PropertySource)设置时会覆盖单个弹簧“beans”属性值 - Individual spring "beans" properties value overridden while setting with corresponding dedicated "properties" file (using @PropertySource) Spring PropertySource找不到的属性 - Properties not found with Spring PropertySource 如何使用Spring注入属性文件? - How to inject a properties file using Spring? Spring 引导 - 使用 @PropertySource 记录到文件不起作用 - Spring boot - logging to file using @PropertySource not working 在 JUnit 测试中使用来自 src/main/resources 的实际属性文件和 Spring @PropertySource - Using actual properties file from src/main/resources with Spring @PropertySource in JUnit test
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM