springboot項目使用了角色權限shiro管理,我要測試其它的接口但是需要登錄成功后才能測試,解決這個問題有兩種方法。
1.postman直接輸入用戶名和密碼登錄成功后,就可以進行其它的接口測試。
2. 使用swagger先登錄成功后,就可以測試其它的接口了。
一,postman
二、swagger
springboot集成swagger后訪問URL
http://localhost:8080/swagger-ui.html
@Configuration
@EnableSwagger2
public class SwaggerConfig {
? ? @Bean
? ? public Docket api() {
? ? ? ? return new Docket(DocumentationType.SWAGGER_2)
? ? ? ? ? ? ? ? .apiInfo(apiInfo())
? ? ? ? ? ? ? ? .select()
? ? ? ? ? ? ? ? .apis(RequestHandlerSelectors.basePackage("com.baidu.controller")) //自己的控制器包名路徑
? ? ? ? ? ? ? ? .paths(PathSelectors.any())
? ? ? ? ? ? ? ? .build();
? ? }
? ? private ApiInfo apiInfo() {
? ? ? ? return new ApiInfoBuilder()
? ? ? ? ? ? ? ? .title("世界 API文檔")
? ? ? ? ? ? ? ? .description("世界 操作文檔")
? ? ? ? ? ? ? ? //服務條款網址
? ? ? ? ? ? ? ? .termsOfServiceUrl("http://www.baidu.com/")
? ? ? ? ? ? ? ? .version("1.0")
? ? ? ? ? ? ? ? .contact(new Contact("祖國", "http://www.baidu.com/", "123456@qq.com"))
? ? ? ? ? ? ? ? .build();
? ? }
}
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>