spring mvc中的异步支持

时间:2015-01-27 11:44:48

标签: spring-mvc asynchronous restful-url

我正在构建一个可以在spring mvc中支持异步功能的Web应用程序。

的web.xml

<?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/javaee" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    id="WebApp_ID" version="3.0">
  <display-name>TestRestful</display-name>
  <servlet>
    <servlet-name>restful</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    <async-supported>true</async-supported>
  </servlet>
  <servlet-mapping>
    <servlet-name>restful</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

宁静-servlet.xml中

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

        <!--  It scans a package and all of its subpackages, looking for classes that could be automatically registered 
              as beans(@Component, @Controller, @Repository and @Service) in the Spring container. -->
        <context:component-scan base-package="education.controller" />
        <!-- Maps request to controller and controller methods that are annotated with @RequestMapping -->
        <!-- useDefaultSuffixPattern="false"
            Set whether to register paths using the default suffix pattern as well: i.e. whether "/users" should be registered as "/users.*" too.
            Default is "true". Turn this convention off if you intend to interpret your @RequestMapping paths strictly.
            Note that paths which include a ".xxx" suffix already will not be transformed using the default suffix pattern in any case.
        -->
        <beans:bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"  
            p:order="1"
            p:useDefaultSuffixPattern="false"/>


        <task:annotation-driven/>
</beans:beans>

HelloRestController.java

@Controller
public class HelloRestController {

    @RequestMapping(value="/test",method=RequestMethod.GET)
    public @ResponseBody Callable<String> testmessage(){

        return new Callable<String>() {
            @Override
            public String call() throws Exception {

                return "hello rest";            
            }
        };

    }

    @RequestMapping(value="test1/{email}",method=RequestMethod.GET)
    public @ResponseBody String testemail(@PathVariable("email") String email){
        System.err.println("plain email method->"+email);

        return "test plain email";
    }
}

在调用test1 / {email}时,我收到了正确的回复。

但是,在调用test时,我收到了HTTP Status 406 ERROR CODE。

在调试期间也发现我的代码甚至没有调用方法。

请建议......

0 个答案:

没有答案