请高手帮忙,ssh集成开发实验,出现如下错误....
出现错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceDaoImpl': Injection of resource fields failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'userDaoImpl' must be of type [com.bookstore.daoImp.UserDaoImpl], but was actually of type [$Proxy12]
...
Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException:
Bean named 'userDaoImpl' must be of type [com.bookstore.daoImp.UserDaoImpl], but was actually of type [$Proxy12]
beans.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:context="http://www.springframework.org/schema/context"
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.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- 打开spring的注解功能 和扫描功能-->
<context:component-scan base-package="com.bookstore"/>
<!-- 数据源配置 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.gjt.mm.mysql.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/bookstore?useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
<property name="initialSize" value="1"/>
<property name="maxActive" value="500"/>
<property name="maxIdle" value="2"/>
<property name="minIdle" value="1"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="annotatedClasses">
<list>
<value>com.bookstore.bean.User</value>
<value>com.bookstore.bean.BookSort</value>
<value>com.bookstore.bean.Book</value>
<value>com.bookstore.bean.BookOrder</value>
<value>com.bookstore.bean.BookOrderItem</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=false
hibernate.format_sql=false
</value>
</property>
</bean>
<!-- 添加spring的事务管理处理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 开启spring事务管理功能,这里推荐注解方式 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
UserServiceDaoImpl.java如下:
package com.bookstore.serviceImpl;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import com.bookstore.bean.User;
import com.bookstore.daoImp.UserDaoImpl;
import com.bookstore.service.UserServiceDao;
@Component
public class UserServiceDaoImpl implements UserServiceDao {
@Resource
private UserDaoImpl userDaoImpl;
public UserDaoImpl getUserDaoImpl() {
return userDaoImpl;
}
public void setUserDaoImpl(UserDaoImpl userDaoImpl) {
this.userDaoImpl = userDaoImpl;
}
public void saveUser(User user) {
userDaoImpl.saveUser(user);
}
public boolean validateUser(String userName, String passsWord) {
return userDaoImpl.validateUser(userName, passsWord);
}
}
UserDaoImpl.java如下:
package com.bookstore.daoImp;
import javax.annotation.Resource;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.bookstore.bean.User;
import com.bookstore.dao.UserDao;
@Component
public class UserDaoImpl implements UserDao {
@Resource
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
@Transactional
public void saveUser(User user) {
sessionFactory.getCurrentSession().save(user);
}
public boolean validateUser(String userName, String passsWord) {
Query q=sessionFactory.getCurrentSession().createQuery("from User where userName=? and passWord=?");
q.setString(0, userName);
q.setString(1, passsWord);
User u=(User)q.uniqueResult();
if(u!=null)
{
//true表示用户存在 或者登陆成功
return true;
}
else
{
return false;
}
}
}