Hibernate 创建名为';sitaTrackerController';:自动连线依赖项的注入失败;

Hibernate 创建名为';sitaTrackerController';:自动连线依赖项的注入失败;,hibernate,spring-mvc,Hibernate,Spring Mvc,我在使用@Autowired注释时遇到bean创建异常。 我在下面附上了我的代码。 加载SitaTracker-servlet.xml文件时遇到错误,该文件扫描并无法从控制器类自动连接服务类。为了更清晰,还附上了痕迹。如果需要,我还将上传服务和Dao类 我甚至尝试在Stacktrace中检查此异常,并尝试了所有可能的方法,但无法找到解决方案。 非常感谢您的帮助 2015-06-09 17:09:32,021 ERROR [org.springframework.web.context.Conte

我在使用@Autowired注释时遇到bean创建异常。 我在下面附上了我的代码。 加载SitaTracker-servlet.xml文件时遇到错误,该文件扫描并无法从控制器类自动连接服务类。为了更清晰,还附上了痕迹。如果需要,我还将上传服务和Dao类 我甚至尝试在Stacktrace中检查此异常,并尝试了所有可能的方法,但无法找到解决方案。 非常感谢您的帮助

2015-06-09 17:09:32,021 ERROR [org.springframework.web.context.ContextLoader] - <Context initialization failed>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sitaTrackerController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.sita.service.AddIncidentService com.sita.controller.SitaTrackerController.addIncidentService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'addIncidentServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.sita.dao.AddIncidentDao com.sita.service.AddIncidentServiceImpl.addIncidentDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'addIncidentImplDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.sita.dao.AddIncidentImplDao.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/SitaTracker-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javassist/util/proxy/MethodFilter
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.sita.service.AddIncidentService com.sita.controller.SitaTrackerController.addIncidentService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'addIncidentServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.sita.dao.AddIncidentDao com.sita.service.AddIncidentServiceImpl.addIncidentDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'addIncidentImplDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.sita.dao.AddIncidentImplDao.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/SitaTracker-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javassist/util/proxy/MethodFilter
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:517)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
... 28 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'addIncidentServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.sita.dao.AddIncidentDao com.sita.service.AddIncidentServiceImpl.addIncidentDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'addIncidentImplDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.sita.dao.AddIncidentImplDao.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/SitaTracker-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javassist/util/proxy/MethodFilter
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidateJun 9, 2015 5:09:32 PM org.apache.catalina.core.StandardContext listenerStart
`

`

