首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

,帮小弟我检查一上配置哪里配错了

2012-10-20 
各位大哥,帮我检查一下配置哪里配错了自己做ssh框架,报了下面的错,在网上找了很多资料,但还是没有解决,各

各位大哥,帮我检查一下配置哪里配错了
自己做ssh框架,报了下面的错,在网上找了很多资料,但还是没有解决,各位大哥,帮忙看下
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

下面是我的配置文件,第一个applicationContext.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&amp;characterEncoding=utf-8</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>123</value>
</property>
</bean>

<!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<!-- 格式化输出sql语句 -->
  <prop key="hibernate.format_sql">true</prop>
  <prop key="hibernate.generate_statistics">true</prop>
</props>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/ourcompany/dao/pojo</value>
</list>
</property>
</bean>

<!-- 配置transactionFactory -->
<bean id="transactionFactory" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!-- 配置事务代理 -->
<bean id="transactionproxy" lazy-init="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionFactory" />
<property name="transactionAttributes">
<props>
<prop key="set*">PROPAGATION_REQUIRED,-DataAccessException</prop>
<prop key="get*">PROPAGATION_REQUIRED,-DataAccessException</prop>
<prop key="save*">PROPAGATION_REQUIRED,-DataAccessException</prop>
<prop key="validateUser*">PROPAGATION_REQUIRED,-DataAccessException</prop>
<prop key="remove*">PROPAGATION_REQUIRED,-DataAccessException</prop>
<prop key="delete*">PROPAGATION_REQUIRED,-DataAccessException</prop>
</props>
</property>
</bean>

</beans>
-----------------------------------------------------------
第二个applicationContext-action.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">


<bean id="userAction" name="/userAction" class="com.ourcompany.action.UserAction">
<property name="userBLL">
<ref bean="userBLL"/>
</property>
</bean>
</beans>
---------------------------------------------------
第三个applicationContext-common.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<!-- 配置baseDAO -->
<bean id="baseDAO" class="com.ourcompany.common.BaseDAO">
<property name="sf">
<ref bean="sessionFactory"/>
</property>
</bean>
</beans>
----------------------------------------------
第四个applicationContext-dao.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="userDAO" class="com.ourcompany.dao.UserDAOImpl">
<property name="sf">
<ref bean="sessionFactory"/>
</property>
</bean>
</beans>
----------------------------------------------
第五个applicationContext-services.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="userBLL" class="com.ourcompany.service.UserBLL">
<property name="userDAO">
<ref bean="userDAO"/>
</property>
</bean>

<bean id="userBLLProxy" parent="transactionproxy">
<property name="target">
<ref local="userBLL"/>
</property>
</bean>
</beans>
-----------------------------------------------------
java代码 action类
public class UserAction extends DispatchAction{

private UserBLL userBLL;

/**
* @description 登录
* @createTime Sep 24, 2012
* @lastUpdateTime Sep 24, 2012
* @see
*/
public ActionForward loginMethod(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
if(userBLL.validateUser((UserForm)form)){
return mapping.findForward("success");
}else{
return mapping.findForward("loginfail");
}
}

public void setUserBLL(UserBLL userBLL) {
this.userBLL = userBLL;
}

java代码 业务层
public class UserBLL {

private UserDAOImpl userDAO;

public boolean validateUser(UserForm userForm) {

try {
return userDAO.validateUser(userForm);
} catch (Exception e) {
e.printStackTrace();
}
return false;
}

public void setUserDAO(UserDAOImpl userDAO) {
this.userDAO = userDAO;
}
}

java代码 数据访问层
public interface UserDAO {
public boolean validateUser(UserForm userForm) throws Exception;


}


public class UserDAOImpl extends BaseDAO implements UserDAO{

public boolean validateUser(UserForm userForm) throws Exception {
Session session = getSession();
Query query = session.createQuery("from User where uname=? and upass=?");
query.setParameter(0, userForm.getUname());
query.setParameter(1, userForm.getUpass());
List list = query.list();
if(null != list && list.size() > 0){
return true;
}
return false;
}
}

java代码:获得session 就是这儿报错
public class BaseDAO {
private SessionFactory sf;

private Session session;


public void setSf(SessionFactory sf) {
this.sf = sf;
}


public Session getSession() {
return sf.getCurrentSession();//就是这儿报错
}
}

请各位大哥帮忙看下


[解决办法]
<value>classpath:/com/ourcompany/dao/pojo</value>这里不要写classpath:直接<value>com/ourcompany/dao/pojo</value>
,private SessionFactory sf;不用提供setter,getter方法,你都配置了。

热点排行
Bad Request.