尝试在我的控制器中使用post方法使用java注释(版本4.2.1)并在我的本地tomcat中成功,但是当我移动到amazon 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);
}
}
请我在这里需要帮助
答案 0 :(得分:0)
问题出在我的网址中,tomcat的网址与网址之间存在差异 弹性传递是弹性的,你不在URL中包含项目名称,在tomcat中你必须包含项目名称
由于