使用spring中@PropertySourceh注解读取properties文件报错

使用spring中@PropertySource注解读取properties文件报错:java.lang.ClassNotFoundException: ${jdbc.driver}

环境:spring 4.2.8;jdk 1.7
1、peoperties文件中的内容:
properties文件

2、主配置类使用@PropertySource注解配置:
使用spring中@PropertySourceh注解读取properties文件报错_第1张图片
3、在子配置文件中使用@value("${jdbc.driver}")给类中的属性注入值:

使用spring中@PropertySourceh注解读取properties文件报错_第2张图片
4、如果就这样进行测试,会下面错误:
java.lang.ClassNotFoundException: ${jdbc.driver}

解决办法:
在主配置文件或子配置文件中加入下面的bean的配置:

@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }

你可能感兴趣的:(使用spring中@PropertySourceh注解读取properties文件报错)