Problem with rest controller in Spring

0

I configured Spring 4 to work without xml.

I created a simple @RestController , like this:

@RestController
public class JogadorRest {

    @RequestMapping("/ola/{jogador}")
    public Jogador message(@PathVariable String jogador) {

        Jogador j = new Jogador();
        j.setNome(jogador);

        return j;
    }

}

But when I test in Postman ( link ), I get HTML instead of json:

<html>
    <head>
        <title>Error</title>
    </head>
    <body>/RestTestJogador/WEB-INF/view/ola/Liorr.jsp</body>
</html>

Why does this happen?

Will it be the way I set up spring? My configuration looks like this:

@Configuration
@ComponentScan("br.com.testejogador.default")
@PropertySource(value = { "classpath:application.properties" })
public class AppConfig {

    @Autowired
    private Environment env;

    @Bean
    public ViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix("/WEB-INF/view/");
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    }

}
    
asked by anonymous 28.08.2015 / 16:17

1 answer

0

You need to say, in RequestMapping, that your method wants to return for example a JSON or an XML. Since you have not defined anything, it is using the convention to look up a JSP based on the address you entered.

Alberto

    
13.09.2015 / 20:20