`


感谢所有帮助找到解决方案的人

我已经添加了javasistjar,在它之后我成功地运行了我的项目。
所有文件都正确编码,因此这些文件中没有错误。

感谢所有帮助找到解决方案的人

我已经添加了javasistjar,在它之后我成功地运行了我的项目。
所有文件都正确编码,因此这些文件中没有错误。

向我们显示AddIncidentService类及其相关类(例如,如果使用接口类)。我编辑了我的问题,并添加了service和serviceimpl类。感谢您的支持。我认为您并没有按照您给出的代码片段在xml中给出AddIncidentService和AddIncidentDao的bean定义。请检查一下。我正在使用注释,因此没有提供任何XML条目。如果您发现任何其他原因,请还原。您是否确实读取了堆栈跟踪
java.lang.NoClassDefFoundError:javassist/util/proxy/MethodFilter
是对错误的一种公开。您缺少javassist依赖项。另一个注意事项是,dao是错误的,在使用Spring管理事务时,永远不要使用
openSession
beginTransaction
。改为使用
getCurrentSession
,并删除事务的启动和提交。向我们显示AddIncidentService类及其相关类(例如,如果它使用接口类)。我已编辑了我的问题,并添加了service和serviceimpl类。感谢您的支持。我认为您并没有按照您给出的代码片段在xml中给出AddIncidentService和AddIncidentDao的bean定义。请检查一下。我正在使用注释,因此没有提供任何XML条目。如果您发现任何其他原因,请还原。您是否确实读取了堆栈跟踪
java.lang.NoClassDefFoundError:javassist/util/proxy/MethodFilter
是对错误的一种公开。您缺少javassist依赖项。另一个注意事项是,dao是错误的,在使用Spring管理事务时,永远不要使用
openSession
beginTransaction
。改为使用
getCurrentSession
,并删除事务的启动和提交。向我们显示AddIncidentService类及其相关类(例如,如果它使用接口类)。我已编辑了我的问题,并添加了service和serviceimpl类。感谢您的支持。我认为您并没有按照您给出的代码片段在xml中给出AddIncidentService和AddIncidentDao的bean定义。请检查一下。我正在使用注释,因此没有提供任何XML条目。如果您发现任何其他原因,请还原。您是否确实读取了堆栈跟踪
java.lang.NoClassDefFoundError:javassist/util/proxy/MethodFilter
是对错误的一种公开。您缺少javassist依赖项。另一个注意事项是,dao是错误的,在使用Spring管理事务时,永远不要使用
openSession
beginTransaction
。改用
getCurrentSession
,并删除事务的启动和提交。
    package com.sita.controller;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.ui.ModelMap;
    import org.springframework.validation.BindingResult;
    import org.springframework.web.bind.annotation.ModelAttribute;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.servlet.ModelAndView;

    import com.sita.entity.AddIncident;    
    import com.sita.service.AddIncidentService;    

    @Controller    
    public class SitaTrackerController {

    @Autowired
    private AddIncidentService addIncidentService;


    @RequestMapping(value="/welcome", method = RequestMethod.GET)
    public ModelAndView checkLoginDetails(){

        ModelAndView mav = new ModelAndView("SuccessLogin");
        System.out.println("Testing");
        return mav;

    }

    @RequestMapping(value="/newIncident", method = RequestMethod.GET)
    public ModelAndView addIncidentView(){

        ModelAndView mav = new ModelAndView("AddIncident");
        System.out.println("Testing 2");
        return mav; 

    }

    @RequestMapping(value="/addIncident", method = RequestMethod.POST)
    public ModelAndView addNewIncident(@ModelAttribute("addIncident") AddIncident addIncident , Model model){//, BindingResult result, Model model){
        System.out.println("Testing 4");
        model.addAttribute("addIncident", new AddIncident() );
        addIncidentService.insertNewIncident(addIncident);
        ModelAndView mav = new ModelAndView("SuccessLogin");

        System.out.println("Testing 3");
        return mav; 

    }
}


<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
    http://www.springframework.org/schema/mvc     
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/beans     
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-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/cache 
    http://www.springframework.org/schema/cache/spring-cache.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<mvc:annotation-driven />
<context:annotation-config/> 
<context:property-placeholder location="/resource/properties/database.properties"/>
<!-- <context:component-scan base-package="com.sita.controller" /> -->
<!-- <context:component-scan base-package="com.sita.service" /> -->
<context:component-scan base-package="com.sita.*" />



<!-- <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
    > <property name="prefix"> <value>/WEB-INF/jsp/</value> </property> <property 
    name="suffix"> <value>.jsp</value> </property> </bean> -->


<bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass">
        <value>
            org.springframework.web.servlet.view.tiles2.TilesView
        </value>
    </property>
</bean>
<bean id="tilesConfigurer"
    class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/tiles.xml</value>
        </list>
    </property>
</bean>

<mvc:resources mapping="/resource/*" location="/resource/" />

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">  
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
</bean> 

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />

    <property name="packagesToScan">
        <list>
            <value>com.sita</value>
        </list>
    </property>

    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>  
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
</bean>
 <bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory" />
 </bean>
<bean id="addIncidentDao" class="com.sita.dao.AddIncidentDao" />  
<bean id="addIncidentService" class="com.sita.service.AddIncidentService"/>  

</beans>

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>SitaTracker</display-name>
<welcome-file-list>
    <welcome-file>Login.jsp</welcome-file>
</welcome-file-list>
<servlet>
  <servlet-name>SitaTracker</servlet-name>
  <servlet-class>
     org.springframework.web.servlet.DispatcherServlet
  </servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>
    <servlet-mapping>
      <servlet-name>SitaTracker</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/SitaTracker-servlet.xml   </param-value>
</context-param>
<context-param>
    <param-name>log4j-config-location</param-name>
    <param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<listener>
   <listener-class>
      org.springframework.web.context.ContextLoaderListener
   </listener-class>
  </listener>
</web-app>
    package com.sita.service;

import com.sita.entity.AddIncident;

public interface AddIncidentService {

public void insertNewIncident(AddIncident addIncident);

}
package com.sita.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sita.dao.AddIncidentDao;
import com.sita.entity.AddIncident;

@Service
public class AddIncidentServiceImpl implements AddIncidentService{

@Autowired
private AddIncidentDao addIncidentDao;

@Transactional
public void insertNewIncident(AddIncident addIncident) {
    addIncidentDao.insertNewIncident(addIncident);

}

}
package com.sita.dao;
import com.sita.entity.AddIncident;
public interface AddIncidentDao {
    public void insertNewIncident(AddIncident addIncident);
}
    package com.sita.dao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.sita.entity.AddIncident;

@Repository
public class AddIncidentImplDao implements AddIncidentDao{

@Autowired
private SessionFactory sessionFactory;

public void insertNewIncident(AddIncident addIncident) {
    Session session = sessionFactory.openSession();
    Transaction trans = session.beginTransaction();
    session.saveOrUpdate(addIncident);
    trans.commit();
}
}