我按照link中列出的步骤(直到步骤5.1)来集成swagger文档 . 下面是我的控制器类的样子 . 当我尝试访问文档时遇到404错误,类似于使用url> http://localhost:8080/greetingservice/swagger-ui.html在文档中描述的文档
但是我看到使用url http://localhost:8080/swagger-ui.html#!/greeting-controller/greetingUsingGET的文档
我希望文档显示类似于在特定于应用程序的上下文路径下的文档中提到的文档 . 你能告诉我我错过的东西吗?
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
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 com.comcast.rapid.ctp.springfox.service.model.Greeting;
@RequestMapping("/greetingservice")
@RestController
public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@RequestMapping(method={RequestMethod.GET}, value="{apiName}", produces=MediaType.APPLICATION_JSON_VALUE)
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name,@PathVariable String apiName) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
}
1 回答
您需要按如下方式设置应用程序上下文路径:
在
src/main/resources
中创建application.properties
并添加以下行:参考:
http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html