-
spring boot 3 버전 이상에서 swagger 사용하기Spring 2024. 7. 2. 00:16
build.gradle에 아래 문구를 작성하여 의존성을 추가해주면 swagger를 사용할 수 있습니다.
//swagger implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
http://localhost:8080/swagger-ui/index.html 에서 확인할 수 있습니다.
Spring Security를 사용 중이라면,
import org.springframework.context.annotation.Configuration; 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; @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/swagger-ui.html", "/swagger-ui/**", "/v3/api-docs/**").permitAll() .anyRequest().authenticated() .and() .csrf().disable(); } }
를 통해, 별도의 로그인 없이 페이지에 접속 가능합니다.
'Spring' 카테고리의 다른 글
Spring OAuth2.0(Google) (0) 2024.08.18 Spring Security OAuth2.0(kakao) (1) 2024.08.17 refresh token redis로 구현하기 (0) 2024.02.22 Spring에서 Redis로 분산락 사용하기 (0) 2024.02.22 AOP, Aspect-Oriented Programming (0) 2024.02.22