0
I set Spring 4 to work without xml.
I created a @RestController
simple, 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 testing on Postman (http://localhost:8080/Resttestplayer/ola/Lior), I get an HTML instead of json:
<html>
<head>
<title>Error</title>
</head>
<body>/RestTestJogador/WEB-INF/view/ola/Liorr.jsp</body>
</html>
Why does that happen?
Is it 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;
}
}
See if this answer helps you: How to return a list as JSON using Spring MVC (@Restcontroller)?. It’s from another question of yours.
– Bruno César