SpringBoot 踩坑笔记(二)

最近在做项目的时候,发现一些不存在的接口,经常会被转发到一个特定的地址(我这里被转发的是:"/api/v1/sendgrid",这个地址在项目是存在的)

然后我打开了对应的controller,刚开始始终没有发现问题:

/**
 * @author xxxx
 * @since 2020/4/21 17:24 sendgrid邮件控制器
 */
@RestController("/api/v1/sendgrid")
public class SendGridController {

    @Autowired
    private ISendGridService sendGridService;

    @PostMapping
    public BaseResult<Object> sendMail(@RequestBody MailRequestForm requestForm) {
        return sendGridService.sendMail(requestForm);
    }
}

经过对比发现,原来是@RestController("/api/v1/sendgrid")出现了问题,一般的写法是

@RestController
@RequestMapping("/api/v1/sendgrid")

RestController源码注释:

    /**
     * The value may indicate a suggestion for a logical component name,
     * to be turned into a Spring bean in case of an autodetected component.
     * @return the suggested component name, if any (or empty String otherwise)
     * @since 4.0.1
     */

解释:该值可以指示逻辑组件名称的建议,在自动检测到组件的情况下,该名称将转换为Spring bean。

总的影响是把所有不存在的请求给来到这儿了。

猜你喜欢

转载自blog.csdn.net/qq_26878363/article/details/106024290