嗨,我使用springboot 1.5.3.RELEASE與swagger2。 當我運行應用程序,我可以通過訪問「localhost:3030/v2/api-docs」來訪問json swagger響應。但是我無法訪問「localhost:3030/swagger-ui.html」,也沒有顯示爲「/swagger-ui.html」找到的映射。 我如何解決這個問題。swagger-ui not load with springboot
依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</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-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- mock testing -->
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.3.4</version>
<scope>compile</scope>
</dependency>
<!-- /mock testing -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml</groupId>
<artifactId>classmate</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
招搖配置
@Configuration
@Component
@EnableSwagger2
public class RestConfig {
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
MappingJackson2HttpMessageConverter converter =
new MappingJackson2HttpMessageConverter(mapper);
return converter;
}
@Bean
public ErpAppConfig configureErpApp() {
// just to process the @PostConstruct
return new ErpAppConfig();
}
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
添加ResourceHandler如'registry.addResourceHandler(「招搖,ui.html 「).addResourceLocations(」 類路徑:/ META-INF /資源/「); (「/ webjars/**」)。addResourceLocations(「classpath:/ META-INF/resources/webjars /」);' –
我應該在哪裏添加這個註冊表? – boycod3
擴展'WebMvcConfigurerAdapter'的文件在那裏覆蓋現有的方法'addResourceHandlers'您的ref:http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api –