applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:util="http://www.springframework.org/schema/util" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"> <!-- 数据源 --> <bean id="NNMiDS" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property> <property name="url" value="jdbc:oracle:thin:@10.27.125.61:1521:reporter"></property> <property name="username" value="openview"></property> <property name="password" value="openview"></property> </bean> <!-- 数据源 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property> <property name="url" value="jdbc:oracle:thin:@//147.16.17.98:1521/hpsm"></property> <property name="username" value="hndsPilot"></property> <property name="password" value="hndsPilot"></property> </bean> <!-- 网络监控(NNMi) 性能数据 --> <bean id="sybaseDS" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.sybase.jdbc4.jdbc.SybDriver"></property> <property name="url" value="jdbc:sybase:Tds:10.27.124.221:9303/hpnnmi_perfspi"></property> <property name="username" value="DBA"></property> <property name="password" value="HP_IQ"></property> </bean> </beans>
// 获取spring配置文件地址 ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext(); // 获取数据源 try { ds = (DataSource) ctx.getBean("dataSource"); sybaseDs = (DataSource) ctx.getBean("sybaseDS"); my= (DataSource) ctx.getBean("NNMiDS"); } catch (Exception e) { e.printStackTrace(); }
异常
这行报null怎么回事,我灰常不理解.请大家帮忙指点给出方案来,谢谢.