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?