AOP 注解问题

lalashuai666 2013-03-29 01:13:10
package com.chuanghe.web.utils;

import javax.xml.rpc.ServiceException;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class ReimDvisor {
@Pointcut("execution (* com.chuanghe.web.action.reim.ReimManageAction.doStampRecord(..))")
public void recordAction() {

System.out.print("===========");
}
@AfterReturning("recordAction()")
public void test(){
System.out.print("----------------");
}

}

spring 配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:component-scan base-package="com.chuanghe" />
<aop:aspectj-autoproxy/>

........省略
不知道怎么回事 打印不出来
...全文
236 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
love_vvl 2013-03-30
  • 打赏
  • 举报
回复
我的也打印不出来,没报错
lalashuai666 2013-03-29
  • 打赏
  • 举报
回复
好像是@Controller("/control/reim/manage") 这个东西 自动注入 和那个切面需要的bean有冲突 我感觉报错好像是和@Controller("/control/reim/manage")有关
  • 打赏
  • 举报
回复
http://blog.sina.com.cn/s/blog_7d2dd23c0100unak.html 看看这个例子,和你几乎是一样的。
  • 打赏
  • 举报
回复
你在一个类中搞来搞去的。没有理解切面到底是干嘛用的
lalashuai666 2013-03-29
  • 打赏
  • 举报
回复
@Component 后面删了 package com.chuanghe.web.action.reim; @Scope("prototype") @Controller("/control/reim/manage") @Component public class ReimManageAction extends DispatchAction { 不报错了...但是 @Component @Aspect public class ReimDvisor { @Pointcut("execution (* com.chuanghe.web.action.reim.ReimManageAction.doStampRecord(..))") public void helloworld() { System.out.println("throw runtime exception"); } @AfterThrowing(pointcut="helloworld()",throwing="e") public void exceptionSayHello(Exception e) { System.out.println("throw runtime exception"+e); } } 没有执行 没有输出
  • 打赏
  • 举报
回复
@Controller @Component 不要加东西。
lalashuai666 2013-03-29
  • 打赏
  • 举报
回复
如果哪位大神有时间 如果愿意的话跪求加Q指导一下1574400632
lalashuai666 2013-03-29
  • 打赏
  • 举报
回复
我重新发一下代码 声明类 package com.chuanghe.web.utils; import javax.xml.rpc.ServiceException; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.springframework.stereotype.Component; @Aspect @Component public class ReimDvisor { @Pointcut("execution (* com.chuanghe.web.action.reim.ReimManageAction.doStampRecord(..))") public void recordAction() { System.out.print("==========="); } @AfterReturning("recordAction()") public void test(){ System.out.print("----------------"); } } 目标类 package com.chuanghe.web.action.reim; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; import java.text.DateFormat; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import net.sf.json.JSONArray; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.actions.DispatchAction; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Pointcut; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import org.springframework.stereotype.Controller; import com.chuanghe.Constant.ReimState; import com.chuanghe.Constant.Report; import com.chuanghe.Constant.ReturnUrl; import com.chuanghe.bean.common.Department; import com.chuanghe.bean.common.Employ; import com.chuanghe.bean.common.StampRecord; import com.chuanghe.bean.common.SystemOption; import com.chuanghe.bean.loan.LoanTab; import com.chuanghe.bean.project.Project; import com.chuanghe.bean.reim.CostType; import com.chuanghe.bean.reim.ReimHead; import com.chuanghe.bean.reim.ReimList; import com.chuanghe.bean.reim.ReportStream; import com.chuanghe.bean.reim.StatusPara; import com.chuanghe.service.common.DepartmentService; import com.chuanghe.service.project.ProjectService; import com.chuanghe.service.reim.CostTypeService; import com.chuanghe.service.reim.ReimHeadService; import com.chuanghe.service.reim.ReimListService; import com.chuanghe.service.reim.ReportStreamService; import com.chuanghe.service.stamprecord.StampRecordService; import com.chuanghe.utils.RandomByMD5; import com.chuanghe.utils.SiteUrl; import com.chuanghe.utils.WebUtil; import com.chuanghe.web.formbean.reim.ReimForm; import com.chuanghe.web.utils.Rights; import com.chuanghe.web.utils.SystemOptionInit; import com.oracle.xmlns.oxp.service.PublicReportService.ParamNameValue; import com.oracle.xmlns.oxp.service.PublicReportService.PublicReportService; import com.oracle.xmlns.oxp.service.PublicReportService.PublicReportServiceServiceLocator; import com.oracle.xmlns.oxp.service.PublicReportService.ReportRequest; import com.oracle.xmlns.oxp.service.PublicReportService.ReportResponse; /** * @author zhangteng * */ @Scope("prototype") @Controller("/control/reim/manage") @Component("com/chuanghe/web/utils/ReimDvisor") public class ReimManageAction extends DispatchAction { .......省略 spring 配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <aop:aspectj-autoproxy proxy-target-class="false"/> <context:component-scan base-package="com.chuanghe" /> 。。。。。。。。省略 报错 Unexpected exception parsing XML document from class path resource [applicationContext.xml]; nested exception is java.lang.IllegalStateException: Stereotype annotations suggest inconsistent component names: '/control/reim/manage' versus 'com/chuanghe/web/utils/ReimDvisor'
  • 打赏
  • 举报
回复
改为<aop:aspectj-autoproxy proxy-target-class="false"/> 在原来的基础上
lalashuai666 2013-03-29
  • 打赏
  • 举报
回复
@Controller("/control/reim/manage") @Component("com/chuanghe/web/utils/ReimDvisor") public class ReimManageAction extends DispatchAction { 现在报错 Unexpected exception parsing XML document from class path resource [applicationContext.xml]; nested exception is java.lang.IllegalStateException: Stereotype annotations suggest inconsistent component names: '/control/reim/manage' versus 'com/chuanghe/web/utils/ReimDvisor'
tianma630 2013-03-29
  • 打赏
  • 举报
回复
有执行doStampRecord方法吗 ReimManageAction有配置注解吗

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