在春季休假中请求映射问题

时间:2018-10-19 11:20:06

标签: spring hibernate rest spring-boot dto

任何人都可以支持我,我正在使用STS尝试制作一个简单的Rest Web服务。 tomcat没有显示任何错误,但是我无法通过webservice保存数据 我在postman中使用此URL http://localhost:8080/auth/authenticateUser。postman显示错误

  

HTTP状态404 –不   基金会1   {font-family:Tahoma,Arial,sans-serif;颜色:白色;背景颜色:#525D76;字体大小:22px;}   h2   {font-family:Tahoma,Arial,sans-serif;颜色:白色;背景颜色:#525D76;字体大小:16像素;}   3小时   {font-family:Tahoma,Arial,sans-serif;颜色:白色;背景颜色:#525D76;字体大小:14px;}   身体   {font-family:Tahoma,Arial,sans-serif;颜色:黑色;背景颜色:白色;}   b   {font-family:Tahoma,Arial,sans-serif;颜色:白色;背景颜色:#525D76;} p   {font-family:Tahoma,Arial,sans-serif; background:white; color:black; font-size:12px;}   一个{color:black;} a.name {color:black;} .line   {height:1px; background-color:#525D76; border:none;}

HTTP   状态404 –找不到

类型状态   报告

消息   / auth / authenticateUser

描述来源   服务器找不到目标资源的当前表示形式   或不愿透露存在。

Apache Tomcat / 9.0.7

休息控制器代码为

package com.innovent.RBAuth.rest;

import java.awt.print.Printable;

import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.MediaType;

import com.RBAuth.DTO.UserDTO;
import com.google.gson.Gson;
import com.innovent.RBAuth.service.RBAuthService;

@RestController
@RequestMapping(value="/auth", method=RequestMethod.POST,
                consumes=MediaType.APPLICATION_FORM_URLENCODED_VALUE + ";charset=UTF-8",
                produces=MediaType.TEXT_PLAIN_VALUE + ";charset=UTF-8")
public class RBAuthResourceAPI {

    @Autowired
    RBAuthService service;

    @RequestMapping(value="/authenticateUser")
    public String authenticateUser(@RequestParam("email") String email, @RequestParam("name") String name) throws Exception {



        JSONObject referenceObject = new JSONObject();
        Gson gson = new Gson();


        // Here you have to call the service methods and authenticate the user accordingly
        UserDTO user = new UserDTO();

        service.saveUser(user);
        System.out.println(user);
        return gson.toJson(user);

    }


}

web.xml是

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                             http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         id="WebApp_ID" version="2.5"> -->
         <web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
          http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">


    <display-name>Event Managemet Application</display-name>



    <!--
        - Servlet that dispatches request to registered handlers (Controller implementations).
    -->
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <!--  registers Spring for soap service  -->
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    <!--  these are for JAX-WS  -->
    <servlet>
        <servlet-name>jaxws-servlet</servlet-name>
        <servlet-class>
            com.sun.xml.ws.transport.http.servlet.WSSpringServlet
        </servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>jaxws-servlet</servlet-name>
        <url-pattern>/auth</url-pattern>
    </servlet-mapping>

spring servlet.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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    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">

    <!-- to make annotations work -->
    <context:component-scan base-package="com.innovent" />
    <mvc:annotation-driven />
    <tx:annotation-driven />
    <tx:jta-transaction-manager  />

    <!-- Property files  -->
<!--     <context:property-placeholder location="/WEB-INF/,
                                            /WEB-INF/"/>
 -->

    <!-- Datasource -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName" value="org.postgresql.Driver" />
      <property name="url" value="jdbc:postgresql://localhost:5432/Events" />
      <property name="username" value="postgres" />
      <property name="password" value="sa4067673" />
   </bean>

    <!-- This produces a container-managed EntityManagerFactory; 
         rather than application-managed EntityManagerFactory as in case of LocalEntityManagerFactoryBean-->
    <bean id="entityManagerFactoryBean" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
      <property name="dataSource" ref="dataSource" />
      <!-- This makes /META-INF/persistence.xml is no longer necessary -->
      <property name="packagesToScan" value="ae.dubaipolice.model, ae.dubaipolice.common.model" />
      <!-- JpaVendorAdapter implementation for Hibernate EntityManager.
           Exposes Hibernate's persistence provider and EntityManager extension interface -->
      <property name="jpaVendorAdapter">
          <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
              <property name="generateDdl" value="true" />
              <property name="showSql" value="true" />
          </bean>
      </property>
      <property name="jpaProperties">
         <props>
            <prop key="hibernate.hbm2ddl.auto">validate</prop>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
         </props>
      </property>
    </bean>

   <!-- This transaction manager is appropriate for applications that use a single JPA EntityManagerFactory for transactional data access. 
        JTA (usually through JtaTransactionManager) is necessary for accessing multiple transactional resources within the same transaction. -->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
      <property name="entityManagerFactory" ref="entityManagerFactoryBean" />
      <property name="dataSource" ref="dataSource"></property>
    </bean>

    <!-- <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" /> -->

</beans>

0 个答案:

没有答案