I'm running a Spring Boot application with Jetty
server. The APIs are served by the Jersey servlet
. The static contents are placed in src/main/static
and src/main/private-static
.
Issue#1 Static content in src/main/static
is not being served
The content in src/main/static
is public and can be accessed freely. According to this: https://docs.spring.io/spring-boot/docs/1.3.8.RELEASE/reference/html/boot-features-developing-web-applications.html#boot-features-spring-mvc-static-content Spring boot should automatically serve the static content, but it does not.
Issues#2 How to set the static content directory to src/main/private-static
for this custom servlet that checks for authentication before serving a file.
I've created another servlet
to serve static content with authentication
@Bean
public ServletRegistrationBean<HttpServlet> privateStaticContent() {
return new ServletRegistrationBean<>(new HttpServlet() {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
int status = isAuthenticated(req) ? 200 : 401;
resp.setStatus(status);
}
}, "/private-static/*");
}
Basically this servlet should serve files from the directory src/main/private-static
, but I'm not sure how and where to configure this.
Issue#3 To make Jersey serve at /api
endpoint, I've added this in application.properties
server.servlet.context-path=/api
But this makes all the servlets to use this /api
endpoint. How can I configure this only for Jersey servlet and not for others. Is there something like server.servlet.jersey.context-path=/api
?