请帮忙找下出现的错误如何解决,谢谢各位了!
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());
}
}
}
applicationContext.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-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>