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

hibernate+sping 配置文件的有关问题(分不够再加)

2011-12-20 
hibernate+sping 配置文件的问题(分不够再加)在调试的时候,出现如下提示:org.springframework.beans.facto

hibernate+sping 配置文件的问题(分不够再加)
在调试的时候,出现如下提示:

org.springframework.beans.factory.BeanCreationException:   Error   creating   bean   with   name   'userService '   defined   in   ServletContext   resource   [/WEB-INF/applicationContext.xml]:  

Can 't   resolve   reference   to   bean   'userTarget '   while   setting   property   'target ';   nested   exception   is   org.springframework.beans.factory.BeanCreationException:   Error   creating   bean   with   name   'userTarget '   defined   in   ServletContext   resource   [/WEB-INF/applicationContext.xml]:  

Error   setting   property   values;   nested   exception   is   org.springframework.beans.NotWritablePropertyException:   Invalid   property   'iUser '   of   bean   class   [com.bookstore.spring.service.UserServiceImpl]:  

Bean   property   'iUser '   is   not   writable   or   has   an   invalid   setter   method:   Does   the   parameter   type   of   the   setter   match   the   return   type   of   the   getter?

------------------------------
applicationContext.xml
------------------------------------

    <!--   *****   USER   SERVICE   *****-->
    <bean   id= "userService "   class= "org.springframework.transaction.interceptor.TransactionProxyFactoryBean ">
        <property   name= "transactionManager ">
            <ref   local= "myTransactionManager "/>
        </property>
        <property   name= "target ">
            <ref   local= "userTarget "/>
        </property>
        <property   name= "transactionAttributes ">
            <props>
                <prop   key= "find* "> </prop>
                <prop   key= "save* "> </prop>
            </props>
        </property>
    </bean>
    <!--   *************************************************************************************   -->
    <!--   userTarget   primary   business   object   implementation   -->
    <bean   id= "userTarget "   class= "com.bookstore.spring.service.UserServiceImpl ">
        <property   name= "iUser ">
            <ref   local= "userDao "/>
        </property>
    </bean>
    <!--   DAO   object:   Hibernate   implementation   -->
    <bean   id= "userDao "   class= "com.bookstore.hibernate.dao.UserDao ">
        <property   name= "sessionFactory ">


            <ref   local= "mySessionFactory "/>
        </property>
    </bean>


--------------------------------
IUserService.java
--------------------------------
package   com.bookstore.spring.service;

import   com.bookstore.bo.*;
import   java.util.*;

public   interface   IUserService   {
//methoud
    public   boolean   validate(String   userName);
    public   void   addUser(User   user);
}
--------------------------------
UserServiceImpl.java
--------------------------------
package   com.bookstore.spring.service;
import   org.apache.log4j.BasicConfigurator;
import   org.apache.log4j.Logger;
import   org.springframework.context.ApplicationContext;
import   org.springframework.context.support.ClassPathXmlApplicationContext;
import   java.util.*;

import   net.sf.hibernate.Hibernate;
import   net.sf.hibernate.Criteria;
import   net.sf.hibernate.expression.*;
import   net.sf.hibernate.Query;
import   com.bookstore.hibernate.dao.*;
import   com.bookstore.bo.*;
import   com.sun.corba.se.impl.naming.pcosnaming.NameService;

public   class   UserServiceImpl   implements   IUserService   {
    private   Logger   log   =   Logger.getLogger(this.getClass());
    private   IUser   iUser;
    public   UserServiceImpl(){
    }
    public   boolean   validate(String   userName){
        return   iUser.validateUser(userName);
    }
    public   void   addUser(User   user){
        iUser.addUser(user);
    }
    public   IUser   getIUser(){
        return   iUser;
    }
    public   void   setIUser(IUser   iUser){
        this.iUser   =   iUser;
    }

}
--------------------------------
IUser.java
--------------------------------
package   com.bookstore.hibernate.dao;

import   com.bookstore.bo.*;
public   interface   IUser{
    public   boolean   validateUser(String   UserName);
    public   void   addUser(User   user);
}
--------------------------------
UserDao.java
--------------------------------
package   com.bookstore.hibernate.dao;
import   java.util.*;
import   java.util.ArrayList;
import   java.util.List;
import   com.bookstore.hibernate.dao.*;

import   net.sf.hibernate.HibernateException;
import   net.sf.hibernate.Query;
import   net.sf.hibernate.Hibernate;
import   net.sf.hibernate.Session;
import   net.sf.hibernate.Criteria;
import   net.sf.hibernate.expression.*;

import   org.apache.log4j.BasicConfigurator;
import   org.apache.log4j.Logger;
import   org.springframework.context.ApplicationContext;


import   org.springframework.context.support.ClassPathXmlApplicationContext;
import   org.springframework.orm.hibernate.HibernateCallback;
import   org.springframework.orm.hibernate.support.HibernateDaoSupport;
import   com.bookstore.bo.*;
public   class   UserDao   extends   HibernateDaoSupport   implements   IUser{

    public   UserDao(){
    }
    public   boolean   validateUser(String   UserName){
        return   true;
    }
    public   void   addUser(User   user){
        getHibernateTemplate().save(user);
        getHibernateTemplate().flush();
    }
}
---------------------------

--------------------------------
--------------------------------




[解决办法]
配置文件这么多问题,而且提示已经给的很明显
[解决办法]
没有set和get方法了

热点排行
Bad Request.