2015-09-30 111 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中你必須包括項目命名

感謝