-2

sorry my english.

i try to solve this error but i don“t know what could be

I'm new with spring and REST

i'm using:

*spring mvc 4.0.1 *NetBeans 8 *Hibernate *Tomcat 8 *Oracle *Json / Jackson REST *AngularJS

the ERROR is 406 error when i try to get in my controller a object list with Json, when i try to get a simple String the answer is 200 (OK)

i try to add this line >> <mvc:annotation-driven/> in my dispatcher-servlet but then return:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Invocation of init method failed; nested exception is org.springframework.http.InvalidMediaTypeException: Invalid mime type "String": does not contain '/' <<<

so, next the code without the previous line and with 406 ERROR:

Dispatcher-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
            <beans xmlns="http://www.springframework.org/schema/beans"
                   xmlns:context="http://www.springframework.org/schema/context"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:p="http://www.springframework.org/schema/p"
                   xmlns:aop="http://www.springframework.org/schema/aop"
                   xmlns:tx="http://www.springframework.org/schema/tx"
                   xmlns:mvc="http://www.springframework.org/schema/mvc"
                   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
                   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
                   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
                   http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

                <context:component-scan base-package="controller"/>

                <context:annotation-config />

                <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                  <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
                  <property name="prefix" value="/WEB-INF/jsp/"/>
                  <property name="suffix" value=".jsp"/>
                </bean>

                <bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
                    <property name="prefixJson" value="true"/>
                </bean>

PerfilesController.java

...

    @ResponseStatus(value=HttpStatus.OK)
    @RequestMapping(value= "perfiles.serv", method = RequestMethod.GET, headers="Accept=*/*", produces= {"application/xml", "application/json", "String"})    
    public @ResponseBody ResponseEntity<List<Perfiles>> getAllProfiles() {
        PerfilesService pService = new  PerfilesService();
            List<Perfiles> list = pService.getAllProfles();
            return new ResponseEntity<List<Perfiles>>(list, HttpStatus.OK);
    }

...

i call with angular JS

app.service

        svservicios.service('PerfilesService',['$http', function ($http) {

        function getPerfiles(pageNumber,size) {
            pageNumber = pageNumber > 0?pageNumber - 1:0;
            return $http({
              method: 'GET',
              headers: {
               'Content-Type': 'application/json','Accept': 'application/json, */*'
             },
                url: 'perfiles.serv?page='+pageNumber+'&size='+size
            });
        }
        return {
            getPerfiles: getPerfiles
        };
    }]);

the view:

<div class="edit-contenedor">

<div class = "btnAddPerfil">

    <md-button href="crearP.html" class = "col-md-12 md-raised">Agregar Perfil</md-button>
</div>

<div>
    <div ng-controller="AdminPerfilesController">
        <div ui-grid="gridOptions" class="grid-ap" ui-grid-pagination>
        </div>
    </div>
</div>

thanks

Fidel Toro
  • 11
  • 3

1 Answers1

0

I resolve with this in my dispatcher-servlet:

<bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"></bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
        <list>
            <ref bean="jacksonMessageConverter"/>
        </list>
    </property>
</bean>

thanks to spring mvc not returning json content - error 406

Fidel Toro
  • 11
  • 3