Java springfox+;大摇大摆不起作用

Java springfox+;大摇大摆不起作用,java,spring,swagger,springfox,Java,Spring,Swagger,Springfox,我的pom.xml <!-- Swagger io for API doc --> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-core</artifactId> <version>1.5.3</version>

我的pom.xml

<!-- Swagger io for API doc -->
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-core</artifactId>
            <version>1.5.3</version>
            <exclusions>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-annotations</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-databind</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.6.1</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.6.1</version>
        </dependency>
服务器日志

16-05-18 13:08:59.137       ContainerBackgroundProcessor[StandardEngine[Catalina]]  INFO    o.s.w.s.m.m.a.RequestMappingHandlerMapping  registerHandlerMethod        190    Mapped "{[/${springfox.documentation.swagger.v2.path:/v2/api-docs}],methods=[GET],params=[],headers=[],consumes=[],produces=[application/json || application/hal+json],custom=[]}" onto public org.springframework.http.ResponseEntity<springfox.documentation.spring.web.json.Json> springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(java.lang.String,javax.servlet.http.HttpServletRequest)
16-05-18 13:08:59.141       ContainerBackgroundProcessor[StandardEngine[Catalina]]  INFO    o.s.w.s.m.m.a.RequestMappingHandlerMapping  registerHandlerMethod        190    Mapped "{[/swagger-resources/configuration/security],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.SecurityConfiguration> springfox.documentation.swagger.web.ApiResourceController.securityConfiguration()
16-05-18 13:08:59.143       ContainerBackgroundProcessor[StandardEngine[Catalina]]  INFO    o.s.w.s.m.m.a.RequestMappingHandlerMapping  registerHandlerMethod        190    Mapped "{[/swagger-resources/configuration/ui],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.UiConfiguration> springfox.documentation.swagger.web.ApiResourceController.uiConfiguration()
16-05-18 13:08:59.145       ContainerBackgroundProcessor[StandardEngine[Catalina]]  INFO    o.s.w.s.m.m.a.RequestMappingHandlerMapping  registerHandlerMethod        190    Mapped "{[/swagger-resources],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto org.springframework.http.ResponseEntity<java.util.List<springfox.documentation.swagger.web.SwaggerResource>> springfox.documentation.swagger.web.ApiResourceController.swaggerResources()

如果我使用spring fox低版本,那么我会在日志中看到它映射了“{[/v2/api docs}”,方法=[get]。但是,我看不到在那里生成的任何json。

好吧,这将不起作用

http://localhost:8080/allocation-order-web/v2/api-docs
您还需要通过group attr,请尝试此方法

http://localhost:8080/allocation-order-web/v2/api-docs?group=public-api

您可能需要指定主应用程序上下文路径以及swagger文档路径(最好在自定义属性文件或application.properties下定义它们):

@配置
@EnableWebMvc
@使能招摇过市2
@PropertySource(“类路径:swagger-v2.properties”)
公共类招摇过市配置{
//...
}
swagger-v2.properties应如下所示:

server.contextPath=/allocation-order-web/
springfox.documentation.swagger.v2.path=/api-docs
然后应通过以下方式获取文件:


它仍然给出404,这很奇怪。对于我来说,没有任何组属性,它显示404,但一旦我添加了group=public api,它就工作了。我添加了一个VM arg springfox.documentation.swagger.v2.path=/swagger,然后尝试了。仍然得到404
http://localhost:8080/allocation-order-web/v2/api-docs?group=public-api
server.contextPath=/allocation-order-web/
springfox.documentation.swagger.v2.path=/api-docs