ssh整合测试时出现org.springframework.beans.factory.BeanCreationException:
请帮忙找下出现的错误如何解决,谢谢各位了!
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'menuImpl': Injection of resource fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/log4j/Level
at
测试代码:
public class MenuImplTest
{
@Resource private static MenuDao menuDao;
@Test
public void testSearch()
{
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
menuDao = (MenuDao)ac.getBean("menuImpl");
List<Menu> list = menuDao.searchMenu("鸡");
for(Menu menu: list)
{
System.out.println("id = " + menu.getMenu_id() + " ,name = " + menu.getMenu_name() + " ,price = " + menu.getMenu_price());
}
}
}
<?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-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.zcb"></context:component-scan>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/shopping?useUnicode=true&characterEncoding=utf-8"></property>
<property name="user" value="root"></property>
<property name="password" value="442044"></property>
<!-- 初始化获取的连接数,取值应该在minPoolSize与maxPoolSize之间。Default:3 -->
<property name="initialPoolSize" value="1"></property>
<!-- 连接池中的保留的最小连接数 -->
<property name="minPoolSize" value="1"></property>
<!-- 连接池中的保留的最大连接数 -->
<property name="maxPoolSize" value="300"></property>
<!-- 最大空闲时间,60s内未使用则连接被丢弃。若为零则永不丢弃。Default:0 -->
<property name="maxIdleTime" value="60"></property>
<!-- 当连接池中的连接耗尽的时候c3p0一次同时获取的连接数Default:3 -->
<property name="acquireIncrement" value="5"></property>
<!-- 每60s检查所有连接池中的空闲连接。Default:0 -->
<property name="idleConnectionTestPeriod" value="60"></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="mappingResources">
<list>
<!-- <value>com/zcb/bean/Menu.hbm.xml</value>-->
<!-- 如果不对尝试改为src/com/zcb/bean/..xml -->
<value>com/zcb/bean/Info.hbm.xml</value>
<value>com/zcb/bean/Menu.hbm.xml</value>
<value>com/zcb/bean/Message.hbm.xml</value>
<value>com/zcb/bean/Orders.hbm.xml</value>
<value>com/zcb/bean/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQL5Dialect
</prop>
</props>
</property>
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="txManager"/>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.zcb.bean">
<class name="Menu" table="tb_menu">
<id name="menu_id" type="integer" >
<generator class="native"/>
</id>
<property name="menu_name"/>
<property name="menu_content"/>
<property name="menu_price"/>
</class>
</hibernate-mapping>
@Service("menuImpl")
public class MenuImpl extends DaoImpl implements MenuDao {
@SuppressWarnings("unchecked")
@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
public List<Menu> searchMenu(String name) {
String hql = "from Menu as mm where mm.menu_name like '%"+name+"%'";
return super.sessionFactory.getCurrentSession().createQuery(hql).list();
}
@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
public Menu findByName(String name) {
String hql = "from Menu as mm where mm.menu_name='"+name+"'";
return (Menu)super.sessionFactory.getCurrentSession().createQuery(hql).uniqueResult();
}
}