其他分享
首页 > 其他分享> > Spring基础之加载外部文件

Spring基础之加载外部文件

作者:互联网

一、用注解加载(@PropertySource)

@PropertySource(value = { "classpath:jdbc.properties" },ignoreResourceNotFound = true)
public class ApplicationCongfig {

}

二、通过Xml配置文件加载

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">

    <!--扫描加注解的包  -->
    <context:component-scan base-package="cn.bzu.springpractice"></context:component-scan>
    <!-- 加载外部文件 -->
    <context:property-placeholder ignore-resource-not-found="false"  location="classpath:jdbc.properties"/>

</beans>

 

标签:文件,PropertySource,ignoreResourceNotFound,外部,Spring,value,默认,加载
来源: https://www.cnblogs.com/wangyinlon/p/14992992.html