Announcement Announcement Module
Collapse
No announcement yet.
Newbie question about configuration of a ProxyFactoryBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Newbie question about configuration of a ProxyFactoryBean

    I want to know how to get access to methods in an implementation class via her interface with the utilisation of a ProxyFactoryBean.

    I have an interface - BusinessDelegate - an her implementation class - BusinessdelegateImpl -. An Action class - BaseAction - from the web layer (using Struts) want to have access to a specific method from the interface - BusinessDelegate.

    /*BusinessDelegate*/
    public interface BusinessDelegate
    {
    public void test();
    }

    /*BusinessDelegate Implementation*/
    public class BusinessDelegateImpl implements BusinessDelegate
    {
    public void test()
    {
    logger.debug("test");
    }
    }

    /*The action class*/
    public abstract class BaseAction extends Action
    {
    private BusinessDelegate businessDelegate;
    public void setServlet(ActionServlet actionServlet) {
    super.setServlet(actionServlet);
    ServletContext servletContext = actionServlet.getServletContext();
    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicati onContext(servletContext);
    this.businessDelegate = (BusinessDelegate) wac.getBean("businessBean");
    this.businessDelegate.test();
    }

    public BusinessDelegate getBusinessDelegate() {
    return businessDelegate;
    }
    }

    and finally the applicationContext.xml
    <bean id="businessBean" class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="proxyInterfaces">
    <value>com.didbre.website.domain.logic.BusinessDel egate</value>
    </property>
    <property name="target">
    <ref local="beanTarget"/>
    </property>
    </bean>

    <bean id="beanTarget" class="com.didbre.website.domain.logic.BusinessDel egateImpl"/>

    **********************

    When I reach the "this.businessDelegate.test();" in the BaseAction class, I received well kind message that said:
    AOP configuration seems to be invalid: tried calling public abstract void com.didbre.website.domain.logic.BusinessDelegate.t est() on [com.didbre.website.domain.logic.BusinessDelegateIm pl@d6ecc2]: java.lang.IllegalArgumentException: object is not an instance of declaring class
    org.springframework.aop.framework.AopProxyUtils.in vokeJoinpointUsingReflection(AopProxyUtils.java:68 )
    org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:138)
    $Proxy0.test(Unknown Source)
    com.didbre.website.web.action.BaseAction.setServle t(BaseAction.java:23)
    org.apache.struts.action.RequestProcessor.processA ctionCreate(RequestProcessor.java:341)
    org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:268)
    org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1482)
    org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:525)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:763)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:856)

    ******************

    What's the problem and how can have access to my business method test ?

    I'm using :
    Tomcat 5.0.19
    Spring 1.0.2
    Struts 1.1

    Thanks.

  • #2
    Will try to investigate more later, but I can say now that there doesn't seem to be anything wrong with your proxy beans and config. I pretty much cut and paste to a small Spring 1.0.2 application test which called the Proxy just fine. It must have something to do with your particular usage or environment.

    Comment


    • #3
      Config looks OK. Like Tim, I'm puzzled at this point. Are you sure that both BusinessDelegate and BusinessDelegateImpl are loaded by the same class loader?

      Have you tried invoking the proxy using a test case that loads the context, but doesn't involve a web app and the rest of your config?

      Comment


      • #4
        AOPUtils is invoking using reflection.

        From javadocs for java.lang.reflect.Method we've got IllegalArgumentException if:
        1) the method is an instance method and the specified object argument is not an instance of the class or interface declaring the underlying method (or of a subclass or implementor thereof)
        2) if the number of actual and formal parameters differ
        3) if an unwrapping conversion for primitive arguments fails
        3) after possible unwrapping, a parameter value cannot be converted to the corresponding formal parameter type by a method invocation conversion

        None of these seem to be the case. Can you isolate the code and post just the minimal code that exhibits the behaviour?

        Comment


        • #5
          Have you tried invoking the proxy using a test case that loads the context
          This worked for me.
          Are you sure that both BusinessDelegate and BusinessDelegateImpl are loaded by the same class loader
          I tried this. Moving both or just the implementation class to Tomcat's ${CATALINA_HOME}/shared/classes worked OK. Moving only the Interface on here causes a NoClassDefFoundError as expected.

          Comment

          Working...
          X