邮递员未经授权获得401 ...使用Spring Boot

时间:2020-10-27 18:25:00

标签: java spring spring-boot hibernate

我正在尝试使用Spring Boot创建一个Web应用程序...我的邮递员让所有时间401未经授权。我该如何解决问题...谢谢

我的application.properties文件

############# Database Properties ############################
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/reddit_clone
spring.datasource.username=user
spring.datasource.password=Jsingh22.
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update
spring.datasource.initialization-mode=always
spring.jpa.show-sql=true

我的控制器类

@RestController
@RequestMapping("/api/auth")
@AllArgsConstructor
public class AuthController {

    private final AuthService authService;

    @PostMapping("/signup")
    public ResponseEntity<String> signUp(@RequestBody RegisterRequest registerRequest) {
        System.out.println("Hello World");
        authService.signUp(registerRequest);
        return new ResponseEntity<>("User Registration Successfully", HttpStatus.OK);
    }
}

我的安全课

@Configuration
@EnableWebSecurity
@AllArgsConstructor
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    
    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity.csrf().disable()
            .authorizeRequests()
            .antMatchers("/api/auth/**")
            .permitAll()
            .anyRequest()
            .authenticated();
    }
}

我正在尝试很多解决方案StackOverflow ...但是我的案子不接受该解决方案 如何解决我的问题?

0 个答案:

没有答案