1. 程式人生 > >javax.validation.ValidationException: HV000183: Unable to initialize 'javax.el.ExpressionFactory'.

javax.validation.ValidationException: HV000183: Unable to initialize 'javax.el.ExpressionFactory'.

情景

使用hibernate bean validator ,生產環境執行專案正常,但使用單元測試時便丟擲異常。

錯誤資訊如下

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.(ResourceBundleMessageInterpolator.java:45)
at org.hibernate.validator.internal.engine.ConfigurationImpl.getDefaultMessageInterpolator(ConfigurationImpl.java:423)
at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:271)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1692)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1630)
… 39 more

方案

新增如下依賴:

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

參考:https://blog.csdn.net/u012043557/article/details/51365293

(個人實踐操作,僅供參考!)