Skip to content

@ApplicationPath is not working? #3935

@rider87

Description

@rider87

Hi,

I´m currently installing Swagger, but it seems the @ApplicationPath is not working as expected.

I have the following code:

@ApplicationPath("/service")
@Api( tags = "docs" )
@OpenAPIDefinition(info = @Info(
        title = "My application", 
        version = "1.0.0", 

)
public class SwaggerApplicationConfig extends Application {
	
}

In Web.xml:

<servlet-mapping>
		<servlet-name>javax.ws.rs.core.Application</servlet-name>
		<url-pattern>/service/*</url-pattern>
	</servlet-mapping>

Example Endpoint:

/**
 * Customer Endpoints
 */
@Path("/customer")
@Tag(name = "Customer", description = "Returns all information for customers")
public class CustomerWebservice {

	@GET
	@Path("/")
	@Produces(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "Returns all Customer", notes = "Returns Customer", response = Response.class)
	@ApiResponses(value = {
			@ApiResponse(responseCode = "200", description = "Successful, returning the value"),
			@ApiResponse(responseCode = "404", description = "Not found"),
			@ApiResponse(responseCode = "500", description = "Internal Server Error")
	})
	public Response findAllCustomers() {
		try {
				return Response.ok(customerDtoList, MediaType.APPLICATION_JSON)
					.build();

		} catch (Exception e) {
			LOGGER.error(ExceptionUtils.getFullStackTrace(e));

			ErrorMessage errorMessage = new ErrorMessage(e.getMessage(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
			return Response.status(Status.INTERNAL_SERVER_ERROR).entity(errorMessage).type(MediaType.APPLICATION_JSON)
					.build();
		}
	}

I´m using those libs:
`<dependency>
			<groupId>io.swagger.core.v3</groupId>
			<artifactId>swagger-jaxrs2</artifactId>
			<version>2.1.8</version>
		</dependency>
		<dependency>
			<groupId>io.swagger.core.v3</groupId>
			<artifactId>swagger-jaxrs2-servlet-initializer-v2</artifactId>
			<version>2.1.8</version>
		</dependency>

The json File is generated, but the URL is only:
http://localhost:8080/customer

But it should be:
http://localhost:8080/service/customer

Here in the Swagger GUI:
image

Any idea what needs to be changed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions