spring boot application is failing to start when i enable swagger - spring

Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.data.rest.core.support.UnwrappingRepositoryInvokerFactory.(UnwrappingRepositoryInvokerFactory.java:57)
The following method did not exist:
org.springframework.plugin.core.PluginRegistry.of(Ljava/util/List;)Lorg/springframework/plugin/core/PluginRegistry;
The method's class, org.springframework.plugin.core.PluginRegistry, is available from the following locations:
jar:file:/C:/Users/182588/.m2/repository/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar!/org/springframework/plugin/core/PluginRegistry.class
The class hierarchy was loaded from the following locations:
org.springframework.plugin.core.PluginRegistry: file:/C:/Users/182588/.m2/repository/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.plugin.core.PluginRegistry
I have added below dependence in the pom.xml
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>

add this dependency, it may works
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<version>1.2.0.RELEASE</version>
</dependency>

Related

Correct the classpath of your application so that it contains a single, compatible version of io.jsonwebtoken.SignatureAlgorithm

I have an issue. Tried to change the versions (like it says on the internet), but it didn't help.I get this error when i try to deploy project using docker composer
Problem:
The method's class, io.jsonwebtoken.SignatureAlgorithm, is available from the following
locations:
jar:file:/app/libs/jjwt-0.9.1.jar!/io/jsonwebtoken/SignatureAlgorithm.class
jar:file:/app/libs/jjwt-api-0.11.2.jar!/io/jsonwebtoken/SignatureAlgorithm.class
It was loaded from the following location:
file:/app/libs/jjwt-0.9.1.jar
Console:
APPLICATION FAILED TO START
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
io.jsonwebtoken.security.Keys.hmacShaKeyFor(Keys.java:84)
The following method did not exist:
io.jsonwebtoken.SignatureAlgorithm.getMinKeyLength()I
The method's class, io.jsonwebtoken.SignatureAlgorithm, is available from the following locations:
jar:file:/app/libs/jjwt-0.9.1.jar!/io/jsonwebtoken/SignatureAlgorithm.class
jar:file:/app/libs/jjwt-api-0.11.2.jar!/io/jsonwebtoken/SignatureAlgorithm.class
It was loaded from the following location:
file:/app/libs/jjwt-0.9.1.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of io.jsonwebtoken.SignatureAlgorithm
This is my pom.xml :
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.11.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.2</version>
</dependency>
According to the documentation you only need the following dependencies:
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.11.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.2</version>
</dependency>
The missing class / method is Jwts.parserBuilder() still available but was probably moved between versions. Removing the import from the class and allowing your IDE to reimport it, should resolve this issue.
(see comments under question for context)

The following method did not exist: 'org.springframework.plugin.core.PluginRegistry org.springframework.plugin.core.PluginRegistry.of(java.util.List)'

pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!-- The Bad Boy -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<version>1.2.0.RELEASE</version>
</dependency>
</dependencies>
With these dependencies I get following error:
*************************** APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The
attempt was made from the following location:
org.springframework.data.rest.core.support.UnwrappingRepositoryInvokerFactory.<init>(UnwrappingRepositoryInvokerFactory.java:57)
The following method did not exist:
'org.springframework.plugin.core.PluginRegistry org.springframework.plugin.core.PluginRegistry.of(java.util.List)'
The method's class, org.springframework.plugin.core.PluginRegistry,
is available from the following locations:
jar:file:/home/md7zn4/.m2/repository/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar!/org/springframework/plugin/core/PluginRegistry.class
It was loaded from the following location:
file:/home/md7zn4/.m2/repository/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a
single, compatible version of
org.springframework.plugin.core.PluginRegistry
If I delete Hal Browser Dependency everything works fine:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
I have tried to update spring-plugin-core to 2.0.0-RELEASE but this time I get the following error:
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
springfox.documentation.spring.web.plugins.DocumentationPluginsManager.createContextBuilder(DocumentationPluginsManager.java:152)
The following method did not exist:
'org.springframework.plugin.core.Plugin org.springframework.plugin.core.PluginRegistry.getPluginFor(java.lang.Object, org.springframework.plugin.core.Plugin)'
The method's class, org.springframework.plugin.core.PluginRegistry, is available from the following locations:
jar:file:/home/md7zn4/.m2/repository/org/springframework/plugin/spring-plugin-core/2.0.0.RELEASE/spring-plugin-core-2.0.0.RELEASE.jar!/org/springframework/plugin/core/PluginRegistry.class
Also I check this.
I think there is a conflict on spring-plugin-core
How can fix this?
Cause
When this error is displayed:
The following method did not exist:
'org.springframework.plugin.core.PluginRegistry org.springframework.plugin.core.PluginRegistry.of(java.util.List)'
It means spring-plugin-core 1.2.0 is in effect. This is good for springfox-swagger2 v2.9.2, however, some other components can't find PluginRegistry.of(java.util.List) in spring-plugin-core, because it is defined in a later version.
When this error is displayed:
The following method did not exist:
'org.springframework.plugin.core.Plugin org.springframework.plugin.core.PluginRegistry.getPluginFor(java.lang.Object, org.springframework.plugin.core.Plugin)'
It means spring-plugin-core 2.0.0 is in effect. This time, springfox-swagger2 v2.9.2 runs into problem because PluginRegistry.getPluginFor(java.lang.Object, org.springframework.plugin.core.Plugin) is removed from this version.
Solution
You may resolve this issue by using the snapshot version of springfox library. It has been upgraded to use the newer version of spring-plugin-core.
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
Please add the repository definition in order to use this snapshot version:
<repositories>
<repository>
<id>jcenter-snapshots</id>
<name>jcenter</name>
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
</repository>
</repositories>
Please also replace #EnableSwagger2 with #EnableSwagger2WebMvc.
Spring Plugins version is low, add this to pom.xml.
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
you can find similar issue here: https://github.com/springfox/springfox/issues/2968
In my case I just upgrade my swagger version, and it worked.
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
I faced the same problem and this is what worked for me-
1.Use HAL explorer instead of HAL browser
2.Update springfox dependency version
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-explorer</artifactId>
</dependency>
<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>2.9.2</version>
</dependency>
either run maven dependency tree command to see that which two jars are included and remove one or an easier way is to delete .m2 folder and re import the dependencies it will fix the issue.

Spring Boot and the new Swagger design

I have Swagger library in Spring Boot project and I added it using the following dependency:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
Currently Swagger UI looks like on screenshot below:
On the Swagger's site I see a bit another design and it looks better:
How can I add same design to my project? Thanks!
In order to get the new Swagger design just need to change dependency version from 2.7.0 to 2.8.0 or upper
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
Refresh your browser cache with Ctrl-F5 to be sure you have picked up the changes.

Wrong mapping swagger ui

I tried to view the api documentation generated by swagger with springfox on the link localhost:8081/swagger-ui.html but I received the error configuration/ui Failed to load resource: the server responded with a status of 404 (Not Found).
I checked and I found the correct url for configuration/ui is swagger-resources/configuration/ui.
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.4.0</version>
</dependency>
How I can resolv this bad mapping?
Change both the swagger version to 2.7.0
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>

Exception in Springboot maven Weblogic environment

After adding Swagger2 in Spring Boot application an error is generated which says java.lang.NoSuchMethodError: com.google.common.collect.Multimaps.asMap(Lcom/google/common/collect/ListMultimap;)Ljava/util/Map;
1 ) Dependency for swagger is shown below.
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version> <scope>compile</scope> </dependency>
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version> <scope>compile</scope> </dependency>
2) JPA version 2.1 is used
3)WebLogic Server Version: 12.1.3.0.0 is Used
4)maven
Please provide me a solution for this exception.

Resources