如何将 dcevm 与 tomcat 和 eclipse 一起使用 我下载了 jdk6u25 并设置 tomcat7 在 eclipse juno 中使用它,然后当我更改托管 bean 中的任何内容时,它可以工作,但没有考虑 xhtml 中的更改
我认为问题出在tomcat
您至少必须清理 BeanElResolver 和 ElMethodCache。以下示例用于 jboss-el 实现:
private void clearJbossElMethodCache() {
try {
Field cacheField = getField(org.jboss.el.util.ReflectionUtil.class, "methodCache");
cacheField.setAccessible(true);
Object cache = cacheField.get(null);
Method m = cache.getClass().getMethod("clear");
m.invoke(cache);
}
catch (Exception e) {
}
}
public void clearBeanElResolver() {
BeanELResolver beanELResolver = getSeamBeanELResover();
doCleanBeanElResolver(beanELResolver);
doCleanBeanElResolver(ELUtils.BEAN_RESOLVER);
java.beans.Introspector.flushCaches();
}
private void doCleanBeanElResolver(BeanELResolver beanELResolver) {
try {
try {
Field cacheField = getField(beanELResolver.getClass(), "cache");
cacheField.setAccessible(true);
Object cache = cacheField.get(beanELResolver);
try {
Method m = cache.getClass().getMethod("clear");
m.invoke(cache);
} catch (NoSuchMethodException e)
{
Class<?> cacheClass = getClass().getClassLoader().loadClass("javax.el.BeanELResolver$ConcurrentCache");
Constructor<?> con = cacheClass.getConstructor(int.class);
con.setAccessible(true);
Object cacheInstance = con.newInstance(100);
cacheField.set(beanELResolver, cacheInstance);
}
}
catch (NoSuchFieldException ee) {
Field props = getField(beanELResolver.getClass(), "properties");
props.setAccessible(true);
Object cache = props.get(beanELResolver);
Method m = cache.getClass().getMethod("clear");
m.invoke(cache);
}
}
catch (Exception e) {
}
}
private BeanELResolver getSeamBeanELResover() {
if (EL.EL_RESOLVER instanceof CompositeELResolver) {
CompositeELResolver compositeElResolver = (CompositeELResolver) EL.EL_RESOLVER;
try {
Field elResolvesField = getField(CompositeELResolver.class, "resolvers");
elResolvesField.setAccessible(true);
ELResolver elResolvers[] = (ELResolver[]) elResolvesField.get(compositeElResolver);
for (ELResolver elResolver: elResolvers) {
if (elResolver instanceof BeanELResolver) {
return (BeanELResolver) elResolver;
}
}
}
catch (Exception e) {
}
}
return null;
}