请求只能根据请求生成具有不可接受的特征的响应"接受"邮递员的标题

时间:2016-01-14 09:44:42

标签: spring hibernate maven spring-mvc

在我的服务应用程序中,我希望通过传递特定的emailID来获取列表。我在邮递员http://localhost:8081/Services/sample/kala@gmail.com中使用了以下路径,但我得到例外说法

  

此请求标识的资源只能根据请求生成具有不可接受的特征的响应"接受"头

下面的

是我的代码

spring.xml

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

    <context:component-scan base-package="com.service.controller" />
    <mvc:annotation-driven />

    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
        <property name="url"
            value="jdbc:sqlserver://localhost;database=sample" />
        <property name="username" value="sa" />
        <property name="password" value="paa" />
    </bean>


    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
            <list>
                <value>com.service.model.Details</value>
                 <value>com.service.model.MasterSpeed</value>
                  <value>com.service.model.CandidateDetails</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>

                <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            </props>
        </property>
    </bean>


    <bean id="txManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <bean id="persistenceExceptionTranslationPostProcessor"
        class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

    <bean id="dataDao" class="com.service.dao.DataDaoImpl"></bean>
    <bean id="dataServices" class="com.service.services.DataServicesImpl"></bean>
</beans>

的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>sampleapp</groupId>
    <artifactId>sampleapp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <spring.version>4.0.5.RELEASE</spring.version>
        <hibernate.version>4.3.5.Final</hibernate.version>
        <log4j.version>1.2.17</log4j.version>
        <jdk.version>1.8</jdk.version>
        <context.path>sampleapp</context.path>
    </properties>




    <build>
        <plugins>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <update>true</update>
                    <url>http://localhost:8081/manager/text</url>
                    <server>Tomcat</server>
                    <path>/sampleapp</path>
                </configuration>
            </plugin>

        </plugins>

        <finalName>sampleapp-File</finalName>

    </build>


    <dependencies>

        <dependency>
            <groupId>com.thetransactioncompany</groupId>
            <artifactId>cors-filter</artifactId>
            <version>2.1</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>sqljdbc4</artifactId>
            <version>4.0</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.10</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

    </dependencies>


</project>

Controller.java

    @Controller
    @RequestMapping("/addEntity")
   public class RestController {
             /* Getting List of objects in Json format in Spring Restful Services */  
             @RequestMapping(value = "/{email}", method = RequestMethod.GET)  
             public @ResponseBody  List getCandidateDetailsbyId(@PathVariable("email") String email) {  


              List candDetails = null;  
              try {  
                  candDetails = dataServices.getDetailbyId(email);  

              } catch (Exception e) {  
               e.printStackTrace();  
              }  

              return candDetails;  
             }  }

请在这个问题上指导我。感谢您的帮助和建议。

2 个答案:

答案 0 :(得分:0)

POM 中配置此jackson依赖项:

<properties>
 ...
 <jackson.version>2.6.3</jackson.version>
 ...
</properties>

然后

<dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>${jackson.version}</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>${jackson.version}</version>
    </dependency>

答案 1 :(得分:0)

有关类似问题,请参阅this answer。它还有一个以电子邮件地址结尾的网址。 .com最终导致了内容协商的问题。