我尝试使用Springfox(这是记录我的Spring Boot项目的大手笔),但是,当我访问/ v2 / api-docs时,它返回以下内容:
<Json>
{"swagger":"2.0","info":{"description":"Api Documentation","version":"1.0","title":"Api Documentation","termsOfService":"urn:tos","contact":{},"license":{"name":"Apache 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0"}},"host":"localhost:9999","basePath":"/","tags":[{"name":"basic-error-controller","description":"Basic Error Controller"},{"name":"operation-handler","description":"Operation Handler"},{"name":"rest-call-controller","description":"Rest Call Controller"},{"name":"web-mvc-links-handler","description":"Web Mvc Links Handler"}],"paths":{"/actuator":{"get":{"tags":["web-mvc-links-handler"],"summary":"links","operationId":"linksUsingGET","produces":["application/json","application/vnd.spring-boot.actuator.v2+json"],"responses":{"200":{"description":"OK","schema":{"type":"object","additionalProperties":{"type":"object","additionalProperties":{"$ref":"#/definitions/Link"}}}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":false}},"/actuator/health":{"get":{"tags":["operation-handler"],"summary":"handle","operationId":"handleUsingGET_2","produces":["application/json","application/vnd.spring-boot.actuator.v2+json"],"parameters":[{"in":"body","name":"body","description":"body","required":false,"schema":{"type":"object","additionalProperties":{"type":"string"}}}],"responses":{"200":{"description":"OK","schema":{"type":"object"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":false}},"/actuator/health/{component}":{"get":{"tags":["operation-handler"],"summary":"handle","operationId":"handleUsingGET_1","produces":["application/json","application/vnd.spring-boot.actuator.v2+json"],"parameters":[{"in":"body","name":"body","description":"body","required":false,"schema":{"type":"object","additionalProperties":{"type":"string"}}}],"responses":{"200":{"description":"OK","schema":{"type":"object"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":false}},"/actuator/health/{component}/{instance}":{"get":{"tags":["operation-handler"],"summary":"handle","operationId":"handleUsingGET","produces":["application/json","application/vnd.spring-boot.actuator.v2+json"],"parameters":[{"in":"body","name":"body","description":"body","required":false,"schema":{"type":"object","additionalProperties":{"type":"string"}}}],"responses":{"200":{"description":"OK","schema":{"type":"object"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":false}},"/actuator/info":{"get":{"tags":["operation-handler"],"summary":"handle","operationId":"handleUsingGET_3","produces":["application/json","application/vnd.spring-boot.actuator.v2+json"],"parameters":[{"in":"body","name":"body","description":"body","required":false,"schema":{"type":"object","additionalProperties":{"type":"string"}}}],"responses":{"200":{"description":"OK","schema":{"type":"object"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":false}},"/error":{"get":{"tags":["basic-error-controller"],"summary":"errorHtml","operationId":"errorHtmlUsingGET","produces":["text/html"],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/ModelAndView"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":false},"head":{"tags":["basic-error-controller"],"summary":"errorHtml","operationId":"errorHtmlUsingHEAD","consumes":["application/json"],"produces":["text/html"],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/ModelAndView"}},"204":{"description":"No Content"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"}},"deprecated":false},"post":{"tags":["basic-error-controller"],"summary":"errorHtml","operationId":"errorHtmlUsingPOST","consumes":["application/json"],"produces":["text/html"],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/ModelAndView"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":false},"put":{"tags":["basic-error-controller"],"summary":"errorHtml","operationId":"errorHtmlUsingPUT","consumes":["application/json"],"produces":["text/html"],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/ModelAndView"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":false},"delete":{"tags":["basic-error-controller"],"summary":"errorHtml","operationId":"errorHtmlUsingDELETE","produces":["text/html"],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/ModelAndView"}},"204":{"description":"No Content"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"}},"deprecated":false},"options":{"tags":["basic-error-controller"],"summary":"errorHtml","operationId":"errorHtmlUsingOPTIONS","consumes":["application/json"],"produces":["text/html"],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/ModelAndView"}},"204":{"description":"No Content"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"}},"deprecated":false},"patch":{"tags":["basic-error-controller"],"summary":"errorHtml","operationId":"errorHtmlUsingPATCH","consumes":["application/json"],"produces":["text/html"],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/ModelAndView"}},"204":{"description":"No Content"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"}},"deprecated":false}},"/fdr/process":{"post":{"tags":["rest-call-controller"],"summary":"postISO","operationId":"postISOUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"in":"body","name":"request","description":"request","required":true,"schema":{"$ref":"#/definitions/PosMessage"}}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":false}},"/fdr/vxn/activateMerchant":{"post":{"tags":["rest-call-controller"],"summary":"activateMerchant","operationId":"activateMerchantUsingPOST","consumes":["application/json"],"produces":["application/json"],"parameters":[{"in":"body","name":"req","description":"req","required":true,"schema":{"$ref":"#/definitions/VxnRequest"}}],"responses":{"200":{"description":"OK","schema":{"type":"object"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":false}},"/fdr/vxn/ping":{"post":{"tags":["rest-call-controller"],"summary":"ping","operationId":"pingUsingPOST","consumes":["application/json"],"produces":["application/json"],"parameters":[{"in":"body","name":"req","description":"req","required":true,"schema":{"$ref":"#/definitions/VxnRequest"}}],"responses":{"200":{"description":"OK","schema":{"type":"object"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":false}},"/fdr/vxn/provisioningMerchant":{"post":{"tags":["rest-call-controller"],"summary":"provisioningMerchant","operationId":"provisioningMerchantUsingPOST","consumes":["application/json"],"produces":["application/json"],"parameters":[{"in":"body","name":"req","description":"req","required":true,"schema":{"$ref":"#/definitions/VxnRequest"}}],"responses":{"200":{"description":"OK","schema":{"type":"object"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":false}},"/fdr/vxn/secureTransport":{"post":{"tags":["rest-call-controller"],"summary":"init","operationId":"initUsingPOST","consumes":["application/json"],"produces":["application/json"],"parameters":[{"in":"body","name":"req","description":"req","required":true,"schema":{"$ref":"#/definitions/VxnRequest"}}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/VxnRequest"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":false}},"/fdr/vxn/serviceDiscovery":{"get":{"tags":["rest-call-controller"],"summary":"serviceDiscovery","operationId":"serviceDiscoveryUsingGET","produces":["*/*"],"parameters":[{"name":"serviceId","in":"query","description":"serviceId","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"object"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":false}},"/fdr/vxn/simpleTransaction":{"post":{"tags":["rest-call-controller"],"summary":"simpleTransation","operationId":"simpleTransationUsingPOST","consumes":["application/json"],"produces":["application/json"],"parameters":[{"in":"body","name":"req","description":"req","required":true,"schema":{"$ref":"#/definitions/VxnRequest"}}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/SimpleTransactionRes"}},"201":{"description":"Created"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}},"deprecated":false}}},"definitions":{"Link":{"type":"object","properties":{"href":{"type":"string"},"templated":{"type":"boolean"}},"title":"Link"},"Map«string,Link»":{"type":"object","title":"Map«string,Link»","additionalProperties":{"$ref":"#/definitions/Link"}},"ModelAndView":{"type":"object","properties":{"empty":{"type":"boolean"},"model":{"type":"object"},"modelMap":{"type":"object","additionalProperties":{"type":"object"}},"reference":{"type":"boolean"},"status":{"type":"string","enum":["100 CONTINUE","101 SWITCHING_PROTOCOLS","102 PROCESSING","103 CHECKPOINT","200 OK","201 CREATED","202 ACCEPTED","203 NON_AUTHORITATIVE_INFORMATION","204 NO_CONTENT","205 RESET_CONTENT","206 PARTIAL_CONTENT","207 MULTI_STATUS","208 ALREADY_REPORTED","226 IM_USED","300 MULTIPLE_CHOICES","301 MOVED_PERMANENTLY","302 FOUND","302 MOVED_TEMPORARILY","303 SEE_OTHER","304 NOT_MODIFIED","305 USE_PROXY","307 TEMPORARY_REDIRECT","308 PERMANENT_REDIRECT","400 BAD_REQUEST","401 UNAUTHORIZED","402 PAYMENT_REQUIRED","403 FORBIDDEN","404 NOT_FOUND","405 METHOD_NOT_ALLOWED","406 NOT_ACCEPTABLE","407 PROXY_AUTHENTICATION_REQUIRED","408 REQUEST_TIMEOUT","409 CONFLICT","410 GONE","411 LENGTH_REQUIRED","412 PRECONDITION_FAILED","413 PAYLOAD_TOO_LARGE","413 REQUEST_ENTITY_TOO_LARGE","414 URI_TOO_LONG","414 REQUEST_URI_TOO_LONG","415 UNSUPPORTED_MEDIA_TYPE","416 REQUESTED_RANGE_NOT_SATISFIABLE","417 EXPECTATION_FAILED","418 I_AM_A_TEAPOT","419 INSUFFICIENT_SPACE_ON_RESOURCE","420 METHOD_FAILURE","421 DESTINATION_LOCKED","422 UNPROCESSABLE_ENTITY","423 LOCKED","424 FAILED_DEPENDENCY","426 UPGRADE_REQUIRED","428 PRECONDITION_REQUIRED","429 TOO_MANY_REQUESTS","431 REQUEST_HEADER_FIELDS_TOO_LARGE","451 UNAVAILABLE_FOR_LEGAL_REASONS","500 INTERNAL_SERVER_ERROR","501 NOT_IMPLEMENTED","502 BAD_GATEWAY","503 SERVICE_UNAVAILABLE","504 GATEWAY_TIMEOUT","505 HTTP_VERSION_NOT_SUPPORTED","506 VARIANT_ALSO_NEGOTIATES","507 INSUFFICIENT_STORAGE","508 LOOP_DETECTED","509 BANDWIDTH_LIMIT_EXCEEDED","510 NOT_EXTENDED","511 NETWORK_AUTHENTICATION_REQUIRED"]},"view":{"$ref":"#/definitions/View"},"viewName":{"type":"string"}},"title":"ModelAndView"},"PosMessage":{"type":"object","properties":{"POSMessage":{"type":"string"},"transactionID":{"type":"string"}},"title":"PosMessage"},"RespClientID":{"type":"object","properties":{"clientRef":{"type":"string"},"did":{"type":"string"}},"title":"RespClientID","xml":{"name":"RespClientID","attribute":false,"wrapped":false}},"SimpleTransactionRes":{"type":"object","properties":{"respClientID":{"$ref":"#/definitions/RespClientID"},"status":{"$ref":"#/definitions/Status"},"transactionResponse":{"$ref":"#/definitions/TransactionResponse"},"version":{"type":"string"}},"title":"SimpleTransactionRes","xml":{"name":"Response","attribute":false,"wrapped":false}},"Status":{"type":"object","properties":{"status":{"type":"string"},"statusCode":{"type":"string"}},"title":"Status","xml":{"name":"Status","attribute":false,"wrapped":false}},"TransactionResponse":{"type":"object","properties":{"payload":{"type":"string"},"returnCode":{"type":"string"}},"title":"TransactionResponse","xml":{"name":"TransactionResponse","attribute":false,"wrapped":false}},"View":{"type":"object","properties":{"contentType":{"type":"string"}},"title":"View"},"VxnRequest":{"type":"object","properties":{"ACTIVEURL":{"type":"string"},"App":{"type":"string"},"CurrentService":{"type":"string"},"DID":{"type":"string"},"MID":{"type":"string"},"MTI":{"type":"string"},"Payload":{"type":"array","items":{"type":"string"}},"PingUrl":{"type":"string"},"PingUrlList":{"type":"array","items":{"type":"string"}},"Postdate":{"type":"string"},"ResponseText":{"type":"string"},"ReturnCode":{"type":"string"},"ServiceID":{"type":"string"},"ServiceType":{"type":"array","items":{"type":"string"}},"StatusCode":{"type":"string"},"TID":{"type":"string"},"TransationId":{"type":"string"},"TxCount":{"type":"integer","format":"int32"},"mti":{"type":"string"},"postdate":{"type":"string"}},"title":"VxnRequest"}}}
</Json>
当我尝试访问/swagger-ui.html
时,它说unable to infer base url...
这是我昂首阔步的配置
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SpringFoxConfig {
@Bean
public Docket apiDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
这是我的pom文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>simpleProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>simpleProject</name>
<description>simpleProject project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<repositories>
<repository>
<id>oracle</id>
<name>Oracle repo</name>
<url>http://download.oracle.com/maven</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</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-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<!-- fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jpos/jpos -->
<dependency>
<groupId>org.jpos</groupId>
<artifactId>jpos</artifactId>
<version>2.1.2</version>
</dependency>
<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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我有另一个项目,它的设置相同,但是它是通过gradle构建的,可以正常运行。我不知道我的这个项目会发生什么...