2015-06-10 45 views
0

我在使用@Autowired注释时面临bean创建异常。 我已在下面附上我的代码。 我在加载SitaTracker-servlet.xml文件时遇到了错误,该文件扫描并无法从我的Controller类自动装载服务类。为了更加清晰,还附加了跟踪。如果需要,我还会上传服务和Dao类 我甚至试图在Stacktrace中检查这个异常,并尝试了所有可能性,但无法找到解决方案。 任何帮助,不胜感激。创建名为'sitaTrackerController'的bean时出错:注入自动装配的依赖关系失败;

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 

严重:异常发送上下文初始化事件监听器类org.springframework.web.context.ContextLoaderListener的实例

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(); 
} 
} 
+0

向我们展示AddIncidentService类和与其相关的类(例如,如果它使用它,则为接口类)。 – Aeseir

+0

我编辑了我的问题并添加了service和serviceimpl类。感谢您的支持。 –

+0

我认为你没有给你的xml中的AddIncidentService和AddIncidentDao的bean定义,因为你已经给出了代码片段。请检查一次。 – ssm

回答

0

谢谢大家谁在寻找解决方案帮助。

我添加了javasist jar之后成功运行我的项目。 所有的文件编码都是正确的,因此这些文件没有错误。

相关问题