Getting "Finished Loading Resource Information. Rendering Swagger UI..." on loading swagger after migration from spring to sprinboot - spring-boot

We just migrated our application from Spring to Sprinboot (2.7.0). whenever i load swagger, all the apis dont get loaded and i get this line "Finished Loading Resource Information. Rendering Swagger UI..." on the top.
But http://host:port/v2/api-docs loads all the apis.
earlier we have below swagger related dependencies in our pom.xml
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${version.io.springfox}</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.6.8</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.6.8</version>
</dependency>
dependencies. I tried with that, i got same issue.
Later i tried adding springfox-boot-starter dependency and commenting out specific swagger based spring dependencies but no luck. I tried to search for a solution but couldnt find anything concrete.
Any idea why this is happening?

Related

WhiteLabel error page while trying to access swagger-ui.html using springfox configuration

I am trying to generate Swagger documentation from a springboot project using Springfox and following https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api documentation.
Initially I got the error "Full authorization is required to access the resource" since I am using OAuth2 in my application. I changed the configuration to permit all the requests ending with /swagger-ui.html.
Now I have been getting "WhiteLabel error page - This application has no explicit mapping for /error" while trying to access /swagger-ui.html on my local.
I went through various posts but none of the solutions worked for me - I am not using #webmvcconfiguration which can interfere.
Can anyone help?
For Swagger 3.0, The URL is changed to
http://localhost:8080/swagger-ui/index.html
Remove the v2 dependencies from your pom.xml or comment them out.
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
Add the springfox-boot-starter
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
Change the URL in your browser to:
http://localhost:8080/swagger-ui/index.html
The general form for the URL is:
http://host/context-path/swagger-ui/index.html
OR
http://host/context-path/swagger-ui/
For more info check this link that leads to the relevant documentation:
https://springfox.github.io/springfox/docs/snapshot/#changes-in-swagger-ui
This is how I solved my problem. Here is my detailed code, if someone want to look.
https://github.com/xbox2204/SpringBoot-JPA-Swagger
Now, I used 3.0.0-SNAPSHOT and a latest spring-boot starter project I created from here:
https://start.spring.io/
My pom.xml, I added following dependencies:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
In my application.properties, I added following:
spring.resources.add-mappings=true
In my SpringBoot Main/Runner class, I added these annotations
#EnableWebMvc
#EnableSwagger2
#SpringBootApplication
My Docket returning function looked like this
#Bean
public Docket productApi() {
Contact contact =new Contact(
"Vineet Mishra",
"https://github.com/xbox2204",
"whatwillyoudo#withmyemail.com"
);
ApiInfo apiInfo= new ApiInfoBuilder().title("VINEET SPRING-BOOT API")
.description("Spring-Boot for all")
.termsOfServiceUrl("jUST CHILL!!!")
.contact(contact)
.licenseUrl("something#something.com").version("1.0").build();
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo)
.select()
.apis(RequestHandlerSelectors.any())
.build();
}
Finally, I accessed my swagger-ui from
http://localhost:8080/swagger-ui/index.html#
Image of final result
The swagger-ui.html page makes a number of calls to get all the details. If you use your browser's dev tools (usually just press F12 to open) you will see failing requests in the network tab. You'll need to permit requests to
"/v2/api-docs",
"/swagger-resources/**",
"/swagger-ui.html**",
"/webjars/**"
There's some info in the springfox docs , do a find for 'security' or 'authorization'

Spring Boot No Class found error though starter dependency has added classes in classpath

Despite having appropriate jars in classpath Spring Boot throws - java.lang.ClassNotFoundException: org.apache.camel.spring.spi.XmlCamelContextConfigurer
Any suggestions what is missing here.
I have added the respective starters in pom.xml as shown below:
<dependency>
<groupId>org.springframework.boot</groupId>[![enter image description here][1]][1]
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.19.3</version>
</dependency>
The project maven dependencies also shows the class availability, as in given image attachment.
the answer is here - https://stackoverflow.com/a/34271507/2885422 It all depends how maven loads the class. There are 2 version of camel-spring.jars available in classpath (2.20.1 and 2.19.3. Ref: my original post image)
And org.apache.camel.spring.spi.XmlCamelContextConfigurer class is available only in 2.20.1 jars. And maven by default looks in earlier one and once package found matching but no class found throws error (?)
And the reason I believe 2.19.3 get loaded is Apache-cxf jars is of 2.19.3. Unfortunately our project repository does not have apache-cxf starter jars.
https://stackoverflow.com/a/34271507/2885422
Solution: - I hope it may be helpful for future references
By adding options I could resolve the issue,by having exclusion clause added as given below. Thus I could load only required version jars.
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.19.3</version>
<exclusions>
<exclusion>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</exclusion>
</exclusions>
</dependency>'

