faces-config.xml中
- org.springframework.web.jsf.DelegatingVariableResolver
的applicationContext.xml
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven />
<context:component-scan base-package="com.test"/>
index.xhtml
<h:outputText value="#{authBean.val}"/>
AuthBean.java
package com.test.ui;
@Component
@Scope("session")
public class AuthBean {
@Getter @Setter private String val;
@Transactional public void test(){} //works fine if @Transactional is removed
工作正常,但是当使用@Transactional注释方法时,会发生以下错误
16:23:13,906 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/jbtst].[Faces Servlet]] (http-localhost-127.0.0.1-8080-1) Servlet.service() for servlet Faces Servlet threw exception: javax.el.PropertyNotFoundException: /index.xhtml @14,49 value="#{authBean.val}": The class '$Proxy28' does not have the property 'val'.
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:111) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIOutput.getValue(UIOutput.java:169) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
使用spring-3.1,hibernate3
答案 0 :(得分:1)
当您使用@Transactional
时,Spring会创建一个代理,该代理实现与您的类相同的接口,但您的AuthBean
类不实现接口。
解决这个问题的最简单方法是使用val
属性定义一个接口并让AuthBean
实现该接口,然后代理也将具有val属性。
答案 1 :(得分:0)
这有助于annotation equivalent of <aop:scoped-proxy>
<context:component-scan base-package="com.test" scoped-proxy="targetClass" />