欢迎来到银龙的博客

人生三从境界:昨夜西风凋碧树,独上高楼,望尽天涯路。 衣带渐宽终不悔,为伊消得人憔悴。 众里寻他千百度,蓦然回首,那人却在灯火阑珊处。

Spring基础之加载外部文件

一、用注解加载(@PropertySource)

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

}
  • ignoreResourceNotFound boolean值,默认是false,含义是如果找不到文件是否将其忽略,在默认情况在找不到文件或抛出异常。
  • name 配置这次属性的名称。
  • value 字符创数组,可以配置多个属性文件。

二、通过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>

 

posted on 2021-07-10 06:48  银龙科技  阅读(173)  评论(0编辑  收藏  举报

导航