Changing Name and Description endpoint in Swagger-ui

I am using Spring boot and Spring Data Rest to implement my Rest API. To document it, I have been using Swagger, with these maven dependencies:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-data-rest</artifactId>
<version>2.6.1</version>
</dependency>
I would like to change and customize a bit my Swagger UI page. I want to change the name and the description it appears in the html page, concretely these names highlighted in red in the screenshot, but nothing works.
I've been trying adding the #Api annotation to my entities and repositories classes/interfaces, but nothing works.
Any idea about how to customize it?
Thanks!
Use the #Api annotation with tags and description.
#Api(description="Device APIs", tags = "Device")
Please note that description is deprecated but it works.

Maven Webjars - bootstrap-datepicker makes bootstrap invisible

I've tried to use Bootstrap and Bootstrap-Datepicker in my SpringMVC project:
GitHub repo
I trying to include both Bootstrap and Bootstrap-Datepicker via WebJars like this:
<!-- WebJars -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap-datepicker</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>1.10.2</version>
</dependency>
When I comment out the bootstrap-datepicker dependency in pom.xml, the browser is throwing errors in the console like this:
GET http://localhost:8080/finager/webjars/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker.js 404 (Not Found)
This is working as expected. When I leave boostrap-datepicker section uncommented, the browser starts to see bootstrap-datepicker files, also as expected. Unfortunately, the browser console starts to throw similar errors saying that now Bootstrap files are not visible! It seems that boostrap-datepicker is somehow overriding Bootstrap.
I've tried to change my includes order and still the same effect. All of my .jsp files (CSS and JS includes) seem to be valid, because Bootstrap is visible when Maven does not try to include the datepicker. Is there a simple way to check what is visible in my webjars folder after compilation?
I am very confused. I couldn't find any useful information on the Internet. I've spent whole day on this, so any help would be hugely appreciated. Thanks in advance!
As always, the solution came up to my mind right after posting the question. It seems that Maven detected that bootstrap-datepicker was depending on bootstrap. I suppose that it included Bootstrap in different version in result - that would explain everything.
However, this is the solution:
<!-- WebJars -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap-datepicker</artifactId>
<version>1.3.0</version>
<exclusions>
<exclusion>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.1.0</version>
</dependency>
Is anybody aware of simple solution to browse /webjars directory structure after the Maven compilation? This would prevent such issues.

multiple SLF4J bindings Error with activemq-all-5.6.0.jar

When I upgrade to activemq-all-5.6.0
I get this error during server startup
SLF4J: Class path contains multiple SLF4J bindings
I don't have this issue when using activemq-all-5.5.1
On checking I do find that there StaticLoggerBinder.class in both activemq-all-5.6.0.jar and slf4j-log4j12-1.5.10.jar which is causing the issue
Please do help in debugging this issue
My pom.xml is as follows
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.10</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.5.10</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.10</version>
<scope>runtime</scope>
</dependency>
The active mq dependency is like this
Old Version 5.5.1 (This works)
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.5.1</version>
</dependency>
New Version 5.6.0 (This gives the error)
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.6.0</version>
</dependency>
Thanks in advance.
The ActiveMQ guys use the Maven Shade Plugin to create the activemq-all "ueber" jar. Somewhere between version 5.5.1 and 5.6.0 they added the org.slf4j:slf4j-log4j12 dependency - hence your problem.
Unfortunately because they used the shade plugin you can not use exclusions in your activemq-all dependency definition in your POM.
Instead you will need to completely replace the activemq-all dependency with all the required individual dependencies (except of course the org.sl4j-log4j12 one).
The following page details all the required dependencies:
http://activemq.apache.org/initial-configuration.html#InitialConfiguration-RequiredJARs
Alternatively the following is the list of all dependencies (required and optional) included in the activemq-all jar (taken from the configuration of the shade plugin in the activemq-all pom):
org.apache.activemq:activemq-camel
org.apache.activemq:activemq-core
org.apache.activemq:activemq-console
org.apache.activemq:activemq-jaas
org.apache.activemq:activemq-optional
org.apache.activemq:kahadb
org.apache.geronimo.specs:geronimo-jms_1.1_spec
org.apache.geronimo.specs:geronimo-jta_1.0.1B_spec
org.apache.geronimo.specs:geronimo-j2ee-management_1.1_spec
org.apache.geronimo.specs:geronimo-annotation_1.0_spec
org.slf4j:slf4j-api
org.slf4j:slf4j-log4j12
log4j:log4j
Hope that helps.
I had the same problem while using Spring. What helped me was replacing the dependency of activemq-all with:
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-spring</artifactId>
<version>5.14.3</version>
</dependency>
Hope this will help anyone...

Resources