Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Spring在Swagger UI上接收404错误_Java_Spring Boot_Swagger_Swagger Ui - Fatal编程技术网

Java 使用Spring在Swagger UI上接收404错误

Java 使用Spring在Swagger UI上接收404错误,java,spring-boot,swagger,swagger-ui,Java,Spring Boot,Swagger,Swagger Ui,我正在将swagger UI与Spring boot应用程序集成。当我点击swagger-ui.html时。我得到了404错误。我的配置类如下: @Configuration @EnableSwagger2 //@Import(SwaggerConfiguration.class) public class SwaggerConfig { @Bean public Docket api() { return new Docket(Document

我正在将swagger UI与Spring boot应用程序集成。当我点击swagger-ui.html时。我得到了404错误。我的配置类如下:

@Configuration
@EnableSwagger2
//@Import(SwaggerConfiguration.class)
public class SwaggerConfig  {
    @Bean
        public Docket api() {
            return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
        }
...
错误消息:

{"status":404,"message":"HTTP 404 Not Found","link":"https://jersey.java.net/apidocs/2.8/jersey/javax/ws/rs/NotFoundException.html"}

希望这有帮助,请在下面找到我的工作招摇配置:

@Configuration
@EnableSwagger2
@Profile({"!production"})
public class SwaggerConfiguration extends WebMvcConfigurerAdapter {

    @Autowired
    private ServletContext servletContext;


    @Bean
    public Docket api() {

        return new Docket(DocumentationType.SWAGGER_2)
                .host("localhost")
                .directModelSubstitute(LocalDate.class, Date.class)
                .pathProvider(new RelativePathProvider(servletContext) {
                    @Override
                    public String getApplicationBasePath() {
                        return "/";
                    }
                })
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }
}

您的配置类中是否有@EnableWebMvc?如果是这样,您必须手动进行资源配置,如下所示:

@Override
public void addResourceHandlers (ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/swagger-ui.html**")
            .addResourceLocations("classpath:/META-INF/resources/swagger-ui.html");
    registry.
            addResourceHandler("/webjars/**")
            .addResourceLocations("classpath:/META-INF/resources/webjars/");
}

我遇到了一个类似的问题,/swagger-ui.html(或新的端点版本/swagger-ui/)返回404,但/v2/api文档返回了有效的json。解决方案是从3.0.0版下调swagger版本。到2.9.2.

大家好,请帮助我。我想默认url是。你能进入吗?或