日期:2014-05-20  浏览次数:20920 次

Spring配置application.xml中的bean出错,求拥抱求合体
图片无法上传,报错信息如下:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.hibernate.cfg.Configuration]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: net/sf/cglib/transform/ClassFilter
==========================================================================================================
我的application.xml配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans" default-autowire="byName">

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:StudentManageSystem/src/hibernate.cfg.xml"></property>
</bean>

<bean id="userDao" class="cn.jbit.accp.dao.impl.UserDaoImpl">

</bean>

<bean id="userService" class="cn.jbit.accp.service.impl.UserServiceImpl">

</bean>

<bean id="userAction" class="cn.jbit.accp.action.UserAction" scope="prototype">

</bean>
</beans>
==========================================================================================================
UserDao如下:
package cn.jbit.accp.dao;

import java.util.List;

import cn.jbit.accp.entity.UsersTable;
/**
 * 数据库操作接口
 * @author PANJIE
 *
 */
public interface UserDao {
public List<UsersTable> findUser(UsersTable user);
}
==========================================================================================================
UserDao的实现类如下:
package cn.jbit.accp.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.jbit.accp.dao.UserDao;
import cn.jbit.accp.entity.UsersTable;

public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

private SessionFactory sessionFactory;


@Override
public List<UsersTable> findUser(UsersTable user) {
// TODO Auto-generated method stub
return this.getHibernateTemplate().find("from UsersTable u where u.userName=? and u.userPwd=?",new Object[]{user.getUserName(),user.getUserPwd()});
}


}
怎么解决啊,网上搜索总是出差错



------解决方案--------------------
nested exception is java.lang.NoClassDefFoundError: net/sf/cglib/transform/ClassFilter
说是找不到这个类的定义,看看是不是缺少jar包
------解决方案--------------------
先配个dataSource
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
<property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:orcl" />
<property name="user" value="scott" />
<property name="password" value="tiger" />