Spring
spring boot 3 버전 이상에서 swagger 사용하기
계양 꿀주먹
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();
}
}
를 통해, 별도의 로그인 없이 페이지에 접속 가능합니다.