时间:2019-5-23 12:46:50
地点:单位、家中
@EnableSwagger2
有了二三章的理解,此时我们再来看EnableSwagger2注解的内容
@Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
@Target(value = { java.lang.annotation.ElementType.TYPE })
@Documented
@Import({Swagger2DocumentationConfiguration.class})
public @interface EnableSwagger2 {
}
Swagger2DocumentationConfiguration
该注解没啥好说的,最终是导入Swagger2DocumentationConfiguration的配置类
@Configuration
@Import({ SpringfoxWebMvcConfiguration.class, SwaggerCommonConfiguration.class })
@ComponentScan(basePackages = {
"springfox.documentation.swagger2.mappers"
})
@ConditionalOnWebApplication
public class Swagger2DocumentationConfiguration {
此处的@ComponentScan注解,扫描了springfox.documentation.swagger2.mappers包路径
Mappers
该包路径下包含了众多运用MapStruct组件自动生成的Mapper实体类转换关系,通过扫描注解,自动注入到Spring的容器中
关于MapStruct组件的使用,可参考:springfox 源码分析(二) 初探mapstruct
主要包括如下:
LicenseMapper
ModelMapper
ParameterMapper
SecurityMapper
SerivceModelToSwagger2Mapper
VendorExtensionsMapper
每个Mapper接口都有一个实现类MapperImpl,实现类通过@Component注解注入到Spring的容器中
最重要的是SerivceModelToSwagger2Mapper这个Mapper
该类的作用会聚合使用Model、Parameter、License等Mapper,将springfox中的对象转化为Swagger标准的对象,包括Swagger
@Generated(
value = "org.mapstruct.ap.MappingProcessor&#