2016-03-21 4 views
2

Ich versuche, einfache Web-Service zu implementieren, der userId nimmt und zeigt einige Benutzer bewertet Info-Informationen auf HTML-Webseite.Spring MVC Web Service GET (Ruhe) Anruf: 404

Ich habe versucht, einige Frühjahr Annotation-basierte Web-Service mit Feder mvc

zu schreiben, wenn ich folgendes Programm auszuführen versuchte, bekam ich 404-Fehler.

http://localhost:8080/EdgeStore/execute/user1

Sein einfaches Programm, das ich geschrieben habe. Fehle ich etwas in diesem Programm?

<?xml version="1.0" encoding="UTF-8"?> 

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans  
     http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-4.2.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd"> 

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

     <mvc:annotation-driven/> 

    </beans> 

und Dispatcher ist

<?xml version="1.0" encoding="UTF-8"?> 
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_ID" 
    version="2.4"> 

    <display-name>EdgeStore</display-name> 
    <servlet> 
      <servlet-name>EdgeStore</servlet-name> 
    <servlet-class> 
      org.springframework.web.servlet.DispatcherServlet 
     </servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
    <servlet-name>EdgeStore</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 
</web-app> 

Und Controller ist

package EdgeStore; 

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.PathVariable; 
import org.springframework.web.bind.annotation.RequestBody; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.ResponseBody; 
import org.springframework.web.bind.annotation.ResponseStatus; 

@Controller 
@RequestMapping("/execute") 
    public class executeController { 

    @RequestMapping(value="/{userId}", method = RequestMethod.GET) 
    @ResponseBody 
    public UserProfile getUserProfile(@PathVariable("userId") String userId) { 
     UserProfile userProfile = new UserProfile(); 
     userProfile.setUserId(userId); 
     userProfile.setSegmentId("defaultSegement"); 
     return userProfile; 
    } 
} 
+0

Haben Sie versucht, '/' auf '/*' zu setzen? –

+0

danke Patrick, habe ich beide versucht "/ *" und "/EdgeStore"...Beide funktioniert nicht –

Antwort

0

Können Sie Ihren Disponenten in diesem Format ändern und versuchen:

<display-name>EdgeStore</display-name> 
    <servlet> 
      <servlet-name>EdgeStore</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
     <param-name>contextConfigLocation</param-name> 
// Give location for your config file. 
     <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
    <servlet-name>EdgeStore</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

Wenn dies nicht der Fall ist Arbeit, lass es mich wissen. Ich werde meine Antwort entfernen.

+0

Sorry" Wir sind Borg ", auch das funktioniert nicht –

+0

Können Sie Ihr Projekt ohne die wichtigen Daten packen und senden Sie es. Ich kann hier schneller auschecken, was das Problem ist. Lass es mich wissen. –

+0

https://drive.google.com/open?id=0B1mAaSOgT6y2WEFMa2lMRm41eWc –