【日常错误】spring-boot配置文件读取不到

最近在用spring-boot做项目时,遇到自定义的配置文件无法读取到的问题,通过在appcation.java类上定义@PropertySource(value = {"classpath:XXX.properties"},encoding="utf-8"),然后在组件中使用@value等方式读取properties文件配置时,始终都是null值,最后发现是由于项目数据层是使用的EJB访问,然后在ejb-config.xml配置文件里定义了这样一个bean:

<bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
        lazy-init="false">
        <property name="locations">
            <list>
                <value>classpath*:jnpurl.properties</value>
            </list>
        </property>
    </bean>

由于这个配置,覆盖了spring-boot的代码配置,所以前面配置的注解配置文件并没有被读取。

解决办法为 把配置文件统一位置:统一写在配置文件的bean中,或统一在代码注解中配置。

spring-boot配置文件参考资料:

http://www.cnblogs.com/hafiz/p/5876243.html

http://blog.csdn.net/je_ge/article/details/54783184

http://tengj.top/2017/02/28/springboot2/

  • 出处: http://www.cnblogs.com/hiscode/
    本文版权归作者和博客园共有,转载请在文章页面明显位置标明原文链接。
  • 原文地址:https://www.cnblogs.com/hiscode/p/7767592.html