2013-04-22 120 views
1

我有一個彈簧web應用程序,我需要運行json服務。嵌套異常是java.lang.ClassNotFoundException:org.springframework.web.servlet.view.json.JsonView

下面是我的程序的調度器 - 小服務程序。

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> 

    <!-- SPECIFIC CONFIGURATIONS --> 
    <import resource="springConfigurations/common-config.xml"/> 
    <import resource="springConfigurations/mvc-config.xml"/> 

    <!-- COMMON CONFIGURATIONS --> 
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /> 
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> 
    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" /> 

    <bean name="viewResolver" class="org.springframework.web.servlet.view.XmlViewResolver"> 
     <property name="location"> 
      <value>/WEB-INF/views.xml</value> 
     </property> 
     <property name="order"> 
      <value>1</value> 
     </property> 
    </bean> 

</beans> 

而這是views.xml代碼。

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"> 

    <bean name="jsonView" class="org.springframework.web.servlet.view.json.JsonView"/> 

</beans> 

我得到了我的問題說頭控制檯下面的錯誤。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'viewResolver' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.web.servlet.view.json.JsonView] for bean with name 'jsonView' defined in ServletContext resource [/WEB-INF/views.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.web.servlet.view.json.JsonView 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) 
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:652) 
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:600) 
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:666) 
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:519) 
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:460) 
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) 
    at javax.servlet.GenericServlet.init(GenericServlet.java:212) 
    at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:421) 
    at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:245) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55) 
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:694) 
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:193) 
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:913) 
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:584) 
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:341) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55) 
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:164) 
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:161) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55) 
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:92) 
    at org.eclipse.jetty.server.Server.doStart(Server.java:232) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55) 
    at com.jkcs.touchpos.server.jetty.JettyServer.start(JettyServer.java:19) 
    at com.jkcs.touchpos.server.jetty.ServerRunner.<init>(ServerRunner.java:12) 
    at com.jkcs.touchpos.server.jetty.JettyStart.startServer(JettyStart.java:22) 
    at com.jkcs.touchpos.application.start.TouchPosApplication.main(TouchPosApplication.java:13) 
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.web.servlet.view.json.JsonView] for bean with name 'jsonView' defined in ServletContext resource [/WEB-INF/views.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.web.servlet.view.json.JsonView 
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1266) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:581) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1335) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:901) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) 
    at org.springframework.web.servlet.view.XmlViewResolver.initFactory(XmlViewResolver.java:143) 
    at org.springframework.web.servlet.view.XmlViewResolver.afterPropertiesSet(XmlViewResolver.java:91) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483) 
    ... 35 more 
Caused by: java.lang.ClassNotFoundException: org.springframework.web.servlet.view.json.JsonView 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247) 
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:316) 
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:269) 
    at org.springframework.util.ClassUtils.forName(ClassUtils.java:260) 
    at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:416) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1287) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1258) 
    ... 45 more 
2013-04-22 09:44:09.028:INFO::Started [email protected]:9157 

我添加了所有必需的JAR文件,但仍出現錯誤。請幫助我解決這個問題!

回答

0

你沒有所有必需的罐子。請轉至this maven page,下載JAR或使用pom依賴項。當您編譯並運行您的應用程序時,將jar添加到您的類路徑中

+0

我已經添加了這些jar文件! – 2013-04-22 05:46:13

+0

添加他們在哪裏以及如何?如果您正在獲取'ClassNotFoundException',則肯定不會在應用程序啓動器中找到它們。 – 2013-04-22 13:18:29

相關問題