Announcement Announcement Module
Collapse
No announcement yet.
@Configurable no longer working for me Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Configurable no longer working for me

    After I reinstalled Eclipse and upgraded all the tools, plugs, and dependencies, for some reason, load-time weaving in collaboration with `@Configurable' no longer works for me.

    This is my test class:

    Code:
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration
    public class ConfigurableTest {
        @Configurable
        public static class MyConfigurable {
            @Resource
            ApplicationContext context;
        }
        
        @Test
        public void testConfigurable() {
            MyConfigurable conf = new MyConfigurable();
            assertThat(conf.context, not(nil()));
        }
    }
    This is `ConfigurableTest-context.xml':

    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:aop="http://www.springframework.org/schema/aop"
            xmlns:context="http://www.springframework.org/schema/context"
            xmlns:tx="http://www.springframework.org/schema/tx"
            xmlns:util="http://www.springframework.org/schema/util"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
                    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
                    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
                    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
        <context:load-time-weaver/>
        <context:spring-configured/>
    </beans>
    JVM args when running the test are `-javaagent:spring-instrument-3.1.1.RELEASE.jar'. In addition, I use AspectJ version 1.6.12.

    The test fails---`conf.context' remains `null'.

    So what am I missing?

    Regards,
    Phil
    Last edited by phkoester; Mar 18th, 2012, 02:29 PM.

  • #2
    I just managed to further narrow down the problem. It is when I switch from Spring 3.0.7.RELEASE to 3.1.0.RELEASE that my test breaks and @Configurable doesn't do what I expect it to do. The AspectJ version doesn't matter.

    What has changed in Spring 3.1 with respect to load-time weaving and @Configurable? Am I missing a new configuration setting?

    Comment


    • #3
      Well, 87 views and no reply---that's kind of disappointing.

      While I was switching from XML-based configurations to the new stylish annotations anyway, I found an example in the Javadoc of @EnableLoadTimeWeaving that solved my problem:

      Code:
      @EnableSpringConfigured
      @Configuration
      @EnableLoadTimeWeaving(aspectjWeaving = AspectJWeaving.ENABLED)
      public static class Config {}
      The assignment to aspectjWeaving is important there. So maybe there is a new attribute for <context:load-time-weaver/> now. I haven't looked into this because my problem vanished anyway.

      Thanks for reading.

      Phil
      Last edited by phkoester; Mar 20th, 2012, 02:38 PM.

      Comment

      Working...
      X