不支持请求方法“POST”和亚马逊弹性豆茎
Posted
技术标签:
【中文标题】不支持请求方法“POST”和亚马逊弹性豆茎【英文标题】:Request method 'POST' not supported and amazon elastic beantalk 【发布时间】:2015-12-28 02:52:24 【问题描述】:尝试在我的控制器中使用带有 java 注释(版本 4.2.1)的 post 方法并在我的本地 tomcat 中成功,但是当我搬到亚马逊 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() ;
网络配置:
@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);
我真的需要帮助
【问题讨论】:
也许这个链接可以帮助你..***.com/questions/4339207/… 【参考方案1】:问题出在我的 URL 中,tomcat 的 URL 和 URL 之间存在差异 弹性延迟是弹性你不要在 URL 中包含项目名称,而在 tomcat 中你必须包含项目名称
谢谢
【讨论】:
以上是关于不支持请求方法“POST”和亚马逊弹性豆茎的主要内容,如果未能解决你的问题,请参考以下文章