Spring JSON Response von Controller

Zack

cookies vader
Hi,

ich versuche mittels des Controllers einen JSON String zu responsen. Nach einigem google bin ich auf folgende Lösung gekommen:

Controller:
Java:
	@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
XML:
<?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 http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/context 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:
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,

Zack
 
Zuletzt bearbeitet von einem Moderator:
Hat sich erledigt, im Springforum konnte mir geholfen werden. Mir fehlte die org.codehaus.jackson lib.
 
Zurück