我们的项目架构使用 Struts 1 和 Struts 2 和 Spring 3。我正在尝试创建一个 Aspect 以更好地处理异常。Struts 1 直到现在还不是 Spring 管理的 - 所以我点击了这个链接How to integration an old Struts application with Spring 3.x to allow Spring component-scan to pick the Struts 1 Action。
编辑: - 版本
Struts 1 - org.apache.struts.struts-core (1.3.10) Struts 2 - org.apache.struts.struts2-core (2.0.9) Spring - 3.2.2
但我的方面类没有拿起它。我的 struts 2 动作或服务类没有任何问题。但我无法理解这里有什么问题。
异常方面类 -
package com.mnm.abc.aop;
public @Aspect @Component class ExceptionHandler {
@Pointcut("execution(public * abc.web.action.AbcAction+.doExecute(..))")
public void inStruts1Action() {
}
/* I tried the following too
* @Pointcut("within(abc.web.action.AbcAction+)")
* @Pointcut("execution(public * abc.web.action.AbcAction.execute(..))")
* @Pointcut("execution(public * abc.web.action.*.doExecute(..)) && within(abc.web.action.AbcAction+)")
*/
@After("inStruts1Action()")
public void after() {
System.out.println("After");
}
}
Struts 1 Action 类 -
package abc.web.action;
public @Component class TransactionAction extends AbcAction {
public @Override ActionForward doExecute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
System.out.println("Hi");
ActionForward forward = mapping.findForward("success");
return forward;
}
}
父类 -
package abc.web.action;
public abstract class AbcAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
try {
return doExecute(mapping, form, request, response);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
public abstract ActionForward doExecute(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception;
}
配置类 -
package com.mnm.abc.config;
@Configuration
@ComponentScan(basePackages = { "abc.web.action", "com.mnm.abc.aop" })
@EnableTransactionManagement
@EnableScheduling
@EnableAspectJAutoProxy(proxyTargetClass=true)
public class DataSourceConfig implements TransactionManagementConfigurer { ... }
当我浏览调试日志时,我收到以下消息
Identified candidate component class: file [C:\...\abc\web\action\TransactionAction.class]
...
org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'transactionAction'
org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'transactionAction'
org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
org.springframework.beans.factory.support.DefaultListableBeanFactory - Eagerly caching bean 'transactionAction' to allow for resolving potential circular references
org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator - Creating implicit proxy for bean 'transactionAction' with 0 common interceptors and 2 specific interceptors
org.springframework.aop.framework.Cglib2AopProxy - Creating CGLIB2 proxy: target source is SingletonTargetSource for target object [abc.web.action.TransactionAction@1d3981c]
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: public org.apache.struts.action.ActionForward abc.web.action.TransactionAction.doExecute(org.apache.struts.action.ActionMapping,org.apache.struts.action.ActionForm,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.lang.Exception
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: public org.apache.struts.action.ActionForward abc.web.action.AbcAction.execute(org.apache.struts.action.ActionMapping,org.apache.struts.action.ActionForm,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.lang.Exception
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected org.apache.struts.util.MessageResources org.apache.struts.action.Action.getResources(javax.servlet.http.HttpServletRequest)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected org.apache.struts.util.MessageResources org.apache.struts.action.Action.getResources(javax.servlet.http.HttpServletRequest,java.lang.String)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: public org.apache.struts.action.ActionForward org.apache.struts.action.Action.execute(org.apache.struts.action.ActionMapping,org.apache.struts.action.ActionForm,javax.servlet.ServletRequest,javax.servlet.ServletResponse) throws java.lang.Exception
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected java.util.Locale org.apache.struts.action.Action.getLocale(javax.servlet.http.HttpServletRequest)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected void org.apache.struts.action.Action.setLocale(javax.servlet.http.HttpServletRequest,java.util.Locale)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: public org.apache.struts.action.ActionServlet org.apache.struts.action.Action.getServlet()
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: public void org.apache.struts.action.Action.setServlet(org.apache.struts.action.ActionServlet)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected boolean org.apache.struts.action.Action.isCancelled(javax.servlet.http.HttpServletRequest)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected org.apache.struts.action.ActionMessages org.apache.struts.action.Action.getErrors(javax.servlet.http.HttpServletRequest)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected void org.apache.struts.action.Action.addMessages(javax.servlet.http.HttpServletRequest,org.apache.struts.action.ActionMessages)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected void org.apache.struts.action.Action.addErrors(javax.servlet.http.HttpServletRequest,org.apache.struts.action.ActionMessages)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected boolean org.apache.struts.action.Action.isTokenValid(javax.servlet.http.HttpServletRequest,boolean)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected boolean org.apache.struts.action.Action.isTokenValid(javax.servlet.http.HttpServletRequest)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected void org.apache.struts.action.Action.resetToken(javax.servlet.http.HttpServletRequest)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected void org.apache.struts.action.Action.saveErrors(javax.servlet.http.HttpServletRequest,org.apache.struts.action.ActionMessages)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected void org.apache.struts.action.Action.saveErrors(javax.servlet.http.HttpServletRequest,org.apache.struts.action.ActionErrors)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected void org.apache.struts.action.Action.saveMessages(javax.servlet.http.HttpServletRequest,org.apache.struts.action.ActionMessages)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected void org.apache.struts.action.Action.saveMessages(javax.servlet.http.HttpSession,org.apache.struts.action.ActionMessages)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected void org.apache.struts.action.Action.saveToken(javax.servlet.http.HttpServletRequest)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected java.lang.String org.apache.struts.action.Action.generateToken(javax.servlet.http.HttpServletRequest)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected org.apache.struts.action.ActionMessages org.apache.struts.action.Action.getMessages(javax.servlet.http.HttpServletRequest)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected javax.sql.DataSource org.apache.struts.action.Action.getDataSource(javax.servlet.http.HttpServletRequest)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected javax.sql.DataSource org.apache.struts.action.Action.getDataSource(javax.servlet.http.HttpServletRequest,java.lang.String)
org.springframework.aop.framework.Cglib2AopProxy - Found finalize() method - using NO_OVERRIDE
org.springframework.aop.framework.Cglib2AopProxy - Found 'equals' method: public boolean java.lang.Object.equals(java.lang.Object)
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: public java.lang.String java.lang.Object.toString()
org.springframework.aop.framework.Cglib2AopProxy - Found 'hashCode' method: public native int java.lang.Object.hashCode()
org.springframework.aop.framework.Cglib2AopProxy - Unable to apply any optimisations to advised method: protected native java.lang.Object java.lang.Object.clone() throws java.lang.CloneNotSupportedException
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract int org.springframework.aop.framework.Advised.indexOf(org.springframework.aop.Advisor)
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract int org.springframework.aop.framework.Advised.indexOf(org.aopalliance.aop.Advice)
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isFrozen()
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract org.springframework.aop.Advisor[] org.springframework.aop.framework.Advised.getAdvisors()
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.removeAdvice(org.aopalliance.aop.Advice)
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvice(org.aopalliance.aop.Advice) throws org.springframework.aop.framework.AopConfigException
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvice(int,org.aopalliance.aop.Advice) throws org.springframework.aop.framework.AopConfigException
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isPreFiltered()
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract java.lang.Class[] org.springframework.aop.framework.Advised.getProxiedInterfaces()
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isInterfaceProxied(java.lang.Class)
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.removeAdvisor(int) throws org.springframework.aop.framework.AopConfigException
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.removeAdvisor(org.springframework.aop.Advisor)
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.replaceAdvisor(org.springframework.aop.Advisor,org.springframework.aop.Advisor) throws org.springframework.aop.framework.AopConfigException
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract java.lang.String org.springframework.aop.framework.Advised.toProxyConfigString()
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract org.springframework.aop.TargetSource org.springframework.aop.framework.Advised.getTargetSource()
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.setTargetSource(org.springframework.aop.TargetSource)
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.setPreFiltered(boolean)
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isProxyTargetClass()
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.setExposeProxy(boolean)
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isExposeProxy()
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvisor(org.springframework.aop.Advisor) throws org.springframework.aop.framework.AopConfigException
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvisor(int,org.springframework.aop.Advisor) throws org.springframework.aop.framework.AopConfigException
org.springframework.aop.framework.Cglib2AopProxy - Method is declared on Advised interface: public abstract java.lang.Class org.springframework.aop.TargetClassAware.getTargetClass()
org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'transactionAction'
我还阅读了很多关于抽象方法调用和 AOP 的信息,但似乎没有任何效果。请帮帮我。