gpt4 book ai didi

java - 尝试打开 swagger-ui.html 时出现 404

转载 作者:行者123 更新时间:2023-12-04 13:55:51 24 4
gpt4 key购买 nike

我没有 Spring Boot,只有 Spring MVC 和 Security。
我的配置:

@Configuration
@EnableTransactionManagement
@EnableWebMvc
@EnableSwagger2
@PropertySource("classpath:access.properties")
@ComponentScan(basePackages = {"com.company.service", "com.company.dao", "com.company.controller"})

public class SpringConfig extends WebMvcConfigurationSupport {

@Value("${url}")
private String URL;
@Value("${user}")
private String USER;
@Value("${password}")
private String PASSWORD;

@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}

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

........
pom.xml
    <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>
http://localhost:8080/api/v2/api-docs我得到了巨大的 JSON,但是当我试图在 http://localhost:8080/api/swagger-ui.html 上获取 ui 时我找不到tomcat 404 Tomcat Log
0:0:0:0:0:0:0:1 - - [30/Jun/2020:11:50:09 +0300] "GET /api/v2/api-docs HTTP/1.1" 200 20832
0:0:0:0:0:0:0:1 - - [30/Jun/2020:11:51:51 +0300] "GET /api/swagger-ui.html HTTP/1.1" 404 702
0:0:0:0:0:0:0:1 - - [30/Jun/2020:11:51:54 +0300] "GET /api/swagger-ui.html HTTP/1.1" 404 702
许多文章讨论了使用 Spring Boot 或添加注解的可能解决方案 @EnableSwagger2 ,但在我的情况下没用。

最佳答案

尝试这个:

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler( "api/swagger-ui.html" )
.addResourceLocations( "classpath:/META-INF/resources/" );
}
或删除 /api/当您想访问您的文档时

关于java - 尝试打开 swagger-ui.html 时出现 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62653782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com