<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
<Resource auth="Container"
descrīption="DB Connection"
driverClass="com.mysql.jdbc.Driver"
maxPoolSize="10"
minPoolSize="2"
acquireIncrement="2"
name="jdbc/connPool"
user="root"
password="123"
factory="org.apache.naming.factory.BeanFactory"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
jdbcUrl="jdbc:mysql://localhost:3306/kds?autoReconnect=true" />
</GlobalNamingResources>
context.xml
<ResourceLink name="jdbc/connPool" global="jdbc/connPool" type="javax.sql.DataSource"/>
/webapps/**/WEB-INF/web.xml
<resource-ref>
<descrīption>DB Connection</descrīption>
<res-ref-name>jdbc/connPool</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
commons.xml
<!-- 定义数据源Bean,使用C3P0数据源实现 com.mchange.v2.c3p0.ComboPooledDataSource-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/kds" />
<property name="user" value="root" />
<property name="password" value="123" />
<property name="initialPoolSize" value="10" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="30" />
<property name="acquireIncrement" value="5" />
<property name="maxStatements" value="0" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>com/kds/pojo/xml/User.hbm.xml</value>
<value>com/kds/pojo/xml/Authority.hbm.xml</value>
<value>com/kds/pojo/xml/Contract.hbm.xml</value>
<value>com/kds/pojo/xml/Contracttype.hbm.xml</value>
<value>com/kds/pojo/xml/Landmark.hbm.xml</value>
<value>com/kds/pojo/xml/Orders.hbm.xml</value>
<value>com/kds/pojo/xml/Product.hbm.xml</value>
<value>com/kds/pojo/xml/Project.hbm.xml</value>
<value> com/kds/pojo/xml/Projectuserrelation.hbm.xml</value>
<value>com/kds/pojo/xml/Rightrolerelation.hbm.xml</value>
<value>com/kds/pojo/xml/Role.hbm.xml</value>
<value>com/kds/pojo/xml/Suit.hbm.xml</value>
<value>com/kds/pojo/xml/Suitproductrelation.hbm.xml</value>
<value>com/kds/pojo/xml/Suitproductrelationinorder.hbm.xml</value>
<value>com/kds/pojo/xml/Task.hbm.xml</value>
<value>com/kds/pojo/xml/Taskuserrelation.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="hibernate.autoReconnect">true</prop>
<prop key="hibernate.show_sql">true</prop><!-- 显示sql -->
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
<property name="dataSource" ref="dataSource" />
</bean>
在网上找到的帖子都是关于tomcat7.0bug的补丁解决办法,但我的问题应该不是bug的问题。
现在的现象是,我网站正常启动了,但是客户端一提交表单到服务器查询就出现javax.servlet.ServletException: java.lang.NullPointerException的空指针错误,我觉得像是C3P0的配置没有连接上数据库而是对象为空造成的,但是为什么连不上我搞了2天都没找到原因,有没有遇到过同样问题的同志给点提示。
3 个解决方案
#1
原来我这段配置应该写在项目的\META-INF\context.xml中
测试页面页显示出了数据库的数据,mysqlTest.jsp
但是网站上的提交用户名和密码到服务器还是返回NullPointerException
java.lang.NullPointerException
com.kds.action.ContractManagerAction.login(ContractManagerAction.java:144)
ContractManagerAction.java
数据库console没有“list is null”的字样打印。
<Resource auth="Container"
descrīption="DB Connection"
driverClass="com.mysql.jdbc.Driver"
maxPoolSize="10"
minPoolSize="2"
acquireIncrement="2"
name="jdbc/connPool"
user="root"
password="123"
factory="org.apache.naming.factory.BeanFactory"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
jdbcUrl="jdbc:mysql://localhost:3306/kds?autoReconnect=true" />
测试页面页显示出了数据库的数据,mysqlTest.jsp
<%@page language="java" import="java.util.*,java.sql.*,javax.naming.*,javax.sql.*" pageEncoding="GB2312"%>
<%@page import="com.mchange.v2.c3p0.*"%>
<%@page import="java.sql.Connection"%>
<%
Connection conn=null;
try
{
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/connPool");
conn=ds.getConnection();
}
catch(NamingException ex)
{
ex.printStackTrace();
}
String sql="select * from user";
PreparedStatement ps=conn.prepareStatement(sql);
ResultSet rs=ps.executeQuery();
//获得数据结果集合
ResultSetMetaData rmeta = rs.getMetaData();
//确定数据集的列数,亦字段数
int numColumns=rmeta.getColumnCount();
// 输出每一个数据值
out.print("id");
out.print("|");
out.print("num");
out.print("<br>");
while(rs.next()) {
out.print(rs.getString(2)+" ");
out.print("|");
out.print(rs.getString(3));
out.print("<br>");
}
out.print("<br>");
out.print("Get it!");
rs.close();
statement.close();
connection.close();
%>
但是网站上的提交用户名和密码到服务器还是返回NullPointerException
<form action="contractManager_login.action" method="post" id="loginForm" name="loginForm">
<table width="100%" border="0">
<tr>
<td align="right">Email:</td>
<td align="left"><input name="email" id="loginName" type="text" value="" size="20" /></td>
</tr>
<tr>
<td align="right">密 码:</td>
<td align="left"><input name="password" type="password" id="loginPwd" value="" size="20" /></td>
</tr>
<tr>
<td align="right">验证码:</td>
<td align="left"><input name="num" type="text" value="" id="num" size="10" onkeydown="javascript:keyDownLogin()"/>
<img border=0 src="image.jsp">
</td>
</tr>
<tr>
<td colspan="2" align="center"><a href="#" class="p-dengl" onclick="checkLogin()">登录</a>
</tr>
</table>
</form>
java.lang.NullPointerException
com.kds.action.ContractManagerAction.login(ContractManagerAction.java:144)
ContractManagerAction.java
/* 用户登录 */
public String login() {
String email = this.getRequest().getParameter("email");
String password = this.getRequest().getParameter("password");
MD5 md5 = new MD5();
if (email == null || password == null)
return ERROR;
User user = cmService.login(email, md5.getMD5ofStr(password));//Line 144
ActionContext.getContext().getSession().put("user", user);
if (user == null)
return ERROR;
this.getSession().setAttribute("user", user);
return "login";
}
public User login(String email, String password) {
List<User> list = getHibernateTemplate().find(" from User u where u.email=? and u.password=?", new String[]{email, password});
User user = null;
if(list == null)
System.out.println("List is Null");
if (list != null && !list.isEmpty())
user = list.get(0);
return user;
}
数据库console没有“list is null”的字样打印。
#2
我的cmService没有初始化……唉
#3
ApplicationContext-Commons.xml
ApplicationContext-Actions.xml
ApplicationContext-Service.xml
ApplicationContext-Daos.xml
ContractManagerService
我cmService明明注入了,应该不是空值啊?
<?xml version="1.0" encoding="utf-8"?>
<!-- beans是Spring配置文件的根元素,并且指定了Schema信息 -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 定义数据源Bean,使用C3P0数据源实现 com.mchange.v2.c3p0.ComboPooledDataSource-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/kds" />
<property name="user" value="root" />
<property name="password" value="123" />
<property name="initialPoolSize" value="10" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="30" />
<property name="acquireIncrement" value="5" />
<property name="maxStatements" value="0" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>com/kds/pojo/xml/User.hbm.xml</value>
<value>com/kds/pojo/xml/Authority.hbm.xml</value>
<value>com/kds/pojo/xml/Contract.hbm.xml</value>
<value>com/kds/pojo/xml/Contracttype.hbm.xml</value>
<value>com/kds/pojo/xml/Landmark.hbm.xml</value>
<value>com/kds/pojo/xml/Orders.hbm.xml</value>
<value>com/kds/pojo/xml/Product.hbm.xml</value>
<value>com/kds/pojo/xml/Project.hbm.xml</value>
<value> com/kds/pojo/xml/Projectuserrelation.hbm.xml</value>
<value>com/kds/pojo/xml/Rightrolerelation.hbm.xml</value>
<value>com/kds/pojo/xml/Role.hbm.xml</value>
<value>com/kds/pojo/xml/Suit.hbm.xml</value>
<value>com/kds/pojo/xml/Suitproductrelation.hbm.xml</value>
<value>com/kds/pojo/xml/Suitproductrelationinorder.hbm.xml</value>
<value>com/kds/pojo/xml/Task.hbm.xml</value>
<value>com/kds/pojo/xml/Taskuserrelation.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="hibernate.autoReconnect">true</prop>
<prop key="hibernate.show_sql">true</prop><!-- 显示sql -->
<prop key="hibernate.format_sql">true</prop><!-- 将sql脚本进行进行格式化后再输出 -->
</props>
</property>
<property name="dataSource" ref="dataSource" />
</bean>
<!--设置事务管理 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!-- 配置事务的传播特性 ,指定事务管理器-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 配置详细的事务语义 -->
<tx:attributes>
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
</beans>
ApplicationContext-Actions.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="projectManagerAction" class="com.kds.action.ProjectManagerAction" scope="prototype">
<property name="pmService" ref="ProjectManagerService" />
</bean>
<bean id="contractManagerAction" class="com.kds.action.ContractManagerAction" scope="prototype">
<property name="pmService" ref="ProjectManagerService" />
<property name="cmService" ref="ContractManagerService" />
</bean>
<bean id="roleAndRightAction" class="com.kds.action.RoleAndRightAction" scope="prototype">
<property name="pmService" ref="ProjectManagerService" />
<property name="cmService" ref="ContractManagerService" />
<property name="pcService" ref="ProjectCustomerService" />
</bean>
</beans>
ApplicationContext-Service.xml
<?xml version="1.0" encoding="GBK"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- 定义业务逻辑组件 -->
<bean id="projectTemplate" abstract="true" lazy-init="true">
<property name="projectDao" ref="projectDao" />
<property name="landmarkDao" ref="landmarkDao" />
<property name="taskDao" ref="taskDao" />
<property name="userDao" ref="userDao" />
<property name="roleDao" ref="roleDao" />
<property name="taskuserrelationDao" ref="taskuserrelationDao" />
<property name="projectuserrelationDao" ref="projectuserrelationDao" />
</bean>
<bean id="projectManagerService" class="com.kds.service.impl.ProjectManagerService" parent="projectTemplate" />
<bean id="projectCustomerService" class="com.kds.service.impl.ProjectCustomerService" parent="projectTemplate"/>
<bean id="contractTemplate" abstract="true" lazy-init="true">
<property name="userDao" ref="userDao"/>
<property name="contractDao" ref="contractDao"/>
<property name="contracttypeDao" ref="contracttypeDao" />
<property name="productDao" ref="productDao" />
</bean>
<bean id="contractManagerService" class="com.kds.service.impl.ContractManagerService" parent="contractTemplate" />
</beans>
ApplicationContext-Daos.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- 配置DAO组件模板 -->
<bean id="daoTemplate" abstract="true" lazy-init="true">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="projectDao" class="com.kds.dao.impl.ProjectDAO" parent="daoTemplate"/>
<bean id="landmarkDao" class="com.kds.dao.impl.LandmarkDAO" parent="daoTemplate"/>
<bean id="taskDao" class="com.kds.dao.impl.TaskDAO" parent="daoTemplate"/>
<bean id="userDao" class="com.kds.dao.impl.UserDAO" parent="daoTemplate"/>
<bean id="roleDao" class="com.kds.dao.impl.RoleDAO" parent="daoTemplate"/>
<bean id="taskuserrelationDao" class="com.kds.dao.impl.TaskuserrelationDAO" parent="daoTemplate"/>
<bean id="projectuserrelationDao" class="com.kds.dao.impl.ProjectuserrelationDAO" parent="daoTemplate"/>
<bean id="contractDao" class="com.kds.dao.impl.ContractDAO" parent="daoTemplate" />
<bean id="contracttypeDao" class="com.kds.dao.impl.ContracttypeDAO" parent="daoTemplate" />
<bean id="productDao" class="com.kds.dao.impl.ProductDAO" parent="daoTemplate"/>
</beans>
ContractManagerService
public User login(String email, String password) {
return userDao.login(email, password);
}
我cmService明明注入了,应该不是空值啊?
#1
原来我这段配置应该写在项目的\META-INF\context.xml中
测试页面页显示出了数据库的数据,mysqlTest.jsp
但是网站上的提交用户名和密码到服务器还是返回NullPointerException
java.lang.NullPointerException
com.kds.action.ContractManagerAction.login(ContractManagerAction.java:144)
ContractManagerAction.java
数据库console没有“list is null”的字样打印。
<Resource auth="Container"
descrīption="DB Connection"
driverClass="com.mysql.jdbc.Driver"
maxPoolSize="10"
minPoolSize="2"
acquireIncrement="2"
name="jdbc/connPool"
user="root"
password="123"
factory="org.apache.naming.factory.BeanFactory"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
jdbcUrl="jdbc:mysql://localhost:3306/kds?autoReconnect=true" />
测试页面页显示出了数据库的数据,mysqlTest.jsp
<%@page language="java" import="java.util.*,java.sql.*,javax.naming.*,javax.sql.*" pageEncoding="GB2312"%>
<%@page import="com.mchange.v2.c3p0.*"%>
<%@page import="java.sql.Connection"%>
<%
Connection conn=null;
try
{
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/connPool");
conn=ds.getConnection();
}
catch(NamingException ex)
{
ex.printStackTrace();
}
String sql="select * from user";
PreparedStatement ps=conn.prepareStatement(sql);
ResultSet rs=ps.executeQuery();
//获得数据结果集合
ResultSetMetaData rmeta = rs.getMetaData();
//确定数据集的列数,亦字段数
int numColumns=rmeta.getColumnCount();
// 输出每一个数据值
out.print("id");
out.print("|");
out.print("num");
out.print("<br>");
while(rs.next()) {
out.print(rs.getString(2)+" ");
out.print("|");
out.print(rs.getString(3));
out.print("<br>");
}
out.print("<br>");
out.print("Get it!");
rs.close();
statement.close();
connection.close();
%>
但是网站上的提交用户名和密码到服务器还是返回NullPointerException
<form action="contractManager_login.action" method="post" id="loginForm" name="loginForm">
<table width="100%" border="0">
<tr>
<td align="right">Email:</td>
<td align="left"><input name="email" id="loginName" type="text" value="" size="20" /></td>
</tr>
<tr>
<td align="right">密 码:</td>
<td align="left"><input name="password" type="password" id="loginPwd" value="" size="20" /></td>
</tr>
<tr>
<td align="right">验证码:</td>
<td align="left"><input name="num" type="text" value="" id="num" size="10" onkeydown="javascript:keyDownLogin()"/>
<img border=0 src="image.jsp">
</td>
</tr>
<tr>
<td colspan="2" align="center"><a href="#" class="p-dengl" onclick="checkLogin()">登录</a>
</tr>
</table>
</form>
java.lang.NullPointerException
com.kds.action.ContractManagerAction.login(ContractManagerAction.java:144)
ContractManagerAction.java
/* 用户登录 */
public String login() {
String email = this.getRequest().getParameter("email");
String password = this.getRequest().getParameter("password");
MD5 md5 = new MD5();
if (email == null || password == null)
return ERROR;
User user = cmService.login(email, md5.getMD5ofStr(password));//Line 144
ActionContext.getContext().getSession().put("user", user);
if (user == null)
return ERROR;
this.getSession().setAttribute("user", user);
return "login";
}
public User login(String email, String password) {
List<User> list = getHibernateTemplate().find(" from User u where u.email=? and u.password=?", new String[]{email, password});
User user = null;
if(list == null)
System.out.println("List is Null");
if (list != null && !list.isEmpty())
user = list.get(0);
return user;
}
数据库console没有“list is null”的字样打印。
#2
我的cmService没有初始化……唉
#3
ApplicationContext-Commons.xml
ApplicationContext-Actions.xml
ApplicationContext-Service.xml
ApplicationContext-Daos.xml
ContractManagerService
我cmService明明注入了,应该不是空值啊?
<?xml version="1.0" encoding="utf-8"?>
<!-- beans是Spring配置文件的根元素,并且指定了Schema信息 -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 定义数据源Bean,使用C3P0数据源实现 com.mchange.v2.c3p0.ComboPooledDataSource-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/kds" />
<property name="user" value="root" />
<property name="password" value="123" />
<property name="initialPoolSize" value="10" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="30" />
<property name="acquireIncrement" value="5" />
<property name="maxStatements" value="0" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>com/kds/pojo/xml/User.hbm.xml</value>
<value>com/kds/pojo/xml/Authority.hbm.xml</value>
<value>com/kds/pojo/xml/Contract.hbm.xml</value>
<value>com/kds/pojo/xml/Contracttype.hbm.xml</value>
<value>com/kds/pojo/xml/Landmark.hbm.xml</value>
<value>com/kds/pojo/xml/Orders.hbm.xml</value>
<value>com/kds/pojo/xml/Product.hbm.xml</value>
<value>com/kds/pojo/xml/Project.hbm.xml</value>
<value> com/kds/pojo/xml/Projectuserrelation.hbm.xml</value>
<value>com/kds/pojo/xml/Rightrolerelation.hbm.xml</value>
<value>com/kds/pojo/xml/Role.hbm.xml</value>
<value>com/kds/pojo/xml/Suit.hbm.xml</value>
<value>com/kds/pojo/xml/Suitproductrelation.hbm.xml</value>
<value>com/kds/pojo/xml/Suitproductrelationinorder.hbm.xml</value>
<value>com/kds/pojo/xml/Task.hbm.xml</value>
<value>com/kds/pojo/xml/Taskuserrelation.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="hibernate.autoReconnect">true</prop>
<prop key="hibernate.show_sql">true</prop><!-- 显示sql -->
<prop key="hibernate.format_sql">true</prop><!-- 将sql脚本进行进行格式化后再输出 -->
</props>
</property>
<property name="dataSource" ref="dataSource" />
</bean>
<!--设置事务管理 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!-- 配置事务的传播特性 ,指定事务管理器-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 配置详细的事务语义 -->
<tx:attributes>
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
</beans>
ApplicationContext-Actions.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="projectManagerAction" class="com.kds.action.ProjectManagerAction" scope="prototype">
<property name="pmService" ref="ProjectManagerService" />
</bean>
<bean id="contractManagerAction" class="com.kds.action.ContractManagerAction" scope="prototype">
<property name="pmService" ref="ProjectManagerService" />
<property name="cmService" ref="ContractManagerService" />
</bean>
<bean id="roleAndRightAction" class="com.kds.action.RoleAndRightAction" scope="prototype">
<property name="pmService" ref="ProjectManagerService" />
<property name="cmService" ref="ContractManagerService" />
<property name="pcService" ref="ProjectCustomerService" />
</bean>
</beans>
ApplicationContext-Service.xml
<?xml version="1.0" encoding="GBK"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- 定义业务逻辑组件 -->
<bean id="projectTemplate" abstract="true" lazy-init="true">
<property name="projectDao" ref="projectDao" />
<property name="landmarkDao" ref="landmarkDao" />
<property name="taskDao" ref="taskDao" />
<property name="userDao" ref="userDao" />
<property name="roleDao" ref="roleDao" />
<property name="taskuserrelationDao" ref="taskuserrelationDao" />
<property name="projectuserrelationDao" ref="projectuserrelationDao" />
</bean>
<bean id="projectManagerService" class="com.kds.service.impl.ProjectManagerService" parent="projectTemplate" />
<bean id="projectCustomerService" class="com.kds.service.impl.ProjectCustomerService" parent="projectTemplate"/>
<bean id="contractTemplate" abstract="true" lazy-init="true">
<property name="userDao" ref="userDao"/>
<property name="contractDao" ref="contractDao"/>
<property name="contracttypeDao" ref="contracttypeDao" />
<property name="productDao" ref="productDao" />
</bean>
<bean id="contractManagerService" class="com.kds.service.impl.ContractManagerService" parent="contractTemplate" />
</beans>
ApplicationContext-Daos.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- 配置DAO组件模板 -->
<bean id="daoTemplate" abstract="true" lazy-init="true">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="projectDao" class="com.kds.dao.impl.ProjectDAO" parent="daoTemplate"/>
<bean id="landmarkDao" class="com.kds.dao.impl.LandmarkDAO" parent="daoTemplate"/>
<bean id="taskDao" class="com.kds.dao.impl.TaskDAO" parent="daoTemplate"/>
<bean id="userDao" class="com.kds.dao.impl.UserDAO" parent="daoTemplate"/>
<bean id="roleDao" class="com.kds.dao.impl.RoleDAO" parent="daoTemplate"/>
<bean id="taskuserrelationDao" class="com.kds.dao.impl.TaskuserrelationDAO" parent="daoTemplate"/>
<bean id="projectuserrelationDao" class="com.kds.dao.impl.ProjectuserrelationDAO" parent="daoTemplate"/>
<bean id="contractDao" class="com.kds.dao.impl.ContractDAO" parent="daoTemplate" />
<bean id="contracttypeDao" class="com.kds.dao.impl.ContracttypeDAO" parent="daoTemplate" />
<bean id="productDao" class="com.kds.dao.impl.ProductDAO" parent="daoTemplate"/>
</beans>
ContractManagerService
public User login(String email, String password) {
return userDao.login(email, password);
}
我cmService明明注入了,应该不是空值啊?