zoukankan      html  css  js  c++  java
  • spring mvc4 配置restfulAPI 接口管理工具问题整体

    1.jar

    2.文件配置

    swagger配置

    package com.myPackage.config;
    
    
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    
    import springfox.documentation.builders.PathSelectors;
    import springfox.documentation.builders.RequestHandlerSelectors;
    import springfox.documentation.service.ApiInfo;
    import springfox.documentation.spi.DocumentationType;
    import springfox.documentation.spring.web.plugins.Docket;
    import springfox.documentation.swagger2.annotations.EnableSwagger2;
    
    @Configuration
    @EnableSwagger2
    public class SwaggerConfig{
    
    
        @Bean
        public Docket api(){
            return new Docket(DocumentationType.SWAGGER_2)
                    .select()
                    .apis(RequestHandlerSelectors.any())
                    .paths(PathSelectors.any())
                    .build()
                    .groupName("test")
                    .apiInfo(apiInfo());
        }
    
        private ApiInfo apiInfo() {
            ApiInfo apiInfo = new ApiInfo(
                    "My Project's REST API", 
                    "This is a description of your API.", 
                    "API TOS",
                    "url",
                    "me@wherever.com", 
                    "API License", 
                    "API License URL");
            return apiInfo;
        }
    
    }
    springMVC配置:

    package com.myPackage.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.view.InternalResourceViewResolver; @Configuration @EnableWebMvc @Import({SwaggerConfig.class}) @ComponentScan("com.myPackage.controller") public class WebSpringConfig extends WebMvcConfigurerAdapter{ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); registry .addResourceHandler("swagger-ui.html") .addResourceLocations("classpath:/META-INF/resources/"); registry .addResourceHandler("/webjars/**") .addResourceLocations("classpath:/META-INF/resources/webjars/"); } @Bean public ViewResolver configureViewResolver() { InternalResourceViewResolver viewResolve = new InternalResourceViewResolver(); viewResolve.setPrefix("/WEB-INF/views/"); viewResolve.setSuffix(".jsp"); return viewResolve; } @Override public void configureDefaultServletHandling( DefaultServletHandlerConfigurer configurer) { configurer.enable(); } }

      3.分发器配置:

    <servlet>
            <servlet-name>appServlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
            <param-name>contextClass</param-name>
            <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
            </init-param>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>com.myPackage.config.WebSpringConfig</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
    

      

    4问题:v2/api-docs 报 404 

    参考:

    https://stackoverflow.com/questions/33780237/springfox-2-2-2-no-api-docs-generated

  • 相关阅读:
    Java第一次作业——Java语言基础
    P田日志<1>
    没解决的问题-git连接失败
    解决每次centos7执行java --version git --version等命令时都要重新source /etc/profile后才能执行,否则找不到命令-转载
    【Linux】VMware虚拟机中如何配置静态IP-转载
    Parallels Desktop 16 破解版 出现网络初始化失败和不能连接USB设备解决方法-转载
    Ubuntu安装git时出错,git-compat-util.h:280:25: fatal error: openssl/ssl.h: 没有那个文件或目录-转载
    遇到的问题29
    解决Idea 导入maven工程编译 Error running 'tms [clean]': Cannot run program "C:Program FilesJavajdk --转载
    jenkins执行shell命令时,提示“Command not found”处理方法-需要在jenkins调用shell脚本的最前面加一行脚本, #!/bin/bash -ilex-------转载
  • 原文地址:https://www.cnblogs.com/codeinet/p/7978969.html
Copyright © 2011-2022 走看看