2016-09-22 144 views
0

试图弹簧支架应用,并得到404,我没能找出问题,在服务器控制台显示任何关于这个问题,下面的代码是404 - 基本弹簧安置失败并显示404错误

there were many posts for this problem, i checked them did modifications also, none worked 
could any body please give the solution to this.Thank you 

这是控制器

@RestController 
@RequestMapping("/service") 
public class SpringServiceController { 
    @RequestMapping(value = "/{name}", method = RequestMethod.GET) 
    public String getGreeting(@PathVariable String name) { 
     String result="Hello "+name; 
     System.out.println("in the controller"); 
     return result; 
    } 
} 

的web.xml

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 
    <display-name>springRest</display-name> 
    <welcome-file-list> 
     <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list> 

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

    <servlet-mapping> 
     <servlet-name>rest</servlet-name> 
     <url-pattern>/*</url-pattern> 
    </servlet-mapping> 

    <context-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/rest-servlet.xml</param-value> 
    </context-param> 

     <listener> 
      <listener-class> 
       org.springframework.web.context.ContextLoaderListener 
      </listener-class> 
     </listener> 


    <session-config> 
     <session-timeout>30</session-timeout> 
    </session-config> 
</web-app> 

这是休息-servlet.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" 
    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.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context.xsd"> 

    <mvc:annotation-driven /> 
    <context:component-scan base-package="com.org.vasu.springRest.controller.*" /> 




</beans> 
+0

你可以尝试添加了@ResponseBody方法getGreeting @ – user3470953

+0

user3470953,---感谢您回应没有变化,其同样的错误,下面是两行显示在服务器控制台org.springframework .web.servlet.PageNotFound noHandlerFound 警告:在名为'rest'的DispatcherServlet中找不到具有URI [/ springRest /]的HTTP请求的映射 – user1245524

+0

在映射中使用“/” / user3470953

回答

0
<context:component-scan base-package="com.org.vasu.springRest.controller" /> 
+0

谢谢它的工作 – user1245524