Мое приложение 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
.requestMatchers(HttpMethod.POST,
"/api/users/register", "/api/users/login").permitAll()
.requestMatchers(HttpMethod.GET, "/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);
}
}
}
Ниже приведены мои свойства application.properties.

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

spring.application.name=Fintech-Backend-Developer-Assignment
springdoc.api-docs.path=/api-docs
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
Но все равно, когда я запускаю URL-адрес http://localhost:8080/swagger-ui/index.html, я получаю следующую ошибку.
Изображение


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

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