ERLEDIGT
JA
JA
ANTWORTEN
1
1
ZUGRIFFE
890
890
EMPFEHLEN
-
Hi,
ich versuche mittels des Controllers einen JSON String zu responsen. Nach einigem google bin ich auf folgende Lösung gekommen:
Controller:
Code java:1 2 3 4 5 6 7 8 9 10 11 12
@SuppressWarnings({ "unchecked", "rawtypes" }) @RequestMapping(value = "/login/register/exuser", method = RequestMethod.POST) public Map existsUser(@RequestParam(value="name", required=true) String name){ Map response = new TreeMap(); int status = this.bc.existsUser(name); response.put("status", status); response.put("msg", this.msg.getMsg(status)); return response; }
servlet.xml
Code xml:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
<?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/mvc [url]http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd[/url] [url]http://www.springframework.org/schema/beans[/url] [url]http://www.springframework.org/schema/beans/spring-beans-3.0.xsd[/url] [url]http://www.springframework.org/schema/context[/url] http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> <!-- Enables the Spring MVC @Controller programming model --> <annotation-driven /> <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --> <resources mapping="/resources/**" location="/resources/" /> <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <beans:property name="prefix" value="/WEB-INF/jsp/" /> <beans:property name="suffix" value=".jsp" /> </beans:bean> <context:component-scan base-package="de.tudresden.mmt.kpmi.web" /> <!-- Transporting JSON - Data --> <beans:bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <beans:property name="mediaTypes"> <beans:map> <beans:entry key="json" value="application/json"/> </beans:map> </beans:property> <beans:property name="defaultViews"> <beans:list> <beans:bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"> <beans:property name="prefixJson" value="true"/> </beans:bean> </beans:list> </beans:property> </beans:bean> </beans:beans>
Wenn ich die Anwendung jetzt starte bekomme ich folgenden Fehler:
Code :1 2 3 4 5
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.view.ContentNegotiatingViewResolver#0' defined in ServletContext resource [/WEB-INF/spring-ws-servlet.xml]: Cannot create inner bean 'org.springframework.web.servlet.view.json.MappingJacksonJsonView#3b8b780f' of type [org.springframework.web.servlet.view.json.MappingJacksonJsonView] while setting bean property 'defaultViews' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.view.json.MappingJacksonJsonView#3b8b780f' defined in ServletContext resource [/WEB-INF/spring-ws-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.web.servlet.view.json.MappingJacksonJsonView]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/codehaus/jackson/map/ObjectMapper
Wo liegt das Problem?
Vielen Dank,
ZackUnd was lernen wir darauf? Es niemals versuchen! (Homer Jay Simpson)
127.0.0.1 Home! Sweet Home!
Ich würde mich über eine Bewertung meiner Beiträge freuen!
-
Hat sich erledigt, im Springforum konnte mir geholfen werden. Mir fehlte die org.codehaus.jackson lib.
Und was lernen wir darauf? Es niemals versuchen! (Homer Jay Simpson)
127.0.0.1 Home! Sweet Home!
Ich würde mich über eine Bewertung meiner Beiträge freuen!
Ähnliche Themen
-
Frage zu JSON. HTML-Konstrukt mit JSON übergeben
Von Jan-Frederik Stieler im Forum Javascript & AjaxAntworten: 2Letzter Beitrag: 16.04.11, 16:04 -
JQuery und Ajax (JSON Response)
Von messmar im Forum Javascript & AjaxAntworten: 14Letzter Beitrag: 19.08.10, 23:04 -
Verhalten von einem Spring-Controller bei Aspekten
Von ck2003 im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 12Letzter Beitrag: 08.06.09, 14:02 -
[Spring] ResourceMessages in Controller oder Beans?
Von Hardi82 im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 4Letzter Beitrag: 27.10.08, 08:49 -
Spring / DispatcherServlet: MVC - Controller
Von gtm im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 0Letzter Beitrag: 18.08.08, 18:05





Zitieren
Login





