Separate front and rear ends arranged swagger interface document ssm

Before configuring been springboot, ssm much simpler now than record what ssm configuration

Add dependency in pom.xml

<!--swagger本身不支持spring mvc的,springfox把swagger包装了一下,让他可以支持springmvc-->
    <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>

Add configuration class SwaggerConfig.java

@WebAppConfiguration
@EnableSwagger2
@EnableWebMvc
@ComponentScan(basePackages = "com.maxcore.controller")
public class SwaggerConfig {


    @Bean
    public Docket customDocket() {
        //
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .build()
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        Contact contact = new Contact("娜", "https://www.baidu.me", "[email protected]");
        return new ApiInfo("仿简书前台API接口",//大标题 title
                "Swagger测试demo",//小标题
                "0.0.1",//版本
                "www.baidu.com",//termsOfServiceUrl
                contact,//作者
                "Blog",//链接显示文字
                "https://www.baidu.me"//网站链接
        );
    }


}

Added as follows dispatcher-servlet.xml (springmvc configuration file)

    <bean class="com.maxcore.config.SwaggerConfig" />

    <mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/" />
    <mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/" />

To add a comment in the controller layer

Finally start the project, the path to access swagger interface documentation must be right, otherwise there have been 404 reported, do you think you did not configure, in fact, you wrong path, I here expressed painful insight

Local access path is the author of http: //localhost/jianShuSSM_war/swagger-ui.html

Usually
http: // ip address: port (the default is 80, not displayed) / project name /swagger-ui.html


end

github

Personal Website

Guess you like

Origin www.cnblogs.com/panbingwen/p/11067746.html