zoukankan      html  css  js  c++  java
  • Spring容器管理各种文件

    1. 导入文件

      <import resource="applicationContext-dataSource.xml" />

    2. 引用资源配置文件

    <context:property-placeholder location="classpath:jdbc.properties,classpath:xxx.properties"/>
    或者
    <context:property-placeholder location="xxx.properties" ignore-unresolvable="true"/>
    <context:property-placeholder location="xxx.properties" ignore-unresolvable="true"/>

      多次引用没有ignore-unresolvable="true"一定会出"Could not resolve placeholder"异常。

      Spring 2.5中,<context:property-placeholder>没有ignore-unresolvable属性,所以就不能使用上面的那种方法去配置,

      可以改如下的格式:

    <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>classpath:/jdbc.properties</value>
    </list>
    </property>
    </bean>

      使用引用的文件内容:

    <bean name="userInfo" class="test.UserInfo">  
      <property name="username" value="${db.username}"/>  
      <property name="password" value="${db.password}"/>  
    </bean> 

    3. 在项目java代码中引用资源文件

      例如引用xxx.properties中的内容

      首先在spring容器中配置:

    <util:properties id="settings" location="/WEB-INF/xxx.properties"></util:properties>

      java代码中使用方法:

    @Value("#{settings}")   
    private Properties file;
    或者
    @Value("#{settings['test.abc']}")   
    private String url;
  • 相关阅读:
    C# 之 获取文件名及拓展名
    C# 之 日常积累(二)
    C# 之 OpenFileDialog的使用
    Linux系统中,main函数的执行过程
    linux线程的实现
    linux内核--进程与线程
    内核线程和进程的区别
    软中断和硬中断
    Linux 2.4.x内核软中断机制
    几种USB控制器类型:OHCI,UHCI,EHCI,xHCI
  • 原文地址:https://www.cnblogs.com/cxyj/p/3885319.html
Copyright © 2011-2022 走看看