Мое приложение Springboot не может запускать пользовательский интерфейс Swagger на локальном хостеJAVA

Программисты JAVA общаются здесь
Anonymous
Мое приложение Springboot не может запускать пользовательский интерфейс Swagger на локальном хосте

Сообщение Anonymous »

Я интегрировал swagger в свое приложение Springboot с помощью следующей зависимости

Код: Выделить всё

    
org.springdoc
springdoc-openapi-starter-webmvc-ui
2.0.2

Я также разрешил URL-адрес Swagger в своих конфигурациях безопасности следующим образом:

Код: Выделить всё

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
public class SecurityConfig {

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) {

try {
return http
.authorizeHttpRequests(authCustomizer -> authCustomizer
.requestMatchers(HttpMethod.POST,
"/api/users/register", "/api/users/login", "/swagger-ui/**").permitAll()
.requestMatchers(HttpMethod.GET, "/api/users/{id}").hasRole("USER")
.requestMatchers(HttpMethod.PUT, "/api/users/{id}").hasRole("USER")
.requestMatchers(HttpMethod.DELETE, "/api/users/{id}").hasRole("USER")
.requestMatchers(HttpMethod.POST, "/api/transactions").hasRole("USER")
.requestMatchers(HttpMethod.GET, "/api/transactions/{id}").hasRole("USER")
.requestMatchers(HttpMethod.PUT, "/api/transactions/{id}").hasRole("USER")
.requestMatchers(HttpMethod.DELETE, "/api/transactions/{id}").hasRole("USER")
)
.build();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Но все же, когда я запускаю URL-адрес (http://localhost:8080/swagger-ui/index.html), я получаю следующую ошибку.
Изображение


Подробнее здесь: https://stackoverflow.com/questions/783 ... -localhost

Вернуться в «JAVA»