【发布时间】:2020-10-20 12:58:16
【问题描述】:
我没有 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 可能解决问题的方法,但对我来说毫无用处。
【问题讨论】:
标签: java spring-mvc spring-security swagger