开发者

Load time weaving in grails

开发者 https://www.devze.com 2023-03-31 13:53 出处:网络
I\'m trying to use load time weaving in a Grails project in order to be able to serialize and deserialize an object and to have automatic injection of spring dependencies. After some searching I found

I'm trying to use load time weaving in a Grails project in order to be able to serialize and deserialize an object and to have automatic injection of spring dependencies. After some searching I found an easy example and that seems to work as expected. But after applying the same configuration to a simple Grails project I get a lot of errors. For example:

[TomcatInstrumentableClassLoader@413a2870] error at org/springframework/web/servlet/theme/AbstractThemeResolver.java::0 class 'org.springframework.web.servlet.theme.AbstractThemeResolver' is already woven and has not been built in reweavable mode

To test this I created a new grails project and changed the applicationContext.xml:

<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"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context.xsd">

<context:spring-configured />
<context:load-time-weaver aspectj-weaving="autodetect" weaver-class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver"/>

In this file I also created a new bean:

<bean class="be.testweaving.Person" scope="prototype">
    <property name="name" value="Timon"/>
</bean>

This defines a prototype for the Person class and injects the value Timon into the name property.

I package this as a war using grails war and deploy this on a tomcat server. This tomcat has the org.springframework.instrument.tomcat-3.0.5.RELEASE.jar in his lib directo开发者_开发百科ry and after the deployment I see a huge list of the errors I mentioned above.

Has anyone been able to configure load time weaving in Grails?


Why don't you just inject your property via metaclass?

class ExampleBootStrap {
 def init = { servletContext ->
     Person.metaClass.constructor = {  
         def person = BeanUtils.instantiateClass(Person) 
         person.name = "Timon"
         person
     }
 }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消