javax.validation.ValidationException Error - spring

Error:
Caused by: javax.validation.ValidationException: HV000183: Unable to initialize 'javax.el.ExpressionFactory'. Check that you have the EL dependencies on the classpath, or use ParameterMessageInterpolator instead
I am using Spring boot 2.6.6 Version
Pom.xml:
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.17.Final</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
</dependency>
I followed couple of posts, but couldn't help. It would be nice if any one suggests why the error is thrown & what could be fix for it.
References I followed:
Hibernate validation "Unable to initialize javax.el.ExpressionFactory" error
javax.validation.ValidationException: HV000183: Unable to load 'javax.el.ExpressionFactory'

Related

Spring-Boot 2.1.2 and class com.fasterxml.jackson.annotation.JsonInclude

My Sprint boot application is not coming up because it's complaining about missing class com.fasterxml.jackson.annotation.JsonInclude$Value, but I have jackson library as dependency, so I think it might be possible some conflict.
SPRING LOG:
:: Spring Boot :: (v2.1.2.RELEASE)
00:22:54.084 [main ] ERROR ngframework.boot.web.embedded.tomcat.TomcatStarter - Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'formContentFilter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedFormContentFilter]: Factory method 'formContentFilter' threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.fasterxml.jackson.annotation.JsonInclude$Value
00:22:55.063 [main ] ERROR org.springframework.boot.SpringApplication - Application run failed
pom.xml (dependencies):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.1.2.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.4</version>
</dependency>
Has anybody already faced similar issue?
Thanks
jackson-core,jackson-annotations and jackson-databind jars are automatically added by spring boot.
so you don't need to add them explicitly unless you want to override the version of the jar that are provided by spring boot .
Use the below version for both the artefacts:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.10.0.pr1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.4</version>
</dependency>
Also, update the maven-compiler-plugin version to the latest if maven build fails.
Jackson has made some changes in the method signature of class ObjectMapper, handle the same if implemented.

Integrate Keycloak Admin Client 3.1.0.Final with Spring Boot 1.5.1

I'm trying to integrate KeyCloak Admin Client with Spring Boot
But there is an exception is thrown when I was trying to create a new account:
Caused by: javax.ws.rs.ProcessingException: RESTEASY003145: Unable to find a MessageBodyReader of content-type application/json and type class org.keycloak.representations.AccessTokenResponse
So I tried to explicitly register Jackson Provider for KeyCloak like this:
KeycloakBuilder
.builder()
.serverUrl(SERVER_URL)
.realm(REALM)
.username(USERNAME)
.password(PASSWORD)
.clientId(CLIENT_ID)
.resteasyClient(new ResteasyClientBuilder()
.providerFactory(factory.register(ResteasyJackson2Provider.class))
.connectionPoolSize(10)
.build())
.build();
But I'm unable to import ResteasyJackson2Provider.class
pom.xml
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-security-adapter</artifactId>
<version>3.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
<version>3.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.1.3.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.1.3.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>3.1.3.Final</version>
</dependency>
Btw, if I use resteasy-jackson-provider, I got this exception:
javax.ws.rs.client.ResponseProcessingException: javax.ws.rs.ProcessingException: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "access_token" (Class org.keycloak.representations.AccessTokenResponse), not marked as ignorable
at [Source: org.jboss.resteasy.client.jaxrs.internal.ClientResponse$InputStreamWrapper#7cc842b0; line: 1, column: 18] (through reference chain: org.keycloak.representations.AccessTokenResponse["access_token"])
After a while, I figured out the solution to this problem:
Firstly, I tested it out with the standalone project (empty maven project), the problem still occurs because of resteasy-jackson-provider. It should be resteasy-jackson2-provider (note that its resteasy-jackson2-provider)
For now, I was known that the problem somehow comes from Spring Boot, RESTeasy. And finally, I come up with this working pom.xml:
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
<version>3.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.1.3.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>3.1.3.Final</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.8.8</version>
</dependency>
One more thing to note is, you should use the admin-cli client in your Keycloak, because by default, it has Direct Access Grants Enabled on
Btw, this is the Java configuration:
KeycloakBuilder
.builder()
.serverUrl("localhost:8080/auth")
.realm("master")
.username("YOUR_USERNAME")
.password("YOUR_PASSWORD")
.clientId("admin-cli")
.build();
Working example: https://github.com/phuongtailtranminh/Keycloak-Admin-Client-Spring-Boot-Demo

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>

Dependency clash between Apache CXF and Kie Remote Client

I'm currently writing an Apache Camel project that's using CXF to expose some REST endpoints and Kie Remote Client to interface with BPMS. However, I'm getting a dependency clash (not sure how to describe it) when I try to include the Kie Remote Client dependency into my pom file.
Here's my pom file currently:
<dependencies>
<!-- Camel Dependencies -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
<version>2.15.2</version>
</dependency>
<!-- Spring Web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.12</version>
</dependency>
<!-- <dependency>
<groupId>org.kie</groupId>
<artifactId>kie-parent-with-dependencies</artifactId>
<version>6.2.0.Final-redhat-4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.kie.remote</groupId>
<artifactId>kie-remote-client </artifactId>
<version>6.2.0.Final-redhat-4</version>
<scope>provided</scope>
</dependency> -->
</dependencies>
When I try to deploy my project I'm getting some property exceptions:
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (2) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'serviceBeans' threw exception; nested exception is java.lang.NoSuchMethodError: org.apache.cxf.jaxrs.JAXRSServerFactoryBean.addToBeans(Ljava/util/Collection;Ljava/lang/Object;)V
PropertyAccessException 2: org.springframework.beans.MethodInvocationException: Property 'providers' threw exception; nested exception is java.lang.NoSuchMethodError: org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean.addToBeans(Ljava/util/Collection;Lj ava/lang/Object;)V
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractProp ertyAccessor.java:121) [spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75) [spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.appl yPropertyValues(AbstractAutowireCapableBeanFactory.java:1510) [spring-beans- 4.1.6.RELEASE.jar:4.1.6
Anyone know what's the root cause of this error? Thanks!
EDIT: I did find a temporary workaround to this problem. If I downgrade my camel versions to 2.13.2 and my spring versions to 3.2.8-RELEASE then the apache-cxf versions seem to aligh. However there are many new features that I need in 2.15.2 camel that I would like to keep. Anyone know of any good alternatives to kie.remote.client?
Kie remote client add the jaxb-impl-2.2.5.jar dependency, in collition with jaxb-core-2.2.11.jar and jaxb-impl-2.2.11.jar from cxf.
just remove the jaxb-impl from you deploy. (or use maven exclusion in dependency of kie-client) it's works for me.

Apache Wink integration with Spring

I am trying to integrate Apache wink 1.4 with Spring on JBoss EAP 6.4. Below is my Pom.xml excerpt.
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-server</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-spring-support</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-client</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-json4j</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.jboss.archetype.eap</groupId>
<artifactId>jboss-javaee6-webapp-archetype</artifactId>
<version>6.4.0.GA</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
I also have configuration in web.xml to look for winkdefault.properties.
While building the application, It is not able to find the "META-INF/wink-default.properties" I am getting following exception in server log.
[org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 96) Context initialization failed: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [META-INF/wink-default1.properties]; nested exception is java.io.FileNotFoundException: class path resource [META-INF/wink-default.properties] cannot be opened because it does not exist
Could anyone help on this please ?
I decompiled wink-spring-support.jar and changed context with following classpath:META-INF/server/wink-core-context.xml and it was able to register.

Resources