Conflict between spring annotation transaction proxy and struts2 chain

Source: Internet
Author: User

First look at simple code

An action class

Package com. snil. quanzi. Action;

@ Scope ("prototype ")
@ Controller ("teizimanager_tran ")
Public class tiezimanager_tran extends actionsupport implements preparable
{
Private Final Static logger = Logger
. Getlogger (tiezimanager_tran.class );
Private integer zhutiid;
Private integer quanziid;
Private zhuizhui= new zhui ();

@ Transactional
(
Rollbackfor = {exception. Class },
Propagation = propagation. required)
Public String publishzhti ()
{
Return success;
}

 

Public String findsomething ()

{

Return success;

}

 

 

 

 

 

 

@ Resource (name = "basedao ")
Protected ibasedao basedao;
Private httpservletrequest request = NULL;
Private httpservletresponse response = NULL;
Private httpsession session = NULL;
Private Huiyuan = NULL;
Public void prepare () throws exception
{
This. Request = servletactioncontext. getrequest ();
This. Response = servletactioncontext. getresponse ();
This. Session = This. Request. getsession (false );
This. Huiyuan = (Huiyuan) Session. getattribute ("user ");
 
}
Public void setbasedao (ibasedao basedao)
{
This. basedao = basedao;
}
Public integer getzhutiid ()
{
Return zhutiid;
}
Public void setzhutiid (integer zhutiid)
{
This. zhutiid = zhutiid;
}
Public zhuigetzhui ()
{
Return zhui;
}
Public void setzhui( zhuizhui)
{
This. zhui= zhui;
}
Public integer getquanziid ()
{
Return quanziid;
}
Public void setquanziid (integer quanziid)
{
This. quanziid = quanziid;
}
}

 

The above code has two actions: publishzhuiand findsomething. publishzhuiis transactional (annotations of things through spring, and do not ask why I add transactions at the control layer ).

At this time, when another action is called through the chain method through findsomethong, classcastexcetion: Package com. snil. quanzi. Action. tiezimanager.

At that time, it was suspected that things caused problems caused by spring's use of cglib to generate proxies. Because the control layer, that is, action, cannot use dynamic proxy

Because a transaction is added, spring uses cglib to generate a proxy for it. In this way, the above error occurs.

But what is the internal mechanism?

The actions used in struts2 here are all managed by spring. Since spring generates a proxy, it should be the proxy assigned to struts, that is, it has nothing to do with the original class. Why does it throw this exception?

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.