|
From: jack h. <hij...@ho...> - 2004-08-05 13:50:38
|
Juergen
Thank you for your quick response:)
I have read the Spring-Struts plugin codes, and now I extact one simple
test case for our discussion.
My struts action is very simple
----------------------------------------HelloAction.java------
public class HelloAction extends Action
{
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
HelloForm helloForm = (HelloForm) form;
populate(helloForm);
return mapping.findForward("display");
}
public void populate(HelloForm form)
{
form.setMsg("Hello World");
}
}
And the BeforeHelloInteceptor wanna to say "before hello" when the action
is excuting populate(..) method. Code is here.
---------------------------------------------BeforeHelloInteceptor.java---
public class BeforeHelloInteceptor implements MethodBeforeAdvice
{
public void before(Method method, Object[] args, Object target)
throws Throwable
{
System.out.println("before hello");
}
}
And the spring config file shows below:
-------------------------------------------------------aopplicationContext.xml----
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!--bean id="helloActionTarget"
class="spring.struts.test.action.Action"/-->
<bean id="helloActionTarget"
class="spring.struts.test.action.HelloAction"/>
<bean id="helloAction" name="/hello"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target"><ref
local="helloActionTarget"></ref></property>
<property
name="interceptorNames"><value>beforeHelloAdvisor</value></property>
</bean>
<bean id="beforeHelloInteceptor"
class="spring.struts.test.interceptor.BeforeHelloInteceptor"/>
<bean id="beforeHelloAdvisor"
class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice">
<ref local="beforeHelloInteceptor"/>
</property>
<property name="patterns">
<list>
<value>spring.struts.test.action.HelloAction.populate</value>
</list>
</property>
</bean>
</beans>
When I run the demo on JBoss3.2.4 and Tomcat5.0.16, both are failed.
Am I wrong in something or just one bug?
PS: My demo is attached. WEB-INF/lib is blank, fill the jars by yourself:)
Regards
Jack
>From: jgen hler [werk3AT] <jue...@we...>
>Reply-To: spr...@li...
>To: <spr...@li...>
>Subject: Re: [Springframework-developer] Spring aop and struts
>Date: Thu, 5 Aug 2004 09:40:54 +0200
>
>Have a look at Spring's org.springframework.web.struts package: Besides
Action base classes that allow easy access to Spring's root web application
context (ActionSupport and DispatchActionSupport), you'll also find a
ContextLoaderPlugIn plus DelegationActionProxy / DelegatingRequestProcessor
there.
>
>The latter delegation mechanisms allows you to have a special Spring XML
bean definition file where your Struts Actions get defined as Spring beans
themselves; the Struts ActionServlet will simply delegate to them. You can
in principle apply all of Spring's bean configuration facilities to those
Actions beans, including AOP ProxyFactoryBeans that specify
advices/interceptors for specific target Actions.
>
>Note that an AOP ProxyFactoryBean for a Struts Action target needs to have
"proxyTargetClass" as "true", to proxy the full target class rather than
just specific interfaces (requiring CGLIB on the classpath). Unfortunately,
Struts does not define an Action interface, so there's no way around that.
>
>Juergen
>
>
>________________________________
>
>Von: spr...@li... im Auftrag von
jack hi
>Gesendet: Do 05.08.2004 08:25
>An: spr...@li...
>Betreff: [Springframework-developer] Spring aop and struts
>
>
>
>Hi,Spring guys.
>
>After I integrated Spring and Struts, the first idea from my brain was:
>Could I apply Spring aop on struts actions?
>
>Yes, SAIF project had supplied struts some interceptor function, but it's
>weak in DispatchAction and MethodInceptor.
>
>And my experience was finally failed:(. I could not create struts Action
>proxy. Because in spring "Either an interface or a target is required for
>proxy creation". Should my struts actions implement TargetSource
interface?
>
>Thank you for your glance at this message, and appreciate your suggestion.
>
>Regards
>Jack
>
>_________________________________________________________________
>??????????,??? MSN Messenger: http://messenger.msn.com/cn
>
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by OSTG. Have you noticed the changes on
>Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
>one more big change to announce. We are now OSTG- Open Source Technology
>Group. Come see the changes on the new OSTG site. www.ostg.com
>_______________________________________________
>Springframework-developer mailing list
>Spr...@li...
>https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by OSTG. Have you noticed the changes on
>Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
>one more big change to announce. We are now OSTG- Open Source Technology
>Group. Come see the changes on the new OSTG site. www.ostg.com
>_______________________________________________
>Springframework-developer mailing list
>Spr...@li...
>https://lists.sourceforge.net/lists/listinfo/springframework-developer
_________________________________________________________________
与联机的朋友进行交流,请使用 MSN Messenger: http://messenger.msn.com/cn
|