<bean id="check" class="quanquanfly.Check"/>           

<bean name="/test" class="quanquanfly.TestAction" >
</bean>

<aop:config>
<aop:aspect id="checkaa" ref="check">
<aop:pointcut id="all" expression="execution(* quanquanfly.TestAction.add(..))"/>
<aop:before method="aa" pointcut-ref="all"/>
</aop:aspect>
</aop:config><form-beans>
<form-bean name="testactionform" type="quanquanfly.TestActionForm" />
</form-beans> <action-mappings> <action path="/test" type="org.springframework.web.struts.DelegatingActionProxy" name="testactionform" 
scope="request" validate="false" parameter="command">
<forward name="success" path="/aa.jsp" />
</action>
</action-mappings>
public class Check {

public void  aa() 
{
System.out.println("aaaaa");
}
}
然后我在页面action="test.do?command =add"的时候后台怎么不打印aaaaa的?aop无法拦截add?

解决方案 »

  1.   

    如果用BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");factory .getBean();是可以打印的,就是运行在jsp页面上的时候后台没有反应,求救
      

  2.   

    你要好好的 仔细的看下AOP了 你配的不对
      

  3.   


    你肯定得通过spring的容器来获得bean,然后你配置的aop才能起作用啊。。
      

  4.   

    不行你就在你的web.xml里 加入:<listener>
      <listener-class>
           org.springframework.web.context.ContextLoaderListener
      </listener-class>
    </listener> 
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext-*.xml</param-value>
    </context-param> 
      

  5.   

    哪里不对了?能否告诉我?获取bean后运行是有效的,但是在网页上运行却不调用check()
      

  6.   

    或者你们谁给我个有效果的实例,让我看看有什么不同?是jsp页面请求action,然后aop拦截action在后台打印出信息,表示运行了该advice
      

  7.   

    应该是Web.xml没有配置Struts的Servlet
      

  8.   

     <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
          <param-name>config</param-name>
          <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <init-param>
          <param-name>debug</param-name>
          <param-value>2</param-value>
        </init-param>
        <init-param>
          <param-name>detail</param-name>
          <param-value>2</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
      </servlet>
      
      <!-- Standard Action Servlet Mapping -->
      <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
      </servlet-mapping>
      
     <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>classpath*:applicationContext.xml</param-value>
      </context-param>
       
       <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
       </listener>
      

  9.   

    aop 用接口注入Iuser <bean id="userDao" class="Dao.UserDao">
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
            <bean name="/test" class="quanquanfly.TestAction" >
                    <property name="Iuser" ref="userDao" />
            </bean>
      

  10.   

     <aop:config>
            <!-- 应该把1放在这里吧-->
     <aop:pointcut id="all" expression="execution(* quanquanfly.TestAction.add(..))"/>    
            <aop:aspect id="checkaa" ref="check">
               <!-- <aop:pointcut id="all" expression="execution(* quanquanfly.TestAction.add(..))"/>    -->       <!-- 1-->
                <aop:before method="aa" pointcut-ref="all"/>
            </aop:aspect>
        </aop:config>
      

  11.   

    你的Action是否有继承DispatchAction
    能贴你的Action代码吗