如何在Google App Engine中创建javax.el.ExpressionFactory以使用Hibernate Validator [英] How to create javax.el.ExpressionFactory in Google App Engine to use Hibernate Validator
问题描述
我正在尝试在我的Google App Engine应用程序上升级到休眠验证器版本6,该版本
I'm trying to upgrade to hibernate validator version 6 on my Google App Engine app, which needs javax.el, so I added org.glassfish:javax.el:jar:3.0.1-b10
to my dependencies.
但是,这是不使用的:
在本地开发环境中,我可以使用ExpressionFactory.newInstance()
创建一个新的ExpressionFactory
. ExpressionFactory
来自本地Jetty安装jetty93/jetty-distribution/lib/apache-jsp/org.mortbay.jasper.apache-el-8.0.33.jar
,它从同一jar返回实现org.apache.el.ExpressionFactoryImpl
.
In the local dev environment, I can create a new ExpressionFactory
with ExpressionFactory.newInstance()
. The ExpressionFactory
is from the local Jetty installation jetty93/jetty-distribution/lib/apache-jsp/org.mortbay.jasper.apache-el-8.0.33.jar
and it returns the implementation org.apache.el.ExpressionFactoryImpl
from the same jar.
在已部署的GAE环境中,ExpressionFactory
来自java8_runtime/runtime-shared.jar!/javax/el/ExpressionFactory.class
,但是ExpressionFactory.newInstance()
仍然尝试获取org.apache.el.ExpressionFactoryImpl
,即使存在com.sun.el.ExpressionFactoryImpl
.
In the deployed GAE environment, the ExpressionFactory
is from java8_runtime/runtime-shared.jar!/javax/el/ExpressionFactory.class
but ExpressionFactory.newInstance()
still tries to get a org.apache.el.ExpressionFactoryImpl
, even though com.sun.el.ExpressionFactoryImpl
is present.
在两种环境中,我都可以从WEB-INF/lib/javax.el-3.0.1-b10.jar
手动加载com.sun.el.ExpressionFactoryImpl
,因此它出现在类路径中:
In both environments, I can manually load a com.sun.el.ExpressionFactoryImpl
from WEB-INF/lib/javax.el-3.0.1-b10.jar
, so it is present in the classpath:
final Constructor<ExpressionFactoryImpl> constructor = com.sun.el.ExpressionFactoryImpl.class.getConstructor();
final ExpressionFactoryImpl expressionFactory = constructor.newInstance();
- 即使参考实现
com.sun.el.ExpressionFactoryImpl
位于类路径上,为什么GAE环境仍如此热衷于加载org.apache.el.ExpressionFactoryImpl
? - 如何使GAE加载现有的
ExpressionFactoryImpl
,以便创建休眠的ValidatorFactory?我是否必须手动提供- Why is the GAE environment so keen on loading
org.apache.el.ExpressionFactoryImpl
even though the reference implementationcom.sun.el.ExpressionFactoryImpl
is on the classpath? - How can I make GAE load the existing
ExpressionFactoryImpl
so I can create a hibernate ValidatorFactory? Do I have to manually supply aMessageInterpolator
so I can supply the correctExpressionFactoryImpl
?
推荐答案
我终于通过在appengine-web.xml中添加系统属性来解决了这个问题:
I finally solved it by adding a system property to appengine-web.xml:
<system-properties> <property name="javax.el.ExpressionFactory" value="com.sun.el.ExpressionFactoryImpl" /> </system-properties>
另一种可能性是添加文件"META-INF/services/javax.el.ExpressionFactory",内容如下:
An other possibility could be to add the file 'META-INF/services/javax.el.ExpressionFactory' with the contents:
com.sun.el.ExpressionFactoryImpl
另请参见此答案
我没有测试第二种方法,但是它在apache-el ExpressionFactory的源代码中具有最高的优先级,而系统属性只是第三种尝试.
I didn't test the second method, but it has the highest priority in the source of apache-el ExpressionFactory, while the system property is only the third try.
这篇关于如何在Google App Engine中创建javax.el.ExpressionFactory以使用Hibernate Validator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- Why is the GAE environment so keen on loading