After many coffees, I think that Ive found what is happenning to Spring AOP when working with my struts actions classes.
I have done a simple example that works nicely (thanks Mike), but it only works when the Actions are instances of classes Action or ActionSupport.
However, when I try the same example with DispatchAction or DispatchActionSupport, the AOP aspects arent called.
Here is my example:
WEB.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Example1</display-name>
<!-- Spring integration -->
<listener>
<display-name>spring-applicationContext</display-name>
<listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
<!-- Spring integration end-->
<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>
<init-param>
<param-name>validate</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- The Usual Welcome File List -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
applicationContext-web.xml
<?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:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schem...-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="action1" name="/action1" scope="prototype" autowire="byName" class="example1.actions.Action1Action"></bean>
<aop:config proxy-target-class="true">
<aop:aspect ref="logging">
<aop

ointcut id="test1"
expression="execution(* example1.actions.*.*(..))" />
<aop:before pointcut-ref="test1" method="logBefore" />
<aop:after-returning pointcut-ref="test1" method="logAfter" />
</aop:aspect>
</aop:config>
<bean id="logging" class="example1.logging.Logging" />
<aop:aspectj-autoproxy />
</beans>
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<!-- Action Mappings -->
<action-mappings>
<action path="/action1" parameter="cmd" type="org.springframework.web.struts.DelegatingAct ionProxy"></action>
</action-mappings>
<plug-in className="org.springframework.web.struts.ContextL oaderPlugIn"/>
</struts-config>
Logging.class
public class Logging {
public void logBefore() {
System.out.println("before an action");
}
public void logAfter() {
System.out.println("After an action");
}
}
Action1Action.class
public class Action1Action extends ActionSupport{
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
return null;
}
}
This works perfect, but when I change Action1Action to DispatchActionSupport it doesnt work:
public class Action1Action extends DispatchActionSupport{
public ActionForward entrance(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
return null;
}
}
Is there a reason for this? Is this a bug? How can I report it as a bug?
Am I doing something wrong?
Well, I hope this helps someone.
P.D. By the way, Im moving to Dublin, is there anyone in Dublin working with this?