gpt4 book ai didi

spring - Grails 中的加载时间编织

转载 作者:行者123 更新时间:2023-12-02 14:47:46 25 4
gpt4 key购买 nike

我正在尝试在 Grails 项目中使用加载时编织,以便能够序列化和反序列化对象并自动注入(inject) spring 依赖项。经过一番搜索,我发现了 easy example这似乎按预期工作。但是在将相同的配置应用于一个简单的 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 类的原型(prototype),并将值 Timon 注入(inject)到 name 属性中。

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

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

最佳答案

为什么不通过元类注入(inject)你的属性?

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

关于spring - Grails 中的加载时间编织,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7243311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com