日期:2014-05-17  浏览次数:20707 次

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 = Hi