0
votes

I followed the steps listed in this link (until step 5.1) for integrating swagger documentation. Below is how my controller class looks like. I get a 404 error when I try to access the documentation similar to how it is described in the documentation using url > http://localhost:8080/greetingservice/swagger-ui.html

However I see the documentation using url http://localhost:8080/swagger-ui.html#!/greeting-controller/greetingUsingGET

I would like the documentation to be displayed similar to how it is mentioned in the documentation under context path specific to the app. Can you please let me know what I am missing?

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

1 Answers

1
votes

I get a 404 error when I try to access the documentation similar to how it is described in the documentation using url > http://localhost:8080/greetingservice/swagger-ui.html

You need to set your application context path as follows:

Create application.properties in src/main/resources and add the following line:

server.context-path=/greetingservice

Reference:

http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html