首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

Struts Spring整合时的AOP部分,为什么action里的方法不被执行解决办法

2012-03-07 
Struts Spring整合时的AOP部分,为什么action里的方法不被执行如题,struts.xml部分代码:XML codeaction na

Struts Spring整合时的AOP部分,为什么action里的方法不被执行
如题,struts.xml部分代码:
   

XML code
        <action name="book" class="bookAction">            <result name="add">book/addBook.jsp</result>            <result name="addSuccess">book/addSuccess.jsp</result>            <result name="modify">book/modifyBook.jsp</result>            <result name="del">book/delBook.jsp</result>            <!--//error后返回到error action,在结果页面里使用struts标签读取error值  --></action>        <action name="index" class="indexAction">            <result name="success">index.jsp</result>        </action>


action类的相关代码:
Java code
@Component("bookAction")@Scope(value="prototype")public class BookAction extends ActionSupport implements ModelDriven<BookDTO>{        private BookDTO bookDTO = new BookDTO();    private BookService bookService;        public BookService getBookService() {        return bookService;    }    @Resource(name="bookService")    public void setBookService(BookService bookService) {        this.bookService = bookService;    }        public BookDTO getBookDTO() {        return bookDTO;    }    public void setBookDTO(BookDTO bookDTO) {        this.bookDTO = bookDTO;    }    public String add() throws Exception{        System.out.println("add");        return "add";    }}

beans.xml代码:
XML code
<?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-3.0.xsd            http://www.springframework.org/schema/context             http://www.springframework.org/schema/context/spring-context-3.0.xsd            http://www.springframework.org/schema/aop             http://www.springframework.org/schema/aop/spring-aop-3.0.xsd            http://www.springframework.org/schema/tx             http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">                 <context:annotation-config />      <aop:aspectj-autoproxy />      <context:component-scan base-package="localhost.lms.aop"></context:component-scan>    <context:component-scan base-package="localhost.lms.service.impl" />    <context:component-scan base-package="localhost.lms.dao.impl" />    <context:component-scan base-package="localhost.lms.action"></context:component-scan>  </beans>

inteceptor部分代码
Java code
@Aspect@Component("beanInteceptor")public class BeanInteceptor{        @Pointcut("execution(public * localhost.lms.action..*(..))")    public void myMethod() {}        @Around("myMethod()") //环绕通知    public Object around(ProceedingJoinPoint pjp) throws Throwable {        System.out.println("进入环绕");        Object[] args = pjp.getArgs();        Object result = pjp.proceed(args);        System.out.println("dddd");        System.out.println("退出环绕");        return result;    }} 



启动服务器后没有异常,但是实际提交action时,只有拦截器里的方法执行,action方法里的内容不执行,就像proceed()不存在

[解决办法]
楼主将struts托给spring 时用的是“注解”
所以struts.xml 的action 里的class要用全名(包括路径)
如果在beans.xml中配的话,直接写bena 的id就行

热点排行