Exception in Springboot maven Weblogic environment - maven

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.

Related

How to generate OpenAPI 3.0.0 instead of 3.0.1 for a Spring Boot application?

I am trying to generate the OpenAPI 3.0.0 for a Spring Boot application, but in Swagger UI I see OpenAPI version 3.0.1.
The following dependency is added in pom.xml:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.2.32</version>
</dependency>
In the output JSON, I see the following:
{"openapi":"3.0.1","info":{"title":"OpenAPI definition","version":"v0"}

spring boot application is failing to start when i enable swagger

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>

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>

Issue with Spring Data (Spring Boot) and Joda Time field mapping

I have some entities with Joda DateTime fields.
When trying to start the application, I get the following error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Map;
[...]
Caused by: java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Map;
at org.jadira.usertype.spi.shared.AbstractUserTypeHibernateIntegrator.integrate(AbstractUserTypeHibernateIntegrator.java:192) ~[usertype.spi-6.0.1.GA.jar:na]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:280) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
I tried to put
spring.jpa.properties.jadira.usertype.autoRegisterUserTypes=true
in the application.properties and it didn't work. So I added the Hibernate annotation into my entity class:
#Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime from;
and it didn't work.
My pom.xml (partial):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>6.0.1.GA</version>
</dependency>
<!-- Jackson json data bind -->
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</dependency>
I also tried Jadira usertype.core 6.0.0.GA, 5.0.0.GA and 4.0.0.GA but nothing changes. How can I fix that?
====================EDIT
Debugging led me to line 192 of the class AbstractUserTypeHibernateIntegrator
String isEnabled = (String)sessionFactory.getProperties().get("jadira.usertype.autoRegisterUserTypes");
My debugger says the value assigned to isEnabled is the "true". However, the execution jumps to the finally clause: ConfigurationHelper.setCurrentSessionFactory((SessionFactory)null)
The signature of SessionFactoryImplementor.getProperties() changed in 5.2 to return Map rather than Properties. This leads to a NoSuchMethodError if hibernate version is lower than that. And also make sure to use latest jadira jar which is compatible with Hibernate 5.2
Add these dependencies in your pom.xml
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>6.0.1.GA</version>
</dependency>
The reason for the above issue is that you forgot to add the entitiyManager dependency.
Try adding the below dependency
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.8.Final</version>
</dependency>
This is what worked for me with spring boot, the problem is that Spring boot version 1.5.4 data-jpa starter has hibernate-core and hibernate-entitymanager version 5.0.12 which is incompatible with jadira version 6.0.1.GA so we have to override these in pom.xml and provide version 5.2.0.Final at least ( I have used 5.2.10.Final in the code as this is the latest one at the time of writting).
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>6.0.1.GA</version>
</dependency>
<!-- Jackson json data bind -->
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</dependency>
<!-- Spring boot version 1.5.4 has hibernate-core 5.0.12 which is incompatible with jadira version 6.0.1.GA -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.10.Final</version>
</dependency>
<!-- Spring boot version 1.5.4 has hibernate-entitymanager 5.0.12 which is incompatible with jadira version 6.0.1.GA -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.10.Final</version>
</dependency>

Resources