(三)SSM框架整合Swagger2
(三)SSM框架整合Swagger2
1.引入依赖
<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>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-web</artifactId>
<version>2.9.2</version>
</dependency>
2.添加java配置类
Swagger2Config.java
/**
* @version v1.0
* @ProjectName: SpringBootTest
* @ClassName: Swagger2Config
* @Description: TODO(Swagger2Config 在线API文档配置类)
* @Author: WDD
* @Date: 2020/2/10 16:52
*/
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
public Docket docket(ApiInfo apiInfo){//apiInfo是由下方的Bean注入进来的
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo)
.select()
.apis(RequestHandlerSelectors.basePackage("com.wdd.controller"))
.paths(PathSelectors.any())
.build();
}
@Bean
public ApiInfo apiInfo(){
Contact contact = new Contact("xxxx","xxxxxxx@qq.com","xxxxxxx@qq.com");
return new ApiInfo(
"SSM框架整合",
"将其他技术整合到SSM框架当中",
"1.0",
"urn:tos",
contact,
"Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0",
new ArrayList<VendorExtension>());
}
}
3.在applcationContext.xml中配置
<!-- 1.引入swagger相关 -->
<!-- 1.1 将Swagger配置类注入到容器中-->
<bean class="com.wdd.config.Swagger2Config"/>
<!-- 1.2 视图配置-->
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/" />
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/" />
<!-- 2.引入swagger相关配置包 -->
<bean class="springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration" id="swagger2Config"/>

浙公网安备 33010602011771号