题说明
最近看到Spring事务,在学习过程中遇到一个很苦恼问题
搭建好Spring的启动环境后出现了一点小问题
在启动时候却出现[java.lang.NullPointerException]
不过因为当时一个小小的疏忽 很low的问题 请往下看 ...
工程结构
代码片段
spring.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xsi:schemaLocation=" 6 http://www.springframework.org/schema/beans 7 http://www.springframework.org/schema/beans/spring-beans.xsd 8 http://www.springframework.org/schema/context 9 http://www.springframework.org/schema/context/spring-context.xsd"> 10 11 <!-- Spring注解扫描 --> 12 <context:component-scan base-package="com.*" /> 13 14 <!-- 1. 数据源对象: C3P0连接池 --> 15 <bean 16 class="com.mchange.v2.c3p0.ComboPooledDataSource"> 17 <property name="driverClass" value="org.h2.Driver"></property> 18 <property name="jdbcUrl" 19 value="jdbc:h2:tcp://192.168.190.1/~/test"></property> 20 <property name="user" value="sa"></property> 21 <property name="password" value="123"></property> 22 </bean> 23 24 <!-- 2. JdbcTemplate工具类实例 --> 25 <bean 26 class="org.springframework.jdbc.core.JdbcTemplate"> 27 <property name="dataSource" ref="dataSource"></property> 28 </bean> 29 30 <!-- 3.配置事务 --> 31 <bean 32 class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 33 <property name="dataSource" ref="dataSource"></property> 34 </bean> 35 36 </beans>