swagger-maven-plugin自动生成swagger.json(springmvc项目)

来源:互联网 发布:美容院会计软件 编辑:程序博客网 时间:2024/06/01 21:37

1,加入依赖:

<!-- Swagger --><dependency>    <groupId>io.swagger</groupId>    <artifactId>swagger-core</artifactId>    <version>1.5.16</version></dependency>
2,加入插件

<!--增加swagger-plugin--><plugin>    <groupId>com.github.kongchen</groupId>    <artifactId>swagger-maven-plugin</artifactId>    <version>3.1.4</version>(貌似别的版本不行,耗了挺长时间的)    <configuration>        <apiSources>            <apiSource>                <springmvc>true</springmvc>                <locations>                    <location>com.gionee.geip.web</location>                </locations>                <schemes>                    <scheme>http</scheme>                    <scheme>https</scheme>                </schemes>                <host>xxxx</host>                <basePath>/api</basePath>                <info>                    <title>Swagger Maven Plugin Sample</title>                    <version>v1</version>                    <description>                        This is a sample.                    </description>                    <termsOfService>                        http://www.github.com/kongchen/swagger-maven-plugin                    </termsOfService>                    <contact>                        <email>xxx</email>                        <name>xxx</name>                        <url>xxx</url>                    </contact>                    <license>                        <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>                        <name>Apache 2.0</name>                    </license>                </info>                <swaggerDirectory>${basedir}/src/main/generated/swagger-ui</swaggerDirectory>            </apiSource>        </apiSources>    </configuration>    <executions>        <execution>            <phase>compile</phase>            <goals>                <goal>generate</goal>            </goals>        </execution>    </executions></plugin>
3,在controller中加入注释:

@Controller@Api(value="web")//必须@RequestMapping("/geip")public class WebController {    @Autowired    private GeipManager geipManager;    @ResponseBody    @ApiOperation(value = "test", response = Void.class)//必须    @RequestMapping(value = "/test",            method = RequestMethod.POST    )    public String test() {        return "test";    }}
写上以免自己忘记