在Glassfish中使用来自急切获取的JSF托管bean的springbean的问题



我正在使用JSF 2.0和Spring 3.0.5进行一个项目,该项目在Glassfish 3.1开源版上运行。然后我有一个ApplicationScoped托管bean,用"热切"声明:

@ManagedBean(eager = true)
@ApplicationScoped
public class CommonMB

其具有使用EL:注入的托管属性

@ManagedProperty(#{foo})
private Foo foo;

然后在Spring上下文文件中配置foo

<bean id="foo" class="Foo" />

最后在faces-config.xml中配置Spring-EL解析器:

<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>

毕竟,当我启动Glassfish时,会抛出异常,表明托管属性没有正确注入:

Caused by: com.sun.faces.mgbean.ManagedBeanCreationException: unable to set property 'foo' on managed bean 'commonMB'
at com.sun.faces.mgbean.ManagedBeanBuilder$BakedBeanProperty.set(ManagedBeanBuilder.java:615)
at com.sun.faces.mgbean.ManagedBeanBuilder.buildBean(ManagedBeanBuilder.java:133)
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:104)
at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:256)
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:255)
... 76 more
Caused by: java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
at org.springframework.web.jsf.FacesContextUtils.getRequiredWebApplicationContext(FacesContextUtils.java:83)
at org.springframework.web.jsf.DelegatingVariableResolver.getWebApplicationContext(DelegatingVariableResolver.java:167)
at org.springframework.web.jsf.DelegatingVariableResolver.getBeanFactory(DelegatingVariableResolver.java:156)
at org.springframework.web.jsf.DelegatingVariableResolver.resolveSpringBean(DelegatingVariableResolver.java:134)
at org.springframework.web.jsf.DelegatingVariableResolver.resolveVariable(DelegatingVariableResolver.java:112)
at com.sun.faces.el.VariableResolverChainWrapper.getValue(VariableResolverChainWrapper.java:115)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at de.odysseus.el.tree.impl.ast.AstIdentifier.eval(AstIdentifier.java:84)
at de.odysseus.el.tree.impl.ast.AstEval.eval(AstEval.java:51)
at de.odysseus.el.tree.impl.ast.AstNode.getValue(AstNode.java:30)
at de.odysseus.el.TreeValueExpression.getValue(TreeValueExpression.java:122)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:55)
at com.sun.faces.mgbean.BeanBuilder$Expression.evaluate(BeanBuilder.java:591)
at com.sun.faces.mgbean.ManagedBeanBuilder$BakedBeanProperty.set(ManagedBeanBuilder.java:606)
... 82 more

由于我使用ContextLoaderListener来初始化Springbeans,并且从stackrace来看,当JSF开始在com.sun.faces.config.ConfigureListener中初始化JSFbeans时,Spring上下文尚未设置,这就是发生此异常的原因。

所以我想知道ConfigureListener(JSF)和ContextLoaderListener(Spring)之间的初始化顺序是否有问题,Spring listener应该在JSF listener之前,但它没有。此外,JSF监听器是在JSF impl中隐式配置的,我不知道如何更改它们的顺序。

顺便说一句,当它在Tomcat7上运行时,一切都很好,但在Glassfish 3.1上它就搞砸了。也许在调用监听器的顺序时,不同的容器实现有什么关系?

你知道这个问题吗?提前感谢!

当它在Tomcat7上运行时,一切都还可以,但在Glassfish 3.1上,它把搞砸了

你检查了项目的依赖关系吗?afaik-tomcat7不提供jsf2.0开箱即用的支持

对于正确的配置,这个春季论坛线程可能会很有用http://forum.springsource.org/showthread.php?86577-Spring-3-JSF-2&p=290645#邮政290645

相关内容

  • 没有找到相关文章

最新更新