Spring Boot
[Spring Boot] template might not exist or might not be accessible by any of the configured template resolvers 오류 해결
KEMON
2020. 11. 26. 02:22
728x90
Thymeleaf를 사용하고 Javascript로 Ajax 통신 중 다음과 같은 에러가 발생했다.
template might not exist or might not be accessible by any of the configured template resolvers ...
$.ajax({
method:'POST',
url:'/getLocationData',
dataType:'json',
success:function (data){
console.log("data:::"+data);
}
})
@Controller
public class LocationController {
@Autowired
private LocationService locationService;
@PostMapping("/getLocationData")
public HashMap<String, Object> getLocationData(){
return locationService.getLocationData();
}
}
원인 : @RestController가 아닌 @Controller를 이용해서 getLocationData()의 리턴값을 View값에 매칭하려고 해서 Template 매칭 오류가 발생
@Controller
public class LocationController {
@Autowired
private LocationService locationService;
@PostMapping("/getLocationData")
public @ResponseBody HashMap<String, Object> getLocationData(){
return locationService.getLocationData();
}
}
해결 방법 : @ResponseBody를 넣어준다
728x90