Grails 中的加载时间编织

发布于 2024-12-02 05:53:03 字数 1697 浏览 3 评论 0原文

我正在尝试在 Grails 项目中使用加载时编织,以便能够序列化和反序列化对象并自动注入 spring 依赖项。经过一番搜索后,我发现 简单的示例,这似乎按预期工作。但是在将相同的配置应用于一个简单的 Grails 项目后,我遇到了很多错误。例如:

[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

为了测试这个,我创建了一个新的 grails 项目并更改了 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"/>

在这个文件中我还创建了一个新的 bean:

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

这定义了 Person 类的原型并注入值 Timonname 属性中。

我使用 grails war 将其打包为 war 并将其部署在 tomcat 服务器上。该tomcat的lib目录中有org.springframework.instrument.tomcat-3.0.5.RELEASE.jar,部署后我看到了上面提到的大量错误。

有人能够在 Grails 中配置加载时间编织吗?

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 directory 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多彩岁月 2024-12-09 05:53:03

为什么不通过元类注入你的属性呢?

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

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
     }
 }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文