2 code  code code__code 于 2016.04.06 17:38 提问

Swagger 集成spring boot 2C

为什么我的API只出现一部分
图片说明

 package cn.paybay.qingjiao;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import static springfox.documentation.builders.PathSelectors.regex;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import cn.paybay.qingjiao.base.filter.UserMessageFilter;
import cn.paybay.qingjiao.base.filter.UserMessageFilter2;
import static com.google.common.base.Predicates.or;
@SpringBootApplication
@EnableSwagger2 //Enable swagger 2.0 spec
@ComponentScan("hello")
public class MainController extends WebMvcConfigurerAdapter{

    public static void main(String[] args) throws Exception {
        SpringApplication.run(MainController.class, args);
    }

    //@Override
    //public void addInterceptors(InterceptorRegistry registry) {  
        //registry.addInterceptor(new UserMessageFilter()).addPathPatterns("/**");  
        //registry.addInterceptor(new UserMessageFilter2()).addPathPatterns("/**"); 
       // super.addInterceptors(registry);
    //}

     @Bean
        public Docket newsApi() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .groupName("greetings")
                    .apiInfo(apiInfo())
                    .select()
                    .paths(regex("/greeting.*"))
                    .build();
        }

        private ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("Spring REST Sample with Swagger")
                    .description("Spring REST Sample with Swagger")
                    .termsOfServiceUrl("http://www-03.ibm.com/software/sla/sladb.nsf/sla/bm?Open")
                    .contact("Niklas Heidloff")
                    .license("Apache License Version 2.0")
                    .licenseUrl("https://github.com/IBM-Bluemix/news-aggregator/blob/master/LICENSE")
                    .version("2.0")
                    .build();
        }
}

 package cn.paybay.qingjiao;

import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ResponseHeader;

@RestController
public class GreetingController {

    private static final String template = "Hello, %s!";
    private final AtomicLong counter = new AtomicLong();

    @ApiOperation(value = "getGreeting", nickname = "getGreeting")
    @RequestMapping(method = RequestMethod.GET, path="/greeting", produces = "application/json")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "name", value = "User's name", required = false, dataType = "string", paramType = "query", defaultValue="Niklas")
      })
    @ApiResponses(value = { 
            @ApiResponse(code = 200, message = "Success", response = Greeting.class),
            @ApiResponse(code = 401, message = "Unauthorized"),
            @ApiResponse(code = 403, message = "Forbidden"),
            @ApiResponse(code = 404, message = "Not Found"),
            @ApiResponse(code = 500, message = "Failure")}) 
    public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
        return new Greeting(counter.incrementAndGet(),
                String.format(template, name));
    }
}
 package cn.paybay.qingjiao;

import com.fasterxml.jackson.annotation.JsonProperty;

import io.swagger.annotations.ApiModelProperty;

public class Greeting {

    private final long id;
    private final String content;

    public Greeting(long id, String content) {
        this.id = id;
        this.content = content;
    }

    public long getId() {
        return id;
    }

    @JsonProperty(required = true)
    @ApiModelProperty(notes = "The name of the user", required = true)
    public String getContent() {
        return content;
    }
}

3个回答

CSDNXIAOD
CSDNXIAOD   2016.04.06 17:41

[Spring Boot 系列] 集成maven和Spring boot的profile功能
spring boot 集成shiro的配置
spring boot
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

code__code
code__code   2016.04.07 13:09

谢谢各位啦! 已解决!

code__code
code__code   2016.04.07 13:10

谢谢各位啦! 已解决!

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!