zoukankan      html  css  js  c++  java
  • 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>
    作者:银龙

    -------------------------------------------

    个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!

    如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!

    万水千山总是情,打赏一分行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主,哈哈哈(っ•̀ω•́)っ✎⁾⁾!

  • 相关阅读:
    终于干掉了默认的输入法, 关于ctfmon.exe文件
    新工作一周的一些记录
    派送Maxthon 2.0 社区预览版本邀请.
    终于决定要跳槽了.
    当QA推出免责条款, 你会怎么看?
    Post by Word 2007, Test. 用word2007来发表一篇随笔.
    一个好的点菜系统
    再见2006
    昨天的实况以及忽悠姐妹花
    在公司我最近都只喝矿泉水
  • 原文地址:https://www.cnblogs.com/wangyinlon/p/14992992.html
Copyright © 2011-2022 走看看