2 wkittt wkittt 于 2015.07.09 11:12 提问

求助,这是什么问题?jar包问题吗?

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'InterviewService' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4992)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5490)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
at org.springframework.orm.hibernate3.support.HibernateDaoSupport.checkDaoConfig(HibernateDaoSupport.java:118)
at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 26 more
2015-7-9 10:52:27 org.apache.catalina.core.StandardContext startInternal
严重: Error listenerStart

application.xml代码如下
<?xml version="1.0" encoding="UTF-8"?>
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-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
context:annotation-config/
class="org.apache.commons.dbcp.BasicDataSource">
value="com.mysql.jdbc.Driver">




<bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref bean="dataSource" />
    </property>
    <property name="mappingResources">
        <list>
            <value>entity/Interview.hbm.xml</value>
            <value>entity/Employee.hbm.xml</value>
            <value>entity/Reply.hbm.xml</value>
            <value>entity/Job.hbm.xml</value>
            <value>entity/News.hbm.xml</value>
            <value>entity/Admin.hbm.xml</value>
        </list>
    </property>
    <!--  -->
    <property name="hibernateProperties">
        <props>
         <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
         <prop key="hibernate.hbm2ddl.auto">update</prop>
         <prop key="hibernate.show_sql">false</prop>
         <prop key="hibernate.format_sql">false</prop>
         <prop key="hibernate.cache.use_second_level_cache">true</prop>
         <prop key="hibernate.cache.use_query_cache">false</prop>
         <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
     </props>
    </property>
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="txManager"/>
<bean id="interviewDAO" class="dao.Impl.InterviewDaoImpl">
    <property name="sessionFactory">
        <ref bean="sessionFactory" />
    </property>
</bean>

<bean id="employeeDAO" class="dao.Impl.EmployeeDaoImpl">
    <property name="sessionFactory">
        <ref bean="sessionFactory" />
    </property>
</bean>

<bean id="replyDAO" class="dao.Impl.ReplyDaoImpl">
    <property name="sessionFactory">
        <ref bean="sessionFactory" />
    </property>
</bean>

<bean id="adminDAO" class="dao.Impl.AdminDaoImpl" >
    <property name="sessionFactory">
        <ref bean="sessionFactory" />
    </property>
</bean>

<bean id="jobDAO" class="dao.Impl.JobDaoImpl">
    <property name="sessionFactory">
        <ref bean="sessionFactory" />
    </property>
</bean>

<bean id="newsDAO" class="dao.Impl.NewsDaoImpl">
    <property name="sessionFactory">
        <ref bean="sessionFactory" />
    </property>
</bean>


 <!-- service配置 -->
 <bean id="InterviewService" class="service.Impl.InterviewServiceImpl">
    <!-- <property name="interviewDAO" ref="interviewDAO"/> -->
 </bean>
 <bean id="EmployeeService" class="service.Impl.EmployeeServiceImpl">
 <!--   <property name="employeeDAO" ref="employeeDAO"/>-->
 </bean>
 <bean id="AdminService" class="service.Impl.AdminServiceImpl">
    <!-- <property name="adminDAO" ref="adminDAO"/> -->
 </bean>
 <bean id="JobService" class="service.Impl.JobServiceImpl">
    <!-- <property name="jobDAO" ref="jobDAO"/> -->
 </bean>
 <bean id="NewsService" class="service.Impl.NewsServiceImpl">
    <!-- <property name="newsDAO" ref="newsDAO"/> -->
 </bean>
    <bean id="ReplyService" class="service.Impl.ReplyServiceImpl">
    <!--<property name="replyDAO" ref="replyDAO"/>-->
 </bean>

        <!--Action方法的配置  -->
<bean id="EmployeeAction" class="action.EmployeeAction" scope="prototype"/>
<bean id="AdminAction" class="action.AdminAction" scope="prototype"/>
<bean id="InterviewAction" class="action.InterviewAction" scope="prototype"/>
<bean id="ReplyAction" class="action.ReplyAction" scope="prototype"/>
<bean id="JobAction" class="action.JobAction" scope="prototype"/>
</beans>

我觉得是包的问题,我把所有的包都换了一遍,结果还是报这个错误。也不知道是缺了哪个包,大家帮帮忙吧!

6个回答

haonanzhuchegmingzhi
haonanzhuchegmingzhi   2015.07.09 11:25

有个Spring集成hibernate的JAR包,具体你找下,那个在初始化的时候需要找到相关配置,你在网上搜搜吧

haonanzhuchegmingzhi
haonanzhuchegmingzhi   2015.07.09 11:26

有个Spring集成hibernate的JAR包,具体你找下,那个在初始化的时候需要找到相关配置,你在网上搜搜吧

wkittt
wkittt 你好,不行,还是报那个错
2 年多之前 回复
bulusli3
bulusli3   Ds   Rxr 2015.07.09 11:49

InterviewService这个bean初始化的时候报错了。这个类里面应该有个方法需要一个参数为'sessionFactory' or 'hibernateTemplate'。

bulusli3
bulusli3 回复wkittt:继承了hibernatedaosupport的类需要注入一个sessionFactory。 <bean id="InterviewService" class="service.Impl.InterviewServiceImpl"><property name="sessionFactory"> <ref bean="sessionFactory"/></property></bean>
2 年多之前 回复
wkittt
wkittt 这个方法是继承了hibernatedaosupport的,然后用@Transactional事务管理注解事务。
2 年多之前 回复
wkittt
wkittt   2015.07.09 12:10

package service.Impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Transactional;

import dao.InterviewDAO;

import entity.Interview;

import service.InterviewService;
@Transactional(readOnly=false)
public class InterviewServiceImpl extends HibernateDaoSupport implements
InterviewService {

@Resource InterviewDAO interviewDAO;

public void saveInterview(Interview interview) {
    this.interviewDAO.saveInterview(interview);
}

public void updateInterview(Interview interview) {
    this.interviewDAO.updateInterview(interview);
}

public void deleteInterview(Interview interview) {
    this.interviewDAO.deleteInterview(interview);
}

public Interview findInterviewById(int id) {
    return this.interviewDAO.findInterviewById(id);
}

public List<Interview> findById(int id) {
    return this.interviewDAO.findById(id);
}

}


这个是serviceimpl,发现好像它有时候会报其它service的错误,因为我还有几个service业务。用的都是@Transactional

yuke198907
yuke198907   2015.07.09 14:11

spring的配置不对,看看xml文件的配置

wkittt
wkittt 可以详细说一下吗?
2 年多之前 回复
frank_20080215
frank_20080215   2015.07.09 15:55

hibernate的jar包没有配置全而已

Csdn user default icon
上传中...
上传图片
插入图片