2015-09-30 65 views
3

试图在我的控制器中使用post方法与java注释(版本4.2.1)和成功在我的本地tomcat,但是当我移动到亚马逊beantalk时,我得到跟随错误:不支持请求方法'POST'和亚马逊弹性beantalk

日志:

28-Sep-2015 10:34:11.339 WARNING [http-nio-8080-exec-10] org.springframework.web.servlet.PageNotFound.handleHttpRequestMethodNotSupported Request method 'POST' not supported 
28-Sep-2015 10:34:11.340 WARNING [http-nio-8080-exec-10] org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.logException Handler execution resulted in exception: Request method 'POST' not supported 
28-Sep-2015 10:34:11.994 WARNING [http-nio-8080-exec-1] org.springframework.web.servlet.PageNotFound.handleHttpRequestMethodNotSupported Request method 'POST' not supported 
28-Sep-2015 10:34:11.995 WARNING [http-nio-8080-exec-1] org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.logException Handler execution resulted in exception: Request method 'POST' not supported 
28-Sep-2015 10:34:15.915 WARNING [http-nio-8080-exec-9] org.springframework.web.servlet.PageNotFound.handleHttpRequestMethodNotSupported Request method 'POST' not supported 
28-Sep-2015 10:34:15.915 WARNING [http-nio-8080-exec-9] org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.logException Handler execution resulted in exception: Request method 'POST' not supported 
28-Sep-2015 10:34:16.938 WARNING [http-nio-8080-exec-5] org.springframework.web.servlet.PageNotFound.handleHttpRequestMethodNotSupported Request method 'POST' not supported 
28-Sep-2015 10:34:16.938 WARNING [http-nio-8080-exec-5] org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.logException Handler execution resulted in exception: **Request method 'POST' not supported** 
28-Sep-2015 10:34:17.660 WARNING [http-nio-8080-exec-10] org.springframework.web.servlet.PageNotFound.handleHttpRequestMethodNotSupported Request method 'POST' not supported 

appConfig.java:

@Configuration 
@ComponentScan(basePackages={"service","controller"}) 
public class AppConfig { 

public AppConfig(){ 

     System.out.println("AppConfig!!!!!!!!!!!!!!!!!!!!!"); 
    } 

    @Autowired 
     private ApplicationContext applicationContext; 

     /** 
     * Actor system singleton for this application. 
     */ 
     @Bean (name="ActorSystem") 
     public ActorSystem actorSystem() { 
      System.out.println("system issssssssssssssssssssssssss"); 
      try { 
       ActorSystem system = ActorSystem.create("AkkaJavaSpring"); 
       System.out.println("system issssssssssssssssssssssssss2222222222"); 

       // initialize the application context in the Akka Spring Extension 
       SpringExtProvider.get(system).initialize(applicationContext); 
       return system; 
     } catch (Exception e) { 
      System.err.println("ActorSystem initialized exception: " + e); 
     } 

      System.err.println("no exception!!!!!!!!!!!!!!!!!!!!"); 
     return null; 
     } 

AbstractAnnotationConfigDispatcherServletInitializer

public class DispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 

    @Override 
    protected Class<?>[] getRootConfigClasses() { 
     System.out.println("getRootConfigClasses!!!!!!!!!!!!!! succed"); 
     return new Class<?>[] { 
      WebConfig.class, 
      AppConfig.class 
     }; 
    } 

    @Override 
    protected Class<?>[] getServletConfigClasses() { 
     return null; 
    } 

    @Override 
    protected String[] getServletMappings() { 
     return new String[] { "/" }; 
    } 

    @Override 
    protected Filter[] getServletFilters() { 
     System.out.println("filter !!!!!!!!!!!!!! succed"); 
     return new Filter[] { new HiddenHttpMethodFilter() }; 
    } 

} 

webConfig

@Configuration 
@EnableWebMvc 
public class WebConfig extends WebMvcConfigurerAdapter{ 

    @Override 
     public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { 

//  configurer.ignoreAcceptHeader(true).defaultContentType(
//    MediaType.APPLICATION_JSON); 

     configurer.favorPathExtension(false). 
       favorParameter(true). 
       parameterName("mediaType"). 
       ignoreAcceptHeader(true). 
       useJaf(false). 
       defaultContentType(MediaType.APPLICATION_JSON). 
       mediaType("xml", MediaType.APPLICATION_XML). 
       mediaType("json", MediaType.APPLICATION_JSON); 

     } 

    @Override 
     public void addResourceHandlers(ResourceHandlerRegistry registry) { 
      registry.addResourceHandler("/**").addResourceLocations("/"); 

     } 

控制器:

@RestController 
@RequestMapping(value="/api/mail") 
public class SendMailController { 


    //Dispatcher dispatcher; 

    //@Autowired 
    public SendMailController(){ 
     //this.dispatcher = dispatcher; 
     System.out.println("SendMailController has been loaded!!!!!!!!!!!!!!!!!!!!!"); 
    } 



    @RequestMapping(produces = "application/json" ,method=RequestMethod.POST) 

    public ResponseEntity<HttpStatus> sendMail(@RequestBody MailRequest mailRequest){ 

     System.out.println("MailRequest 2 mailRequest!!!!!!!!!!!!!!!!!!! "); 

    // dispatcher.SendMail(new MailRequestEvent(mailRequest)); 
     return new ResponseEntity<HttpStatus>(HttpStatus.OK); 
    } 

} 

请我relly需要帮助这里

+0

也许这个链接可以帮助你.. http://stackoverflow.com/questions/4339207/http-post-with-request-content-type-form-not-working-in-spring -mvc-3 –

回答

0

问题是在我的URL有一个不同的URL到tomcat和URL之间 要弹性传递是弹性你不包括项目名称的URL和在Tomcat中你必须包括项目命名

感谢