Я разработал серверную программу, используя весенний mvc. Мне нужно использовать jackson для выходных данных. Я добавил в servlet-context.xml. , но ответ сервера имеет HTTP-статус ошибки 406 Ресурс, идентифицированный этим запросом, способен генерировать ответы с характеристиками, неприемлемыми в соответствии с заголовками запроса «принять». Почему я не могу ответить на HTTP с помощью jackson на сервере? И где принимается заголовок в весеннем проекте с использованием eclipse?Почему я не могу ответить на http с помощью jackson весной mvc?
Это мой сервлет-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
\t xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
\t xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
\t xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
\t <!-- DispatcherServlet Context: defines this servlet's request-processing
\t \t infrastructure -->
\t <!-- Enables the Spring MVC @Controller programming model -->
\t <annotation-driven />
\t <!-- Handles HTTP GET requests for /resources/** by efficiently serving
\t \t up static resources in the ${webappRoot}/resources directory -->
\t <resources mapping="/resources/**" location="/resources/" />
\t <!-- Resolves views selected for rendering by @Controllers to .jsp resources
\t \t in the /WEB-INF/views directory -->
\t <beans:bean
\t \t class="org.springframework.web.servlet.view.InternalResourceViewResolver">
\t \t <beans:property name="prefix" value="/WEB-INF/views/" />
\t \t <beans:property name="suffix" value=".jsp" />
\t </beans:bean>
\t <beans:bean
\t \t class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
\t \t <beans:property name="favorPathExtension" value="true" />
\t \t <beans:property name="ignoreAcceptHeader" value="true" />
\t \t <beans:property name="mediaTypes">
\t \t \t <beans:map>
\t \t \t \t <beans:entry key="json" value="application/json" />
\t \t \t \t <beans:entry key="html" value="text/html" />
\t \t \t </beans:map>
\t \t </beans:property>
\t </beans:bean>
\t <context:component-scan base-package="kr.ac.jbnu.jinggumdari" />
\t <beans:bean
\t \t class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
\t <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
\t \t destroy-method="close">
\t \t <beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
\t \t <beans:property name="url"
\t \t \t value="jdbc:mysql://localhost:3306/jinggumdari" />
\t \t <beans:property name="username" value="root" />
\t \t <beans:property name="password" value="mysql1234" />
\t </beans:bean>
\t <!-- Hibernate 4 SessionFactory Bean definition -->
\t <beans:bean id="hibernate4AnnotatedSessionFactory"
\t \t class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
\t \t <beans:property name="dataSource" ref="dataSource" />
\t \t <beans:property name="annotatedClasses">
\t \t \t <beans:list>
\t \t \t \t <beans:value>kr.ac.jbnu.jinggumdari.model.Member</beans:value>
\t \t \t </beans:list>
\t \t </beans:property>
\t \t <beans:property name="hibernateProperties">
\t \t \t <beans:props>
\t \t \t \t <beans:prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect
\t \t \t \t </beans:prop>
\t \t \t \t <beans:prop key="hibernate.show_sql">true</beans:prop>
\t \t \t </beans:props>
\t \t </beans:property>
\t </beans:bean>
\t <beans:bean id="memberDAO" class="kr.ac.jbnu.jinggumdari.DAO.MemberDAOImpl">
\t \t <beans:property name="sessionFactory"
\t \t \t ref="hibernate4AnnotatedSessionFactory" />
\t </beans:bean>
\t <beans:bean id="memberService"
\t \t class="kr.ac.jbnu.jinggumdari.serviceImplementation.MemberManageServiceImpl">
\t \t <beans:property name="memberDAO" ref="memberDAO"></beans:property>
\t </beans:bean>
\t <beans:bean id="reviewDAO" class="kr.ac.jbnu.jinggumdari.DAO.ReviewDAOImpl">
\t \t <beans:property name="sessionFactory"
\t \t \t ref="hibernate4AnnotatedSessionFactory" />
\t </beans:bean>
\t <beans:bean id="reviewService"
\t \t class="kr.ac.jbnu.jinggumdari.serviceImplementation.ReviewManageServiceImpl">
\t \t <beans:property name="reviewDAO" ref="reviewDAO"></beans:property>
\t </beans:bean>
\t <tx:annotation-driven transaction-manager="transactionManager" />
\t <beans:bean id="transactionManager"
\t \t class="org.springframework.orm.hibernate4.HibernateTransactionManager">
\t \t <beans:property name="sessionFactory"
\t \t \t ref="hibernate4AnnotatedSessionFactory" />
\t </beans:bean>
</beans:beans>
Это мой pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
\t xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
\t <modelVersion>4.0.0</modelVersion>
\t <groupId>com.jbnu</groupId>
\t <artifactId>jinggumdari</artifactId>
\t <name>server</name>
\t <packaging>war</packaging>
\t <version>1.0.0-BUILD-SNAPSHOT</version>
\t <properties>
\t \t <java-version>1.6</java-version>
\t \t <org.springframework-version>4.1.5.RELEASE</org.springframework-version>
\t \t <org.aspectj-version>1.8.5</org.aspectj-version>
\t \t <org.slf4j-version>1.6.6</org.slf4j-version>
\t \t <hibernate.version>4.3.9.Final</hibernate.version>
\t \t <jackson.version>1.9.13</jackson.version>
\t </properties>
\t <dependencies>
\t \t <!-- Spring -->
\t \t <dependency>
\t \t \t <groupId>org.springframework</groupId>
\t \t \t <artifactId>spring-context</artifactId>
\t \t \t <version>${org.springframework-version}</version>
\t \t \t <exclusions>
\t \t \t \t <!-- Exclude Commons Logging in favor of SLF4j -->
\t \t \t \t <exclusion>
\t \t \t \t \t <groupId>commons-logging</groupId>
\t \t \t \t \t <artifactId>commons-logging</artifactId>
\t \t \t \t </exclusion>
\t \t \t </exclusions>
\t \t </dependency>
\t \t <dependency>
\t \t \t <groupId>org.springframework</groupId>
\t \t \t <artifactId>spring-webmvc</artifactId>
\t \t \t <version>${org.springframework-version}</version>
\t \t </dependency>
\t \t <dependency>
\t \t \t <groupId>org.springframework</groupId>
\t \t \t <artifactId>spring-core</artifactId>
\t \t \t <version>${org.springframework-version}</version>
\t \t </dependency>
\t \t <dependency>
\t \t \t <groupId>org.springframework</groupId>
\t \t \t <artifactId>spring-beans</artifactId>
\t \t \t <version>${org.springframework-version}</version>
\t \t </dependency>
\t \t <dependency>
\t \t \t <groupId>org.springframework</groupId>
\t \t \t <artifactId>spring-tx</artifactId>
\t \t \t <version>${org.springframework-version}</version>
\t \t </dependency>
\t \t <dependency>
\t \t \t <groupId>org.springframework</groupId>
\t \t \t <artifactId>spring-orm</artifactId>
\t \t \t <version>${org.springframework-version}</version>
\t \t </dependency>
\t \t <!-- AspectJ -->
\t \t <dependency>
\t \t \t <groupId>org.aspectj</groupId>
\t \t \t <artifactId>aspectjrt</artifactId>
\t \t \t <version>${org.aspectj-version}</version>
\t \t </dependency>
\t \t <dependency>
\t \t \t <groupId>org.aspectj</groupId>
\t \t \t <artifactId>aspectjweaver</artifactId>
\t \t \t <version>${org.aspectj-version}</version>
\t \t </dependency>
\t \t <!-- Logging -->
\t \t <dependency>
\t \t \t <groupId>org.slf4j</groupId>
\t \t \t <artifactId>slf4j-api</artifactId>
\t \t \t <version>${org.slf4j-version}</version>
\t \t </dependency>
\t \t <dependency>
\t \t \t <groupId>org.slf4j</groupId>
\t \t \t <artifactId>jcl-over-slf4j</artifactId>
\t \t \t <version>${org.slf4j-version}</version>
\t \t \t <scope>runtime</scope>
\t \t </dependency>
\t \t <dependency>
\t \t \t <groupId>org.slf4j</groupId>
\t \t \t <artifactId>slf4j-log4j12</artifactId>
\t \t \t <version>${org.slf4j-version}</version>
\t \t \t <scope>runtime</scope>
\t \t </dependency>
\t \t <dependency>
\t \t \t <groupId>log4j</groupId>
\t \t \t <artifactId>log4j</artifactId>
\t \t \t <version>1.2.15</version>
\t \t \t <exclusions>
\t \t \t \t <exclusion>
\t \t \t \t \t <groupId>javax.mail</groupId>
\t \t \t \t \t <artifactId>mail</artifactId>
\t \t \t \t </exclusion>
\t \t \t \t <exclusion>
\t \t \t \t \t <groupId>javax.jms</groupId>
\t \t \t \t \t <artifactId>jms</artifactId>
\t \t \t \t </exclusion>
\t \t \t \t <exclusion>
\t \t \t \t \t <groupId>com.sun.jdmk</groupId>
\t \t \t \t \t <artifactId>jmxtools</artifactId>
\t \t \t \t </exclusion>
\t \t \t \t <exclusion>
\t \t \t \t \t <groupId>com.sun.jmx</groupId>
\t \t \t \t \t <artifactId>jmxri</artifactId>
\t \t \t \t </exclusion>
\t \t \t </exclusions>
\t \t \t <scope>runtime</scope>
\t \t </dependency>
\t \t <!-- @Inject -->
\t \t <dependency>
\t \t \t <groupId>javax.inject</groupId>
\t \t \t <artifactId>javax.inject</artifactId>
\t \t \t <version>1</version>
\t \t </dependency>
\t \t <!-- Servlet -->
\t \t <dependency>
\t \t \t <groupId>javax.servlet</groupId>
\t \t \t <artifactId>servlet-api</artifactId>
\t \t \t <version>2.5</version>
\t \t \t <scope>provided</scope>
\t \t </dependency>
\t \t <dependency>
\t \t \t <groupId>javax.servlet.jsp</groupId>
\t \t \t <artifactId>jsp-api</artifactId>
\t \t \t <version>2.1</version>
\t \t \t <scope>provided</scope>
\t \t </dependency>
\t \t <dependency>
\t \t \t <groupId>javax.servlet</groupId>
\t \t \t <artifactId>jstl</artifactId>
\t \t \t <version>1.2</version>
\t \t </dependency>
\t \t <!-- Test -->
\t \t <dependency>
\t \t \t <groupId>junit</groupId>
\t \t \t <artifactId>junit</artifactId>
\t \t \t <version>4.7</version>
\t \t \t <scope>test</scope>
\t \t </dependency>
\t \t <!-- Hibernate -->
\t \t <dependency>
\t \t \t <groupId>org.hibernate</groupId>
\t \t \t <artifactId>hibernate-core</artifactId>
\t \t \t <version>${hibernate.version}</version>
\t \t </dependency>
\t \t <dependency>
\t \t \t <groupId>org.hibernate</groupId>
\t \t \t <artifactId>hibernate-entitymanager</artifactId>
\t \t \t <version>${hibernate.version}</version>
\t \t </dependency>
\t \t <!-- JDBC -->
\t \t <dependency>
\t \t \t <groupId>mysql</groupId>
\t \t \t <artifactId>mysql-connector-java</artifactId>
\t \t \t <version>5.1.30</version>
\t \t </dependency>
\t \t <!-- javax.persistence -->
\t \t <dependency>
\t \t \t <groupId>javax.persistence</groupId>
\t \t \t <artifactId>persistence-api</artifactId>
\t \t \t <version>1.0.2</version>
\t \t </dependency>
\t \t <!-- apache DBCP -->
\t \t <dependency>
\t \t \t <groupId>commons-dbcp</groupId>
\t \t \t <artifactId>commons-dbcp</artifactId>
\t \t \t <version>1.4</version>
\t \t </dependency>
\t \t <!-- JSON -->
\t \t <dependency>
\t \t \t <groupId>org.codehaus.jackson</groupId>
\t \t \t <artifactId>jackson-mapper-asl</artifactId>
\t \t \t <version>${jackson.version}</version>
\t \t </dependency>
\t \t <dependency>
\t \t \t <groupId>org.codehaus.jackson</groupId>
\t \t \t <artifactId>jackson-core-asl</artifactId>
\t \t \t <version>${jackson.version}</version>
\t \t </dependency>
\t </dependencies>
\t <build>
\t \t <plugins>
\t \t \t <plugin>
\t \t \t \t <artifactId>maven-eclipse-plugin</artifactId>
\t \t \t \t <version>2.9</version>
\t \t \t \t <configuration>
\t \t \t \t \t <additionalProjectnatures>
\t \t \t \t \t \t <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
\t \t \t \t \t </additionalProjectnatures>
\t \t \t \t \t <additionalBuildcommands>
\t \t \t \t \t \t <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
\t \t \t \t \t </additionalBuildcommands>
\t \t \t \t \t <downloadSources>true</downloadSources>
\t \t \t \t \t <downloadJavadocs>true</downloadJavadocs>
\t \t \t \t </configuration>
\t \t \t </plugin>
\t \t \t <plugin>
\t \t \t \t <groupId>org.apache.maven.plugins</groupId>
\t \t \t \t <artifactId>maven-compiler-plugin</artifactId>
\t \t \t \t <version>2.5.1</version>
\t \t \t \t <configuration>
\t \t \t \t \t <source>1.6</source>
\t \t \t \t \t <target>1.6</target>
\t \t \t \t \t <compilerArgument>-Xlint:all</compilerArgument>
\t \t \t \t \t <showWarnings>true</showWarnings>
\t \t \t \t \t <showDeprecation>true</showDeprecation>
\t \t \t \t </configuration>
\t \t \t </plugin>
\t \t \t <plugin>
\t \t \t \t <groupId>org.codehaus.mojo</groupId>
\t \t \t \t <artifactId>exec-maven-plugin</artifactId>
\t \t \t \t <version>1.2.1</version>
\t \t \t \t <configuration>
\t \t \t \t \t <mainClass>org.test.int1.Main</mainClass>
\t \t \t \t </configuration>
\t \t \t </plugin>
\t \t </plugins>
\t </build>
</project>
Это мой проект исследователь
Post контроллер ... Первое, что использовать Джексон 2 как Spring 4.x прекращена поддержка Джексон 1. –
Также разместите свой код вызова. Это то, что устанавливает заголовок accept. –