Announcement Announcement Module
No announcement yet.
iBatis returning AOP proxy instead of target class? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • iBatis returning AOP proxy instead of target class?

    I have a simple interface Example with an implementing class called ExampleImpl.
    I wanted to add some AOP functionality to the class and declared a ProxyFactoryBean to achieve this. All beans that have a reference to an Example declare this using the bean name "example", which is now actually a reference to the Proxy instead.
    This works fine and the declaration looks like this:

    <bean id="exampleTarget" class="domain.ExampleImpl"></bean>
    <bean id="example" class="org.springframework.aop.framework.ProxyFactoryBean">
      <property name="target">
    	<ref local="exampleTarget"/>
      <property name="proxyInterfaces">
      <property name="interceptorNames">
    Instances of Example is supposed to be fetched from the database using iBatis. My question is how I get iBatis to return the ProxyFactoryBean instead of an instance of ExampleImpl?

    If I got it right, I must declare the implementing class in iBatis result-map element, in my case "domain.ExampleImpl", like this:

    <result-map name="result" class="domain.ExampleImpl">
    <property name="exampleId" column="EXAMPLEID" columnIndex="1" />
    <property name="exampleString" column="EXAMPLESTRING" columnIndex="2" />

    Put in another way: Instead of class="domain.ExampleImpl" I would like to be able to write something like bean="example".

    How can this be done?


  • #2
    At the moment as I'm aware, Spring's has no tighter bondage with iBatis than SqlMapClientTemplate - which nicely transactionaly and exception converting exposes default SqlMapClientOperations.

    If there is something as Interceptor (see Hibernate) in iBatis, than you can probably do something similar as

    Other simple solution is to actualy write wrapper class:

    class ExampleWrapper {

    private Example example;

    public ExampleWrapper() {
    ProxyFactory proxyFactory = new ProxyFactory(new ExampleImpl());
    proxyFactory.addAdvice(new MethodInterceptor());
    this.example = (Example)proxyFactory.getProxy();

    public Object getFoo() {
    return example.getFoo();

    public void setFoo(Object foo) {


    • #3
      Thanks for the Advice (pun intended)!

      I think the wrapper idea is the way to go, but maybe in a somewhat other fashion. I think I'll have a (Spring managed) bean Example that simply holds a reference to a (not Spring managed) object ExampleData that only holds data. The constructor in Example will make sure that ExampleData is loaded from iBatis. This way I can advice Example (or rather it's interface) as it's a Spring managed Bean, without having to put any Spring dependencies in my code.

      Thanks again