Announcement Announcement Module
Collapse
No announcement yet.
Configurable or Mixin but not both, Why not? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configurable or Mixin but not both, Why not?

    I am experimenting with Spring AspectJ DI configured prototype pojos with mixin introductions. I am working in Eclipse 3.2 using AJDT. If I run my unit test with these javaagents defined:

    -javaagent:.../spring-agent.jar -javaagent:.../aspectjweaver.jar

    then my configurable beans have property values injected correctly on instantiation, but my mixin aspect is not applied and the pojo that should be extended is not.

    On the other hand, if I run my unit test without the -javaagent options, then my mixin aspect is applied and extends my pojo, but the property values are not injected on instantiation.

    I suspect that in the first case, autoproxies are being applied to perform the dependency injection and in the second case LTW is extending my pojo with the mixin aspect and for some reason they are not compatible.

    Can anyone shed light on what is vexxing me and guide me toward a solution that gives me both configurable and mixin prototype pojos?

    Thanks!

    -- Bob

    Here is my sample code:

    ConfigurablePojo.java:
    Code:
    import org.springframework.beans.factory.annotation.Configurable;
    
    @Configurable
    public class ConfigurablePojo
    {
      private String name;
    
      public ConfigurablePojo() {}
    
      public String getName() { return name; }
    
      public void setName(String name) { this.name = name; }
    }
    Mixin.java
    Code:
    public interface Mixin
    {
      public String getLastName();
    }
    ConfigurableMixin.java:
    Code:
    import org.springframework.beans.factory.annotation.Configurable;
    
    @Configurable
    public class ConfigurableMixin implements Mixin
    {
      private String lastName;
    
      public ConfigurableMixin() {}
    
      public String getLastName() { return lastName; }
    
      public void setLastName(String lastName) { this.lastName = lastName; }
    }
    ConfigurablePojoMixin.java:
    Code:
    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.DeclareParents;
    
    @Aspect
    public class ConfigurablePojoMixin
    {
      @DeclareParents(value="ConfigurablePojo", defaultImpl=ConfigurableMixin.class)
      public static Mixin mixin;
    }
    configurablePojoMixinTests.xml
    Code:
    <?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/schema/beans/spring-beans.xsd
    	   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
    
    	<aop:spring-configured/>
    	
    	<bean id="mixinAspect" class="ConfigurablePojoMixin"/>
    
    	<bean class="ConfigurablePojo" scope="prototype">
    		<property name="name" value="Jay"/>
    	</bean>
    
    	<bean class="ConfigurableMixin" scope="prototype">
    		<property name="lastName" value="Aspect"/>
    	</bean>
    
    </beans>
    ConfigurablePojoMixinTests.java
    Code:
    import junit.framework.TestCase;
    
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class ConfigurablePojoMixinTests extends TestCase
    {
      @Override
      protected void setUp() throws Exception
      {
        new ClassPathXmlApplicationContext("configurablePojoMixinTests.xml");
      }
    
      // only passes when javaagent is defined.
      public void testConfigurablePojo()
      {
        ConfigurablePojo pojo = new ConfigurablePojo();
        assertEquals("Jay", pojo.getName());
        System.out.println("Configurable pojo name is: " + pojo.getName());
      }
    
      // only passes when javaagent is defined.
      public void testConfigurableMixin()
      {
        ConfigurableMixin mixin = new ConfigurableMixin();
        assertEquals("Aspect", mixin.getLastName());
        System.out.println("Configurable mixin last name is: " + mixin.getLastName());
      }
    
      // only passes when javaagent is NOT defined.
      public void testThatConfigurablePojoIsAMixin()
      {
        ConfigurablePojo pojo = new ConfigurablePojo();
        assertTrue(pojo instanceof Mixin);
        System.out.println("Configurable pojo is a mixin");
      }
    
      // never passes, but boy, I wish I knew how it could!
      public void testThatConfigurablePojoIsAMixinAndConfigured()
      {
        ConfigurablePojo pojo = new ConfigurablePojo();
        assertTrue(pojo instanceof Mixin);
        Mixin mixin = (Mixin)pojo;
        assertEquals("Jay", pojo.getName());
        assertEquals("Aspect", mixin.getLastName());
        System.out.println("Configurable pojo mixin full name is: " + pojo.getName() 
            + " " + mixin.getLastName());
      }
    }

  • #2
    I came across the same problem. Have you found any solution yet?

    Comment

    Working...
    X