SpringBoot 调用ajax POST 方法报Request method 'POST' not supported解决方法

本文介绍了解决Spring Boot应用中无法通过AJAX提交POST请求的问题。通过在启动类中添加@ComponentScan注解,成功实现了对Controller的扫描与注册,避免了出现405错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天在学习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)错误。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值