Error cause: it may be caused by version mismatch. My spring boot is 2.6.0, but the spring cloud version needs to be compared in this way and cannot be degraded, so it is configured in this way
POM dependency
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>25.1-jre</version>
</dependency>
</dependencies>
Startup class:
@SpringBootApplication
@EnableDiscoveryClient
@EnableWebMvc // Comment out
public class UploadServiceApplication {
public static void main(String[] args) {
SpringApplication.run(UploadServiceApplication.class, args);
}
}
This configuration may cause the UI page of swagger to fail to open, so the following configuration is required:
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class WebMvcConfigurer extends WebMvcConfigurerAdapter {
/**
* Accessing static resources
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
/**
* SpringBoot autoconfiguration itself does not map the /swagger-ui.html
* This path is mapped to the corresponding directory META-INF/resources/
* Use WebMvcConfigurerAdapter to publish the static files of swagger;
*/
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
//Map all /static/** accesses to the classpath:/static/ directory
registry.addResourceHandler("/static/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX +"/static/");
super.addResourceHandlers(registry);
}
}
Similar Posts:
- [Solved] Springboot integrate swagger Error: failed to start bean ‘documentationpluginsboot
- [Solved] Springboot Integrate Swagger2 3.0.0 Error: Failed to start bean ‘documentationPluginsBootstrapper’
- [Solved] Whitelabel page error when using Swagger2 in SpringBoot
- [How to Solve] RestController cannot be recognized in spring boot
- Eureka server project startup error handling
- Mockito can’t solve the problem of mockfinal class
- Error creating bean with name ‘com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration’
- Springboot always reports an error when importing JSP dependencies
- [Solved] SpringBoot Package Error: Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-res
- Unregistering JMX-exposed beans on shutdown Solution