404 - 基本弹簧休息失败并显示404错误

时间:2016-09-22 12:13:52

标签: rest

尝试一个弹簧休息应用程序并获得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>

这是rest-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>

1 个答案:

答案 0 :(得分:0)

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