Front-end and back-end separation of SSM configuration swagger interface documents

Time:2019-9-14

Springboot was previously configured, which is much simpler than ssm. Now record the configuration of SSM

Adding dependencies to pom. XML

Springfox wrapped the swagger so that he could support spring MVC - >.
    <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 the 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 ("Na", "https://www.baidu.me", "[email protected]");
        Return new ApiInfo ("Simulated Brief Book Front Desk API Interface", // Headline title
                Swagger Test Demo, // Subtitle
                "0.0.1", //Version
                "www.baidu.com",//termsOfServiceUrl
                Contact,//author
                "Blog", // Link Displays Text
                "Https://www.baidu.me"//website link
        );
    }


}

Add the following configuration in 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 comments to the controller layer

Finally, start the project, access to swagger interface documents must be right, otherwise always report 404, you think you have not configured the right, in fact, your path is wrong, the author here expressed a very painful understanding.

The author’s local access path is http://localhost/jianShuSSM_w…

Generally speaking.
Http://ip address: port (default 80, not shown)/project name/swagger-ui.html


end

github

Personal website

Recommended Today

King of Everest: bitcoin will be supported in the future on December 6.

What is the biggest headache for the Federal Reserve, which is responsible for fulfilling the responsibilities of the Central Bank of the United States? There may be many answers, but too much balance sheet must be one of them. The Fed’s means of influencing monetary policy have long been out of the era of money […]