■ 참고
spring mvc 406에러 – Not Acceptable
http://knight76.tistory.com/entry/spring-mvc-406-%EC%97%90%EB%9F%AC-Not-Acceptable
Spring Boot Application: No converter found for return value of type
https://stackoverflow.com/questions/33832735/spring-boot-application-no-converter-found-for-return-value-of-type/33896080#33896080
■ pom.xml에 jackson lib추가
<dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.13</version> </dependency>
■ spring 설정파일에 annotation-driven 추가
<mvc:annotation-driven />
■ json으로 표현 못하는 Class를 json으로 만들때 발생 , 적당하게 map, array, list로 표현할 수 있도록 변환
■ 나의 경우는 위의 사항을 전부 지켰지만 오류가 해결 되지 않았다.
@Controller @RequestMapping("jsonsample") public class JsonSampleController { @RequestMapping( value = "sample.jsonf", method = RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE) @ResponseBody public List<SampleVO> listSample( @ModelAttribute Params params) throws Exception { List<SampleVO> sampleList = new ArrayList<SampleVO>(); SampleVO sampleVO = new SampleVO(); sampleVO.setId("id01"); sampleVO.setName("name01"); sampleList.add(sampleVO); return sampleList; } }
■ 위의 코드에서 produces=MediaType.APPLICATION_JSON_VALUE 부분을 제거해보았더니 다음과 같은 에러발생.
No converter found for return value of type: class java.util.ArrayList] with root cause
■ stackoverflow에서 해결책을 찾았는데 설정은 아래와 같다.
– pom.xml, jackson버전은 동일하게 맞춰야한다. 1.x이면 1.x로, 2.x면 2.x로 통일한다.
<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.4.3</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.4.3</version> </dependency>
– spring 설정파일
<mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframework.http.converter.StringHttpMessageConverter"/> <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/> </mvc:message-converters> </mvc:annotation-driven>
– Spring Controller
@Controller @RequestMapping("jsonsample") public class JsonSampleController { @RequestMapping( value = "sample.jsonf", method = RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE) @ResponseBody public List<SampleVO> listSample( @ModelAttribute Params params) throws Exception { List<SampleVO> sampleList = new ArrayList<SampleVO>(); SampleVO sampleVO = new SampleVO(); sampleVO.setId("id01"); sampleVO.setName("name01"); sampleList.add(sampleVO); return sampleList; } }
– 참고1. SampleVO
public class SampleVO { private String id; private String name; private int age; private int level; public int getLevel() { return level; } public void setLevel(int level) { this.level = level; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } }
– 참고2. angularjs client
<!DOCTYPE html> <html ng-app="myApp"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta charset="utf-8"> <head> <title></title> <script src="/js/angularjs/1.5.6/angular.js"></script> <script src='/js/jquery/jquery-1.11.0.min.js'></script> <script> var myApp = angular.module("myApp",[]); myApp.controller("myAppCtrl", function($scope,$http){ $scope.result = ""; $scope.start = function(event) { $http({ method : 'GET', cache : false, url : '/jsonsample/sample.jsonf' }) .success(function(response){ console.log(response); $scope.result = response; }); } }); </script> </head> <body ng-controller="myAppCtrl"> <h1> AngularJS Built-in Service $http<br/> </h1> <button ng-click="start()">$http</button> <hr/> my location <div>{{result}}</div> </body> </html>
- SpringBoot Port 변경 2022년 12월 27일
- jQuery checkbox 전체 선택/해제 예제 2022년 3월 15일
- Highcharts error #17 2019년 7월 10일
- Highchart TypeError: c.init is not a function 2019년 7월 10일
- Highchart 크기 조정 2019년 7월 8일
- Highcharts error #13 2019년 7월 8일
- Spring 트랜잭션 관리 2019년 6월 20일
- Spring RESTful 웹 서비스 사용하기 2019년 6월 19일
- Spring RESTful 웹 서비스 2019년 6월 19일
- Spring Scheduling Task 예제 2019년 6월 18일
- Grid Stack Two grids demo 예제 2019년 6월 12일
- 동적으로 추가/생성된 태그에 이벤트 추가 방법 2019년 6월 10일
- Highcharts update event 2019년 3월 26일
- spring mybatis mysql 연결 예제 2018년 5월 4일
- Spring Path Parameter 예제 2018년 2월 13일
- AngularJS $http, spring TEXT response 예제 2018년 1월 17일
- jdom2를 이용한 spring xml response(응답) 2017년 12월 5일
- jquery xml 요청, spring xml 리턴 2017년 12월 5일
- spring controller에서 get, post 동시 허용 방법 2017년 12월 5일
- mybatis, oracle procedure(오라클 커서)를 통한 데이터 조회 2017년 11월 6일
- HTTP 406 Not Acceptable in Spring, Jackson, Json 2017년 11월 6일
- jquery div show hide 예제 2016년 5월 25일
- jquery css 예제 2016년 5월 25일
- jquery selectbox 예제 2016년 5월 25일
- jquery json 예제 2016년 5월 25일
- jquery template 예제 1 2016년 5월 25일
- jquery datepicker 2016년 5월 9일
- ServletContextLister를 구현한 웹 애플리케이션 시작 시 작업 2016년 5월 2일
- jquery radiobox 2016년 4월 29일
- Web Application MessageResource 2016년 3월 8일
- org.mariadb.jdbc.internal.common.QueryException : No database selected 2016년 2월 19일
- jquery bgiframe 정리 2016년 2월 1일
- jquery each( $.each ) 2016년 1월 25일
- jquery spring – checkbox로 선택된 배열 주고 받기 2015년 8월 15일
- jquery spring ajax call 2015년 8월 15일
- spring json return 2015년 8월 15일
- spring exception – SimpleMappingExceptionResolver 2015년 8월 8일
- jQuery 동적 체크박스 제어 2015년 1월 27일
- 간단한 jquery chained selectbox 예제 2014년 12월 4일
- jquery ui tip 2014년 9월 2일