Announcement Announcement Module
Collapse
No announcement yet.
ObjectMapper not being woven by load time weaver. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ObjectMapper not being woven by load time weaver.

    I am attempting to use aspectj load time weaving(<context:load-time-weaver />) alongside the <mvc:annotation-driven/> directive.

    My issue is that the com.fasterxml.jackson.databind.ObjectMapper class is not be woven at load time. After some digging, I realized that it was because the <mvc:annotation-driven/> directive loads the MappingJackson2HttpMessageConverter, which creates a new ObjectMapper instance. This all happens before the org.springframework.context.weaving.AspectJWeaving Enabler's postProcessBeanFactory method is called and the AspectJ weaver is enabled.

    The end result of this is that the ObjectMapper is loaded by the TomcatInstrumentableClassLoader prior Spring switching on aspectj load time waving, and is therefore not woven.

    I realize that I could use the following configuration in lieu of <mvc:annotation-driven />

    Code:
    <bean name="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper"/>
    	
    	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    		<property name="messageConverters">
    			<list>
    				<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
    					<property name="objectMapper" ref="objectMapper" />
    				</bean>
                                    ...... Other converters			
    			</list>
    		</property>
    	</bean>

    This solution is not ideal because the aspect code is in a shared jar used by 8 different spring projects within my organization. I want to allow these projects, and any future projects using the shared jar to retain the ability to use the <mvc:annotation-driven /> directive without having to worry about the specifics of the shared jar.

    If anyone has suggestions as to how I can use both the <context:load-time-weaver /> directive and the <mvc:annotation-driven/> directive in my spring configuration and have the ObjectMapper woven, I would be grateful.

    META-INF/aop.xml
    Code:
    <!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
    <aspectj>
    	<weaver options="">
    		<include within="com.collegenet.jackson.map.aspect.JsonFilterAspect"/>
    		<include within="com.fasterxml.jackson.databind.ObjectMapper" />
    		<include within="web.mvc..*"/>
    	</weaver>
    
    	<aspects>
    		<aspect name="com.collegenet.jackson.map.aspect.JsonFilterAspect"/>
    	</aspects>
    </aspectj>
    web/META-INF/context.xml
    Code:
    <Context reloadable="false">
    <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
    </Context>
    Version Details
    Spring MVC - 3.1.2.RELEASE
    Spring Instument Tomcat - 3.1.2.RELEASE
    Spring AOP - 3.1.2.RELEASE
    AspectJ jars (aspectjweaver and aspectjrt) - 1.6.9
    Jackson - 2.1.2


    If there is any further information I can provide, please let me know and thank you for taking a look at this issue.
Working...
X