我试图用jQuery库使用$.ajax()方法和Json作为dataType进行AJAX调用,问题来了,当我试图将其应用到我的应用程序在springmvc 2.5,我根本找不到一个很好的教程如何应用到Spring mvc 2.5,但3.0
欢呼exception
javax.servlet。ServletException: servlet .init()为servlet分派器抛出异常org.apache.catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase.java: 462)org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java: 100)org.apache.catalina.valves.AccessLogValve.invoke (AccessLogValve.java: 563)org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java: 399)org.apache.coyote.http11.Http11Processor.process (Http11Processor.java: 317)org.apache.coyote.http11.Http11Protocol Http11ConnectionHandler.process美元(Http11Protocol.java: 204)org.apache.coyote.http11.Http11Protocol Http11ConnectionHandler.process美元(Http11Protocol.java: 182)org.apache.tomcat.util.net.JIoEndpoint SocketProcessor.run美元(JIoEndpoint.java: 311)java.util.concurrent.ThreadPoolExecutor Worker.runTask美元(ThreadPoolExecutor.java: 886)java.util.concurrent.ThreadPoolExecutor Worker.run美元(ThreadPoolExecutor.java: 908)java.lang.Thread.run (Thread.java: 662)
根源org.springframework.beans.factory。BeanCreationException:在ServletContext资源[/WEB-INF/dispatcher-servlet.xml]中定义名为'viewResolver'的bean创建错误:初始化bean失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:在ServletContext资源[/WEB-INF/views.xml]中定义名为'jsonView'的bean创建错误:bean的实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException: Could not instantiate bean类。:构造函数抛出异常;嵌套异常是java.lang.NoClassDefFoundError: org/apache/commons/beanutils/ConvertUtilsBeanorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java: 480)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory 1.美元运行(AbstractAutowireCapableBeanFactory.java: 409)java.security.AccessController。doPrivileged(本地方法)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java: 380)org.springframework.beans.factory.support.AbstractBeanFactory 1.美元getobject (AbstractBeanFactory.java: 264)org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java: 222)org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java: 261)org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java: 185)org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java: 164)org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons (DefaultListableBeanFactory.java: 429)org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java: 728)org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java: 380)org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext (FrameworkServlet.java: 402)org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext (FrameworkServlet.java: 316)org.springframework.web.servlet.FrameworkServlet.initServletBean (FrameworkServlet.java: 282)org.springframework.web.servlet.HttpServletBean.init (HttpServletBean.java: 126)javax.servlet.GenericServlet.init (GenericServlet.java: 160)org.apache.catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase.java: 462)org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java: 100)org.apache.catalina.valves.AccessLogValve.invoke (AccessLogValve.java: 563)org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java: 399)org.apache.coyote.http11.Http11Processor.process (Http11Processor.java: 317)org.apache.coyote.http11.Http11Protocol Http11ConnectionHandler.process美元(Http11Protocol.java: 204)org.apache.coyote.http11.Http11Protocol Http11ConnectionHandler.process美元(Http11Protocol.java: 182)org.apache.tomcat.util.net.JIoEndpoint SocketProcessor.run美元(JIoEndpoint.java: 311)java.util.concurrent.ThreadPoolExecutor Worker.runTask美元(ThreadPoolExecutor.java: 886)java.util.concurrent.ThreadPoolExecutor Worker.run美元(ThreadPoolExecutor.java: 908)java.lang.Thread.run (Thread.java: 662)
根源org.springframework.beans.factory。BeanCreationException:在ServletContext资源[/WEB-INF/views.xml]中定义名为'jsonView'的bean创建错误:实例化bean失败;嵌套异常是org.springframework.beans.BeanInstantiationException: Could not instantiate bean类。:构造函数抛出异常;嵌套异常是java.lang.NoClassDefFoundError: org/apache/commons/beanutils/ConvertUtilsBeanorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean (AbstractAutowireCapableBeanFactory.java: 883)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance (AbstractAutowireCapableBeanFactory.java: 839)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java: 440)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory 1.美元运行(AbstractAutowireCapableBeanFactory.java: 409)java.security.AccessController。doPrivileged(本地方法)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java: 380)org.springframework.beans.factory.support.AbstractBeanFactory 1.美元getobject (AbstractBeanFactory.java: 264)org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java: 222)org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java: 261)org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java: 185)org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java: 164)org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons (DefaultListableBeanFactory.java: 429)org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java: 728)org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java: 380)org.springframework.web.servlet.view.XmlViewResolver.initFactory (XmlViewResolver.java: 138)org.springframework.web.servlet.view.XmlViewResolver.initApplicationContext (XmlViewResolver.java: 89)org.springframework.context.support.ApplicationObjectSupport.initApplicationContext (ApplicationObjectSupport.java: 119)org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext (WebApplicationObjectSupport.java: 69)org.springframework.context.support.ApplicationObjectSupport.setApplicationContext (ApplicationObjectSupport.java: 73)org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization (ApplicationContextAwareProcessor.java: 70)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization (AbstractAutowireCapableBeanFactory.java: 350)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.java: 1331)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java: 473)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory 1.美元运行(AbstractAutowireCapableBeanFactory.java: 409)java.security.AccessController。doPrivileged(本地方法)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java: 380)org.springframework.beans.factory.support.AbstractBeanFactory 1.美元getobject (AbstractBeanFactory.java: 264)org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java: 222)org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java: 261)org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java: 185)org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java: 164)org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons (DefaultListableBeanFactory.java: 429)org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java: 728)org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java: 380)org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext (FrameworkServlet.java: 402)org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext (FrameworkServlet.java: 316)org.springframework.web.servlet.FrameworkServlet.initServletBean (FrameworkServlet.java: 282)org.springframework.web.servlet.HttpServletBean.init (HttpServletBean.java: 126)javax.servlet.GenericServlet.init (GenericServlet.java: 160)org.apache.catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase.java: 462)org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java: 100)org.apache.catalina.valves.AccessLogValve.invoke (AccessLogValve.java: 563)org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java: 399)org.apache.coyote.http11.Http11Processor.process (Http11Processor.java: 317)org.apache.coyote.http11.Http11Protocol Http11ConnectionHandler.process美元(Http11Protocol.java: 204)org.apache.coyote.http11.Http11Protocol Http11ConnectionHandler.process美元(Http11Protocol.java: 182)org.apache.tomcat.util.net.JIoEndpoint SocketProcessor.run美元(JIoEndpoint.java: 311)java.util.concurrent.ThreadPoolExecutor Worker.runTask美元(ThreadPoolExecutor.java: 886)java.util.concurrent.ThreadPoolExecutor Worker.run美元(ThreadPoolExecutor.java: 908)java.lang.Thread.run (Thread.java: 662)
根源org.springframework.beans。BeanInstantiationException:无法实例化bean类。:构造函数抛出异常;嵌套异常是java.lang.NoClassDefFoundError: org/apache/commons/beanutils/ConvertUtilsBeanorg.springframework.beans.BeanUtils.instantiateClass (BeanUtils.java: 115)org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate (SimpleInstantiationStrategy.java: 61)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean (AbstractAutowireCapableBeanFactory.java: 877)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance (AbstractAutowireCapableBeanFactory.java: 839)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java: 440)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory 1.美元运行(AbstractAutowireCapableBeanFactory.java: 409)java.security.AccessController。doPrivileged(本地方法)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java: 380)org.springframework.beans.factory.support.AbstractBeanFactory 1.美元getobject (AbstractBeanFactory.java: 264)org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java: 222)org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java: 261)org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java: 185)org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java: 164)org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons (DefaultListableBeanFactory.java: 429)org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java: 728)org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java: 380)org.springframework.web.servlet.view.XmlViewResolver.initFactory (XmlViewResolver.java: 138)org.springframework.web.servlet.view.XmlViewResolver.initApplicationContext (XmlViewResolver.java: 89)org.springframework.context.support.ApplicationObjectSupport.initApplicationContext (ApplicationObjectSupport.java: 119)org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext (WebApplicationObjectSupport.java: 69)org.springframework.context.support.ApplicationObjectSupport.setApplicationContext (ApplicationObjectSupport.java: 73)org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization (ApplicationContextAwareProcessor.java: 70)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization (AbstractAutowireCapableBeanFactory.java: 350)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.java: 1331)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java: 473)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory 1.美元运行(AbstractAutowireCapableBeanFactory.java: 409)java.security.AccessController。doPrivileged(本地方法)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java: 380)org.springframework.beans.factory.support.AbstractBeanFactory 1.美元getobject (AbstractBeanFactory.java: 264)org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java: 222)org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java: 261)org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java: 185)org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java: 164)org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons (DefaultListableBeanFactory.java: 429)org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java: 728)org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java: 380)org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext (FrameworkServlet.java: 402)org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext (FrameworkServlet.java: 316)org.springframework.web.servlet.FrameworkServlet.initServletBean (FrameworkServlet.java: 282)org.springframework.web.servlet.HttpServletBean.init (HttpServletBean.java: 126)javax.servlet.GenericServlet.init (GenericServlet.java: 160)org.apache.catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase.java: 462)org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java: 100)org.apache.catalina.valves.AccessLogValve.invoke (AccessLogValve.java: 563)org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java: 399)org.apache.coyote.http11.Http11Processor.process (Http11Processor.java: 317)org.apache.coyote.http11.Http11Protocol Http11ConnectionHandler.process美元(Http11Protocol.java: 204)org.apache.coyote.http11.Http11Protocol Http11ConnectionHandler.process美元(Http11Protocol.java: 182)org.apache.tomcat.util.net.JIoEndpoint SocketProcessor.run美元(JIoEndpoint.java: 311)java.util.concurrent.ThreadPoolExecutor Worker.runTask美元(ThreadPoolExecutor.java: 886)java.util.concurrent.ThreadPoolExecutor Worker.run美元(ThreadPoolExecutor.java: 908)java.lang.Thread.run (Thread.java: 662)
根源. lang。NoClassDefFoundError: org/apache/commons/beanutils/ConvertUtilsBeanorg.springframework.web.servlet.view.json.filter.SimplePropertyFilter.setUpBeanUtils (SimplePropertyFilter.java: 31)org.springframework.web.servlet.view.json.filter.SimplePropertyFilter。(SimplePropertyFilter.java: 27)org.springframework.web.servlet.view.json.JsonView。(JsonView.java: 25)sun.reflect.NativeConstructorAccessorImpl。newInstance0(本地方法)sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java: 39)sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java: 27)java.lang.reflect.Constructor.newInstance (Constructor.java: 513)org.springframework.beans.BeanUtils.instantiateClass (BeanUtils.java: 100)org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate (SimpleInstantiationStrategy.java: 61)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean (AbstractAutowireCapableBeanFactory.java: 877)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance (AbstractAutowireCapableBeanFactory.java: 839)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java: 440)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory 1.美元运行(AbstractAutowireCapableBeanFactory.java: 409)java.security.AccessController。doPrivileged(本地方法)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java: 380)org.springframework.beans.factory.support.AbstractBeanFactory 1.美元getobject (AbstractBeanFactory.java: 264)org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java: 222)org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java: 261)org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java: 185)org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java: 164)org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons (DefaultListableBeanFactory.java: 429)org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java: 728)org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java: 380)org.springframework.web.servlet.view.XmlViewResolver.initFactory (XmlViewResolver.java: 138)org.springframework.web.servlet.view.XmlViewResolver.initApplicationContext (XmlViewResolver.java: 89)org.springframework.context.support.ApplicationObjectSupport.initApplicationContext (ApplicationObjectSupport.java: 119)org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext (WebApplicationObjectSupport.java: 69)org.springframework.context.support.ApplicationObjectSupport.setApplicationContext (ApplicationObjectSupport.java: 73)org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization (ApplicationContextAwareProcessor.java: 70)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization (AbstractAutowireCapableBeanFactory.java: 350)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.java: 1331)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java: 473)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory 1.美元运行(AbstractAutowireCapableBeanFactory.java: 409)java.security.AccessController。doPrivileged(本地方法)org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java: 380)org.springframework.beans.factory.support.AbstractBeanFactory 1.美元getobject (AbstractBeanFactory.java: 264)org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java: 222)org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java: 261)org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java: 185)org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java: 164)org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons (DefaultListableBeanFactory.java: 429)org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java: 728)org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java: 380)org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext (FrameworkServlet.java: 402)org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext (FrameworkServlet.java: 316)org.springframework.web.servlet.FrameworkServlet.initServletBean (FrameworkServlet.java: 282)org.springframework.web.servlet.HttpServletBean.init (HttpServletBean.java: 126)javax.servlet.GenericServlet.init (GenericServlet.java: 160)org.apache.catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase.java: 462)org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java: 100)org.apache.catalina.valves.AccessLogValve.invoke (AccessLogValve.java: 563)org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java: 399)org.apache.coyote.http11.Http11Processor.process (Http11Processor.java: 317)org.apache.coyote.http11.Http11Protocol Http11ConnectionHandler.process美元(Http11Protocol.java: 204)org.apache.coyote.http11.Http11Protocol Http11ConnectionHandler.process美元(Http11Protocol.java: 182)org.apache.tomcat.util.net.JIoEndpoint SocketProcessor.run美元(JIoEndpoint.java: 311)java.util.concurrent.ThreadPoolExecutor Worker.runTask美元(ThreadPoolExecutor.java: 886)java.util.concurrent.ThreadPoolExecutor Worker.run美元(ThreadPoolExecutor.java: 908)java.lang.Thread.run (Thread.java: 662)
你需要用restful url来注释你的控制器方法,并在控制器方法中添加一个@ResponseBody注释。
的例子:
@Controller
@RequestMapping(value = "/pets")
@ResponseBody
public Pet getPet(@PathVariable String petId, Model model) {
//..generate some Json
// Add Json to the Response
model.addAttribute("json", json);
}
然后在你的js中使用jquery对URL进行ajax调用
$.ajax({
type: 'POST',
url: "/pets",
data: data,
success: function(data){
alert(data.json); //alerts json object
},
dataType: 'json'
});