spring mvc project中的org.springframework.beans.factory.BeanCreationException

时间:2015-02-19 10:50:25

标签: java spring spring-mvc

1.我在春天很新,这个问题已被多次询问,但我仍然无法找出错误的东西。并且得到了这些例外。

这是我的控制台输出

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sidSearchController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.jlcindia.spring.mvc.SidValidator com.jlcindia.spring.mvc.SidSearchController.sidValidator; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.web.servlet.handeler.SimpleMappingExceptionResolver] for bean with name 'org.springframework.web.servlet.handeler.SimpleMappingExceptionResolver#0' defined in ServletContext resource [/WEB-INF/jlcindia-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.web.servlet.handeler.SimpleMappingExceptionResolver
    org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1055)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
    org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)
    org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:443)
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:459)
    org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:340)
    org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:307)
    org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
    javax.servlet.GenericServlet.init(GenericServlet.java:212)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    java.lang.Thread.run(Thread.java:619)

控制器类

@Controller
public class SidSearchController 
{

@Autowired
private SidValidator sidValidator;

@RequestMapping(value="/searchStudent",method=RequestMethod.POST)
@ExceptionHandler({StudentNotFoundException.class})

public String searchStudent(@ModelAttribute("sidSearchCommand")SidSearchCommand sidCommand,Errors errors,HttpServletRequest req,Model model){
    System.out.println("contact controller");
    sidValidator.validate(sidCommand, errors);
    if(errors.hasErrors()){
        return "sidsearch";
        }
      String sid=sidCommand.getSid();
        String results="";

       if(sid.equals("sim-123")||sid.equals("sim-999")) {

StudentTO sto=new StudentTO();
sto.setSid(sid);
sto.setBid("B-99");
sto.setSname("srinivas");
sto.setPhone("99999");
model.addAttribute("STO", sto);
req.setAttribute("STO",sto);
results="sidresults";

    }
    else
    {
req.setAttribute("sidSearchCommand",sidCommand);
throw new StudentNotFoundException(sid);
}return results;
}@RequestMapping(value="/sidsearch")
  protected String showSearchPage(Map model) throws ServletException{
      System.out.println("show search page");
      SidSearchCommand sidCommand=new SidSearchCommand();
      model.put("sidSearchCommand", sidCommand);
      return "sidsearch";
            }
  }

3.mvc-调度-servlet.xml中:

 <context:component-scan base-package="com.jlcindia.spring.mvc" />
   <bean id="sidValidator" class="com.jlcindia.spring.mvc.SidValidator"/>
  <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="viewClass" value="org.springframework.web.servlet.view.InternalResourceView"/> 
        <property name="prefix" value="/" />  
        <property name="suffix" value=".jsp" />  
    </bean>  

   <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename" value="messages"/>
   </bean>

   <bean class="org.springframework.web.servlet.handeler.SimpleMappingExceptionResolver">
        <property name="exceptionMappings">
        <props>
        <prop key="com.jlcindia.spring.mvc.StudentNotFoundException">sidsearch
        </prop>
       </props>
      </property>
  </bean>
  </beans>

1 个答案:

答案 0 :(得分:3)

你的mvc-dispatcher-servlet.xml中的

错误拼写了以下内容:org.springframework.web.servlet.handeler.SimpleMappingExceptionResolver

编写handeler而不是处理程序