zoukankan      html  css  js  c++  java
  • XmlBeanFactory和ApplicationContext读取spring xml配置文件

    1、使用XmlBeanFactory读取spring配置文件,可以如下:

     Resource resource=new ClassPathResource("conf/spring/applicationContext.xml");
      BeanFactory factory=new XmlBeanFactory(resource);
    
     com.geostar.query.beans.DataSource ds=(com.geostar.query.beans.DataSource)factory.getBean("ds");
    System.out.println(ds.getDriverClassName());
    

    控制台:

    log4j:WARN No such property [maxBackupIndex] in org.apache.log4j.DailyRollingFileAppender.
    log4j:WARN No such property [maxFileSize] in org.apache.log4j.DailyRollingFileAppender.
     ${google.database.driverClassName}

    ------下面是我的spring配置部分:

      <bean id="ds" class="com.geostar.query.beans.DataSource">
             <property name="driverClassName">
                 <value>${google.database.driverClassName}</value>
             </property>
             <property name="url" >
                    <value>${google.database.url}</value>
             </property>
             <property name="userName">
                  <value>${google.database.username}</value>
             </property>
             <property name="passWord">
                    <value>${google.database.password}</value>
             </property>
             <property name="tableName">
                       <value>${google.database.tablename}</value>
             </property>
             <property name="fieldName">
                       <value>${google.database.fieldname}</value>
             </property>
             <property name="orderFieldName">
                 <value>${google.database.orderfieldname}</value>
             </property>
        </bean>

      2、使用ApplicationContext

       

       ApplicationContext factory=new ClassPathXmlApplicationContext("classpath:conf/spring/applicationContext.xml");
        DataSource  ds=(DataSource)factory.getBean("ds");
        System.out.println(ds.getDriverClassName());
    

      控制台:

      --------------------------------------------spring ioc容器初始化----------------------

      oracle.jdbc.driver.OracleDriver

  • 相关阅读:
    蓝桥杯-带分数
    蓝桥杯-分红酒
    蓝桥杯-猜算式
    hdu2045不容易系列之(3)—— LELE的RPG难题
    蓝桥杯-奇怪的比赛
    linux应用之perl环境的安装(centos)
    linux应用之php开发环境lamp搭建(centos)
    linux应用之yum命令详解
    linux应用之用户管理相关命令
    linux应用之mysql数据库指定版本的yum安装(centos)
  • 原文地址:https://www.cnblogs.com/likehua/p/2290737.html
Copyright © 2011-2022 走看看