SpringBoot中配置文件加載

<bean id="configProperties"       class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath*:/*.properties</value>
            </list>
        </property>
        <property name="fileEncoding" value="UTF-8"/>
 </bean>

XML配置文件中加上如上配置,並且在啓動類中用上

@ImportResource({"classpath*:/**/applicationContext-*.xml"})即可。

後續直接在代碼中用 @Value(value = "${key}")即可

 

發佈了11 篇原創文章 · 獲贊 7 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章