could not initialize proxy - no Session

起因

自己在玩着自己的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还是不行的话,不妨再修改下事务试试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值