jersey

Micvkey166

Grünschnabel
hallo...
Ich spiele gerade mit Jersey und Spring herum. Ist es möglich, dass man Jersey dann auch ein ModelAndView - Objekt zurück gibt? Kann man ein ViewResolver in der xml definieren?

Java:
@Component
@PerRequest
@Scope("prototype")
   @Path("/test")  
   public class Test {
@GET
 @Produces("text/html")
       public ModelAndView getIt() {
   	   return new ModelAndView("view");
       }
}

Ich bekomme folgende Fehlermeldung:

A message body writer for Java type, class org.springframework.web.servlet.ModelAndView, and MIME media type, text/html, was not found

Meine web.xml

HTML:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>Jersey Spring Web Application</servlet-name>
        <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
        
        
        <load-on-startup>1</load-on-startup>
        
    </servlet>
  
    <servlet-mapping>
        <servlet-name>Jersey Spring Web Application</servlet-name>
        <url-pattern>/webresources/*</url-pattern>
    </servlet-mapping> 
  
  
</web-app>

ApplicationContext.xml
HTML:
<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"
          xsi:schemaLocation="
   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
       <context:component-scan base-package="example.jersey.spring"/>
       
       
        <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>   
    
   </beans>
 
Zuletzt bearbeitet:
Zurück