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

  • 相关阅读:
    loj#2540. 「PKUWC2018」随机算法
    loj#2538. 「PKUWC2018」Slay the Spire
    loj#2537. 「PKUWC2018」Minimax
    CF662C Binary Table
    bzoj4589: Hard Nim
    【HDU5909】Tree Cutting(FWT)
    P3175 [HAOI2015]按位或
    P4389 付公主的背包
    P4233 射命丸文的笔记
    GFS分布式文件系统环境部署与管理
  • 原文地址:https://www.cnblogs.com/likehua/p/2290737.html
Copyright © 2011-2022 走看看