Spring Boot 如何解决SpringBoot 405方法不允许错误?

7qhs6swi  于 2022-11-05  发布在  Spring
关注(0)|答案(1)|浏览(370)

当我输入URL“http://localhost:8080/registration”时,我希望在Postman(用于临时测试,直到我使用HTML和CSS实现前端和表单)上收到消息“Works”。根据下面发布的代码,这应该会发生。但我收到了405方法不允许错误。
类包的名称为:WebSecurityConfig;

import com.example.finalVersionBookProject.appuser.AppUserService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import       org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import  org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

private final AppUserService appUserService;
private final BCryptPasswordEncoder bCryptPasswordEncoder;
public WebSecurityConfig(AppUserService appUserService, BCryptPasswordEncoder bCryptPasswordEncoder) {
this.appUserService = appUserService;
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
}

注册类别
第一个

wfveoks0

wfveoks01#

当你在Postman中输入URL http://localhost:8080/registration时,你使用了什么方法?我怀疑你使用的是GET,而你的控制器有一个支持POST方法的@PostMapping
您可以尝试改用@GetMapping

相关问题