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 >
             <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

 

相关文章:

  • 2022-02-09
  • 2021-06-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
猜你喜欢
  • 2023-04-08
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案