【问题标题】:Why happen Class 'net.sf.json.spring.web.servlet.view.JsonView' not found?为什么找不到类“net.sf.json.spring.web.servlet.view.JsonView”?
【发布时间】:2018-05-29 05:15:54
【问题描述】:

我做了以下设置来使用jsonView。

调度程序-serlvet.xml:

<?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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
        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-4.1.xsd">

<bean id="jsonView" class="net.sf.json.spring.web.servlet.view.JsonView"> 
            <property name="contentType" value="application/json;charset=UTF-8" /> 
        </bean> 
</beans>

pom.xml:

 <dependency>
    <groupId>net.sf.json-lib</groupId>
    <artifactId>json-lib</artifactId>
    <version>2.4</version>
    <classifier>jdk15</classifier>
</dependency>

但是dispatcher-sevlet.xml中出现如下错误:

Multiple annotations found at this line:
- Class 'net.sf.json.spring.web.servlet.view.JsonView' not found
- Class 'net.sf.json.spring.web.servlet.view.JsonView' not found [config set: rachelivf/web-
 context]

我不知道为什么会这样。初学者需要答案。请告诉我如何解决它。

【问题讨论】:

    标签: json spring maven spring-mvc servlets


    【解决方案1】:

    我已经解决了这个问题。

    我为 dispacther-servlet 编写的内容是旧的。

    代码已修改为(dispacther-serlvet.xml):

    <bean id="jsonView" class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
        <property name="contentType" value="application/json;charset=UTF-8"/>
    </bean>
    

    结果,错误消失了。

    【讨论】:

      猜你喜欢
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-24
      • 1970-01-01
      • 1970-01-01
      • 2014-09-27
      相关资源
      最近更新 更多