lundi 1 juin 2015

Spring MVC - Configure StringHttpMessageConverter for an @RequestMapping method which return string that interpreted as the logical view name

I'm trying make an @RequestMapping method which return a string(which is a path to a JSP file)

@RequestMapping(value="/home", method=RequestMethod.GET)
    public String home(){
        logger.info("home");
        return "blog/home";
    }

it worked well until when I defined mvc:annotation-driven (i need to set it for being able to use @ControllerAdvice) in the dispatcher-servlet.xml file. So that's a my dispatcher-servlet.xml file

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
    xmlns:xsi="http://ift.tt/ra1lAU"
    xmlns:mvc="http://ift.tt/1bHqwjR"    
    xsi:schemaLocation="http://ift.tt/GArMu6 
            http://ift.tt/1jdM0fG
            http://ift.tt/1bHqwjR
            http://ift.tt/1fmimld">

    <import resource="controllers.xml" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="supportedMediaTypes" value="text/*;charset=UTF-8" />
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

</beans>

The return of thehome()method interpreted as HTTP body. I'm getting this issue in my log

Written [redirect:/blog/home] as "text/html" using [org.springframework.http.converter.StringHttpMessageConverter@61f77969]

I don't know what i'm missing that this path "blog/home" does not interpret as view reference

Aucun commentaire:

Enregistrer un commentaire