question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support WebJars directly in Jersey

See original GitHub issue

This is half question and half (potential) bug report. I’ve inquired about the problem in the webjars-locator project and was directed here.

I’m trying to get swagger-ui working in a version agnostic manner inside of Spring Boot with Jersey and Tomcat. According to the WebJars documentation, having a pom.xml similar to the following should allow me to access swagger-ui via http://localhost:8080/webjars/swagger-ui/ but it only works via http://localhost:8080/webjars/swagger-ui/3.6.1.

<dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jersey</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>
    <dependency>
      <groupId>org.webjars</groupId>
      <artifactId>swagger-ui</artifactId>
      <version>3.6.1</version>
    </dependency>
    <dependency>
      <groupId>org.webjars</groupId>
      <artifactId>webjars-locator</artifactId>
      <version>0.32-1</version>
    </dependency>
</dependencies>

Is there anything special I’d need to do to get webjars-locator working in this situation? It works just fine in spring-boot-starter-web which leads me to believe this is potentially a bug.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
w4tsoncommented, Feb 14, 2018

I’ve managed to replicate some of the issue in a git repo. Instructions to reproduce are in the README.

I’ve done some analysis on this and would like to help fix.

As @philwebb mentioned the webjars functionality is getting implemented by org.springframework.web.servlet.resource.WebJarsResourceResolver. Unfortunately this is in the spring-mvc project and leverages the ResourceResolver mechanism which isn’t available to spring-jersey users.

I’ve dreamt up a couple of options

  1. Allow the servlet 3.0 convention to statically serve webjars
  2. A Jersey controller with regex of /webjars/.* to serve content
  3. A servlet/filter that does the same

By all accounts a servlet 3.0 should serve static files in the META-INF/resources directory. The webjars documentation explains as such. I just can’t get this to work. Tried adding in the Tomcat DefaultServlet and setting Jersey to be a Filter but no joy.

Can someone steer me in the right direction?

0reactions
bclozelcommented, Jun 7, 2019

While this feature would be useful to Jersey users, I think we can’t really address this properly in Spring Boot. Spring Framework supports WebJars in the context of the resource handling feature, supporting serving static resources, cache busting, HTTP cache headers, etc.

Spring Boot should auto-configure this feature, once it’s supported officially by Jersey. Closing this issue for now, we should reopen it once it’s available in Jersey.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Config Swagger-ui with Jersey - java - Stack Overflow
I have my web service on Tomcat. I have been able to integrate the swagger with Jersey. To integrate swagger-ui , based on...
Read more >
Jersey 2.25.1 User Guide - GitHub Pages
This is user guide for Jersey 2.25.1. We are trying to keep it up to date as we add new features. When reading...
Read more >
Simple Java RESTful Web Service with Jersey — JAX-RS ...
First, you need to know how to direct all the REST requests that are coming from your REST client to direct towards your...
Read more >
Build RESTful Service in Java using JAX-RS and Jersey ...
Java API for RESTful Web Services (JAX-RS), is a set if APIs to developer REST service. JAX-RS is part of the Java EE6,...
Read more >
Developing RESTful Web Services with JAX-RS (Jersey)
Jersey RESTful Web Services framework is an open source, ... RESTful Web Services in Java that provides support for JAX-RS APIs and serves ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found