今天在学习spring boot的时候,在用ajax调用后台controller的时候发现没法提交POST请求,最终解决方案如下:
@SpringBootApplication
@ServletComponentScan( basePackages = "com.bd.*")
@ComponentScan( basePackages = "com.bd.*")
@EnableAutoConfiguration
public class Application {
public static void main(String[] args){
// new SpringApplicationBuilder(Application.class).web(true).run(args);
SpringApplication.run(Application.class,args);
}
}
在application类中添加@ComponentScan注解,此注解能够对Controller进行扫描并注册,不然对controller中的发放进行提交时会报Request method 'POST' not supported(405 not allowed)错误。