起因
自己在玩着自己的jbpm4.4的demo,但是到暂停流程时候,出现了这个错误。
demo是ssh(spring3 +spring mvc +hibernate3)+jbpm4.4
解决方法
因为报错的实体类是jbpm的jar内置的,所以没没办法关闭这个实体类的lazy加载。于是选择使用OpenSessionInView
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
但是有报错
No WebApplicationContext found: no ContextLoaderListener registered?
发现缺少监听,于是补充
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
但是启动后发现
Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
原来监听器默认的是/WEB-INF/applicationContext.xml,还需要配置context-param
加入
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-servlet.xml</param-value>
</context-param>
可是,发现还是不行,网上基本都是这个方法,那到底是错误在哪呢
终于在我多次尝试下,发现原来是事务的锅
再加入
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" isolation="READ_COMMITTED" rollback-for="java.lang.Exception"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="pc" expression="execution(* com.hyc.ssh..*.*Service.*(..))" />
<aop:advisor pointcut-ref="pc" advice-ref="txAdvice" />
</aop:config>
终于可以运行了
如果你也是报could not initialize proxy - no Session,在加入OpenSessionInViewFilter还是不行的话,不妨再修改下事务试试