当前位置: 代码迷 >> Java Web开发 >> sessionFactory的有关问题
  详细解决方案

sessionFactory的有关问题

热度:823   发布时间:2013-02-25 21:18:26.0
sessionFactory的问题
在applicationContext.xml中报No setter found for property 'sessionFactory' in class 'com.test.dao.impl.UserLoginDaoImpl'错
applicationContext.xml代码
XML code
<?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:p="http://www.springframework.org/schema/p"    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>        <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"></property>        <property name="username" value="scott"></property>        <property name="password" value="tiger"></property>        <property name="maxActive" value="100"></property>        <property name="maxIdle" value="30"></property>        <property name="maxWait" value="500"></property>        <property name="defaultAutoCommit" value="true"></property>    </bean>        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">        <property name="dataSource" ref="dataSource"></property>        <property name="hibernateProperties">            <props>                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>                <prop key="hibernate.show_sql">true</prop>            </props>        </property>        <property name="mappingResources">            <list>                <value>com/test/domain/UserLogin.hbm.xml</value>            </list>        </property>    </bean>        <bean id="userLoginDao" class="com.test.dao.impl.UserLoginDaoImpl">        <property name="sessionFactory">//此行报错No setter found for property 'sessionFactory' in class 'com.test.dao.impl.UserLoginDaoImpl'            <ref bean="sessionFactory"/>        </property>    </bean>        <bean id="userLoginService" class="com.test.service.impl.UserLoginServiceImpl">        <property name="userLoginDao" ref="userLoginDao"/>//No setter found for property 'userLoginDao' in class 'com.test.service.impl.UserLoginServiceImpl'    </bean>        <bean id="registerAction" class="com.test.action.RegisterAction">        <property name="userLoginService" ref="userLoginService"></property>//No setter found for property 'userLoginService' in class 'com.test.action.RegisterAction'    </bean></beans>

UserLoginDaoImpl.java
Java code
package com.test.dao.impl;import org.hibernate.Query;import org.hibernate.Session;import com.test.dao.UserLoginDao;import com.test.domain.UserLogin;import com.test.myutil.HibernateUtil;public class UserLoginDaoImpl implements UserLoginDao {    public UserLogin getUserByName(String username) {        Session s = null;        try{            s = HibernateUtil.getSession();            String hql = "from UserLogin as userlogin where userlogin.username=:name";            Query query = s.createQuery(hql);            query.setString("name",username);                        UserLogin user = (UserLogin)query.uniqueResult();            return user;        }finally{            if(s!=null)                s.close();        }    }    public void saveUser(UserLogin user) {        HibernateUtil.add(user);    }}
  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!
 
  • 最近登录:Mon Jul 16 10:52:33 CST 2018
  • 最近登录:Mon Jul 16 10:52:33 CST 2018
  • 最近登录:Mon Jul 16 10:52:33 CST 2018
  • 最近登录:Mon Jul 16 10:52:33 CST 2018
  • 最近登录:Mon Jul 16 10:52:33 CST 2018