Announcement Announcement Module
Collapse
No announcement yet.
Can AnnotationConfigApplicationContext and LTW work together? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can AnnotationConfigApplicationContext and LTW work together?

    I have the following app.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:context="http://www.springframework.org/schema/context"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    	http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
    	<bean id="accountService" class="com.fundserv.simple.service.AccountService" scope="prototype">
    		<aop:scoped-proxy />
    	</bean>
    
    	<bean class="com.fundserv.simple.busobj.Teller">
    		<property name="accountService" ref="accountService"/>
    	</bean>
    
    	<context:load-time-weaver />
    </beans>


    1. Is it possible to load the above app.xml with AnnotationConfigApplicationContext, I also want to take advantage of the annotations detection.
    2. What is the annotation equivalent of <context:load-time-weaver/>?
    3. What is the corresponding java class of <context:load-time-weaver/>? Can I simply declare a bean object of this class in my Java Config class?

  • #2
    There is no direct equivalent of <context:load-time-weaver/> in @Configuration classes. Generally, where namespaces (like <context:*/>) are needed, it's recommended that you use the @ImportResource annotation to import just the snippet of XML that you need. e.g.:

    Code:
    @Configuration
    @ImportResource("classpath:load-time-weaving.xml")
    public class AppConfig {
        @Bean
        public AccountService accountService() {
            return new DefaultAccountService(...);
        }
    }
    load-time-weaving.xml:
    Code:
    <beans ...>
        <context:load-time-weaver/>
    </beans>
    Feel free to raise a feature request about first-class support for load-time-weaving against the AnnotationConfigApplicationContext API and/or @Configuration programming model.

    Comment


    • #3
      Originally posted by Chris Beams View Post
      There is no direct equivalent of <context:load-time-weaver/> in @Configuration classes. Generally, where namespaces (like <context:*/>) are needed, it's recommended that you use the @ImportResource annotation to import just the snippet of XML that you need. e.g.:

      Code:
      @Configuration
      @ImportResource("classpath:load-time-weaving.xml")
      public class AppConfig {
          @Bean
          public AccountService accountService() {
              return new DefaultAccountService(...);
          }
      }
      load-time-weaving.xml:
      Code:
      <beans ...>
          <context:load-time-weaver/>
      </beans>
      Feel free to raise a feature request about first-class support for load-time-weaving against the AnnotationConfigApplicationContext API and/or @Configuration programming model.
      I did exactly what you suggested, but it did not work. Here is my progress..
      http://forum.springsource.org/showthread.php?t=84190

      Comment

      Working...
      X