spring-attic / spring-hadoop-samples

Spring Hadoop Samples
Apache License 2.0
492 stars 466 forks source link

Unable to initialize 'javax.el.ExpressionFactory' after update Spring Boot to 1.5.2 #30

Open MichalMichalak opened 7 years ago

MichalMichalak commented 7 years ago

Hello. I am not sure this is the right place to open an issue. If it's not, I'd gladly appreciate if you could share the right person / project.

We are using Spring Boot and Hadoop as shown in Gradle script below.

plugins {
    // before update it was: '1.4.4.RELEASE'
    id 'org.springframework.boot' version '1.5.2.RELEASE'
}
dependencies {
    compile 'org.springframework.data:spring-data-hadoop-boot:2.4.0.RELEASE-cdh5'
}

When trying to get validator, we got following exception.

import javax.validation.Validator;
class Utils {
    Validator v = Validation.buildDefaultValidatorFactory().getValidator();
}
java.lang.ExceptionInInitializerError
    at com.rakuten.felix.listnormalizer.broker.MessageProcessor.handleIncomingMessage(MessageProcessor.java:110)
    at com.rakuten.felix.listnormalizer.test.broker.MessageProcessorTest.handleIncomingMessageTest(MessageProcessorTest.java:115)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:498)
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
    at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.buildExpressionFactory(ResourceBundleMessageInterpolator.java:102)
    at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.<init>(ResourceBundleMessageInterpolator.java:45)
    at org.hibernate.validator.internal.engine.ConfigurationImpl.getDefaultMessageInterpolator(ConfigurationImpl.java:423)
    at org.hibernate.validator.internal.engine.ConfigurationImpl.getDefaultMessageInterpolatorConfiguredWithClassLoader(ConfigurationImpl.java:575)
    at org.hibernate.validator.internal.engine.ConfigurationImpl.getMessageInterpolator(ConfigurationImpl.java:364)
    at org.hibernate.validator.internal.engine.ValidatorFactoryImpl.<init>(ValidatorFactoryImpl.java:144)
    at org.hibernate.validator.HibernateValidator.buildValidatorFactory(HibernateValidator.java:38)
    at org.hibernate.validator.internal.engine.ConfigurationImpl.buildValidatorFactory(ConfigurationImpl.java:331)
    at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:110)
    at com.rakuten.felix.listnormalizer.ValidatorUtils.<clinit>(ValidatorUtils.java:11)
    ... 4 more
Caused by: javax.el.ELException: Provider com.sun.el.ExpressionFactoryImpl not found
    at javax.el.FactoryFinder.newInstance(FactoryFinder.java:101)
    at javax.el.FactoryFinder.find(FactoryFinder.java:197)
    at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:189)
    at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:160)
    at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.buildExpressionFactory(ResourceBundleMessageInterpolator.java:98)
    ... 13 more
Caused by: java.lang.ClassNotFoundException: com.sun.el.ExpressionFactoryImpl
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at javax.el.FactoryFinder.newInstance(FactoryFinder.java:87)
    ... 17 more

After an investigation we found out that two javax.el.ExpressionFactory classes exist in class path. One from tomcat-embed-el:8.5.11 and other from jsp:jsp-api:2.1. I assumed jsp-api contains old version of ExpressionFactory class and excluded JSP API, which solved the issue.

The question is - shouldn't this be solved in Spring itself? Since I wasn't excluding anything before and it was working fine, I would expect the same behavior after update. Any ideas how to proceed with this? Thank you.

whitfin commented 7 years ago

I found this issue whilst looking for something similar I was seeing with Hadoop. This leads me to believe it's coming from the Hadoop libraries rather than the Spring libraries?

It's weird though, excluding JSP API didn't fix it for me.

bric3 commented 6 years ago

Foud this issue after upgrading a simple spring boot web project as well.

MichalMichalak commented 6 years ago

I may be wrong here, but since it's Spring's library it should be fixed by Spring team. Either exclude conflicting libs, maybe create some custom package instead, etc. OR they should communicate with Apache and solve the issue together / ask them to use different version.

digz6666 commented 6 years ago

Try include following to your dependencies:

<dependency>
    <groupId>javax.el</groupId>
    <artifactId>javax.el-api</artifactId>
    <version>3.0.0</version>
</dependency>
<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.el</artifactId>
    <version>3.0.0</version>
</dependency>