SSM配置Swagger 超簡單
阿新 • • 發佈:2018-11-07
1,新增依賴
<!--swagger--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.5.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.5.0</version> </dependency>
2,SpringMvc檔案中新增配置
<!--新增swagger配置--> <bean class="springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration" id="swagger2Config"/> <mvc:resources location="classpath:/META-INF/resources/" mapping="swagger-ui.html"/> <mvc:resources location="classpath:/META-INF/resources/webjars/" mapping="/webjars/**"/>
或者
<bean class="springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration" id="swagger2Config"/> <mvc:annotation-driven /> <!-- 2.靜態資源預設servlet配置 (1)加入對靜態資源的處理:js,gif,png (2)允許使用"/"做整體對映 --> <mvc:default-servlet-handler/>
3,訪問地址
http://IP:port/web-obj-name/swagger-ui.html
具體控制器配置註解請自行了解