spring – WARN 7136 — [nio-8080-exec-1] osweb.servlet.PageNotFound :No mapping for GET /swagger-ui.html

I try to use the swagger 2 on my project. But when I used http://localhost:8080/swagger-ui.html I got a Whitelabel Error Page. and on my IDE I got this warning WARN 12788 — [nio-8080-exec-1] osweb.servlet.PageNotFound : No mapping for GET /swagger-ui.html. I don’t know if I do it right. Can somebody help to access the swagger UI on my browser? Here’s my code:

config/SwaggerConfig.java

@EnableWebMvc
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket swaggerApiConfig() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .paths(PathSelectors.any())
                .apis(RequestHandlerSelectors.basePackage("com.week4group3.ProductsCRUD"))
                .build();
    }
}

ProductCRUDApplication.java

@EnableWebMvc
@EnableSwagger2
@SpringBootApplication
public class ProductCRUDApplication {

    public static void main(String[] args) {
        SpringApplication.run(ProductCRUDApplication.class, args);

    }

    @Component
    public class DataLoader implements ApplicationRunner {

        private ProductsRepository productsRepository;

        @Autowired
        public DataLoader(ProductsRepository productsRepository) {
            this.productsRepository = productsRepository;
        }

        public void run(ApplicationArguments args) {
            //insert initial data here
            productsRepository.save(new Products("Gucci","Classic Clothes","453456712","User","updatedBy",1,1000,0));
            productsRepository.save(new Products("Chanel","Top Clothes","093456712","User","updatedBy",1,1450,0));
            productsRepository.save(new Products("Hermes","Old Clothes","233456712","User","updatedBy",1,1700,15));
            productsRepository.save(new Products("Penshoppe","New Clothes","123456712","User","updatedBy",1,1500,13));
            productsRepository.save(new Products("RRJ","Sinampay Lang","093456432","User","updatedBy",1,850,10));
            productsRepository.save(new Products("Dickies","Classic Clothes","093456123","User","updatedBy",1,1350,12));
            productsRepository.save(new Products("Fioni","Old Clothes","093456721","User","updatedBy",1,1800,19));
        }
    }
}

application.properties

spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.7</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>crud</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>crud</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>18</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>4.6.0-1</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>3.6.0</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>webjars-locator</artifactId>
            <version>0.45</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-oas</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-spring-web</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.12.2</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Project Structure enter image description here

Leave a Comment