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

  • 相关阅读:
    Oracle expdp导出多表或表中的部分数据
    sklearn随机森林-分类参数详解
    python中函数 reshape(-1,1)
    Scikit-Learn & TensorFlow机器学习实用指南(二):一个完整的机器学习项目【上】
    查看包内函数:
    盘点 | Python自带的那些数据集
    机器学习之数据预处理
    Python Numpy模块函数np.c_和np.r_
    Pandas dataframe数据写入文件和数据库
    机器学习入门-文本数据-构造Tf-idf词袋模型(词频和逆文档频率) 1.TfidfVectorizer(构造tf-idf词袋模型)
  • 原文地址:https://www.cnblogs.com/codeinet/p/7978969.html
Copyright © 2011-2022 走看看