tanakahdaのプログラマ手帳

プログラミングとかソフトウェア開発とかの備忘録

Spring Data RESTとSwaggerの設定@Spring Framework

pom.xml

     <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.5.9</version>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-data-rest</artifactId>
            <version>1.5.9</version>
        </dependency>

application.properties

Spring Securityを導入している場合、URLを除外リストに入れる必要があるので下記のとおり設定する

springdoc.api-docs.path=/api-docs
springdoc.swagger-ui.path=/swagger/swagger-ui.html

SecurityConfig.java

    @Override
    public void configure(WebSecurity web) throws Exception {
        // 「/js/**」を追加
        web.ignoring().antMatchers(
                "/js/**", "/css/**", "/img/**", "/webjars/**", "/swagger/**", "/api-docs/**");
    }