当前位置: 首页 > 知识库问答 >
问题:

为什么我不能让Spring加载时间编织的工作吗

轩辕庆
2023-03-14

我一直在尝试获得一个示例@Configuration构建工作(在groovy中),所以我可以使用Spring容器触发依赖注入,但我得到的只是关于-javaagent的错误,我似乎无法修复

我有一个这样的beanConfig类

@Configuration @EnableSpringConfigured // 应打开 AnnotationBeanConfigurerAspect @EnableLoadTimeWeaving (aspectjWeaving=AspectJWeaving.ENABLED) // 打开此上下文类 BeanConfig {

然后,我将调用一个示例类new,并尝试获取spring容器中的注入,在上面的配置类中声明diSource bean

“@Configurable(自动装配=自动装配。BY_TYPE,靠

def say () {
    println "ExtDI : diSource set as " + diSource.name
}
}

`

在我的sampler类中,我调用它来尝试并触发注入

` ...static void main(String[]args){ AnnotationConfigApplicationContext CTX = new AnnotationConfigApplicationContext(/bean config . class/)CTX . scan(" com .软木")ctx.refresh()....

    //trigger LTW injection
    ExtDI ext = new ExtDI()
    ext.say()

`

在类路径上,我有aspectjeaver-1.6.10.jar,aspectjrt-1.6.10.jar,spring-xxx-3.1.4.jars等,这是我的gradle depdency列表

dependencies { compile 'org.codehaus.groovy:groovy-all:2.1.7' 编译组: 'commons-collections', name: 'commons-collections', version: '3.2' testCompile group: 'junit', name: 'junit', version: '4. ' compile “org.springframework:spring-core:${spring_version}” compile “org.springframework:spring-beans:${spring_version}” compile “org.springframework:spring-context:${spring_version}” compile “org.springframework:spring-aspects:${spring_version}” compile ”org.springframework:spring-aop:${spring_version}“ compile ”org.springframework:spring-instrument:${spring_version}“ compile ”org.aspectj:aspectjrt:1.6.10“ compile ”org.aspectj:aspectjweaver:1.6.10“ compile ”cglib:cglib:2.2“ }

在虚拟机参数的eclipse项目运行时中,我有-javaagent:C:/Users/802518659/aspectjweaver-1.6.10.jar

并且用spring-instrument-3.1.4.jar试过同样的问题。

当我运行这个项目我得到这个错误

`

Oct 19, 2013 4:02:40 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@492ff1: startup date [Sat Oct 19 16:02:40 BST 2013]; root of context hierarchy
Oct 19, 2013 4:02:40 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@11bedb0: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,beanConfig,willsBean,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.aspectj.SpringConfiguredConfiguration,org.springframework.context.config.internalBeanConfigurerAspect,org.springframework.context.annotation.LoadTimeWeavingConfiguration,loadTimeWeaver,publicBean,privateBean,publicBeanWithDI,myDISource,diTarget]; root of factory hierarchy
Oct 19, 2013 4:02:40 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@11bedb0: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,beanConfig,willsBean,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.aspectj.SpringConfiguredConfiguration,org.springframework.context.config.internalBeanConfigurerAspect,org.springframework.context.annotation.LoadTimeWeavingConfiguration,loadTimeWeaver,publicBean,privateBean,publicBeanWithDI,myDISource,diTarget]; root of factory hierarchy
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadTimeWeaver' defined in class path resource [org/springframework/context/annotation/LoadTimeWeavingConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.instrument.classloading.LoadTimeWeaver org.springframework.context.annotation.LoadTimeWeavingConfiguration.loadTimeWeaver()] threw exception; nested exception is java.lang.IllegalStateException: ClassLoader [sun.misc.Launcher$AppClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581)
...

`

告诉我,我的应用程序可以与赞誉吗

那么我做错了什么——这真的开始困扰我了——我可以在上下文中得到普通的注入来工作(没有LTW ),但是我真的想在容器外得到这个注入来工作

我做错了什么

共有1个答案

都才俊
2023-03-14

花了一些时间,但找出哪里出了问题

纠正在另一篇文章在Spring论坛看到计画

我也在我的博客上加了一条更长的说明

http://willwoodman.wordpress.com/

 类似资料:
  • 每当打开Hibernate会话时,我都想使用AsheJ添加一个过滤器。我创建了一个方面并为我自己的类测试了它,它起作用了,但是对于Hibernate会话它什么也不做。 我创建了一个META-INF/aop。资源中的xml: 当我开始我的程序时,我得到以下异常: 我遵循了这些教程: 教程1教程2 我发现我必须按照异常的指示传递JVM参数,所以我尝试在构建梯度中执行以下操作: 根据IntelliJ,a

  • 我有以下内容: 配置中的基uri是: 基本URI:/API 所以我应该能够获得localhost:8080/api/cars/test 为什么?

  • 和位于同一个包中,编织工作在直接实例化的包上,而不是bean返回的包上。 我搜索了Spring AOP文档,但似乎找不到任何与此相关的内容。对于自动代理,您需要做一些魔术,对于SpringAOP也需要做一些限制,但是加载时间编织就我所知应该可以工作--例如,我已经尝试过私有方法,它可以工作。

  • 问题内容: 更新5: 我已经基于最新的Eclipse下载了最新的Spring ToolsSuite IDE。当我将项目导入为Maven项目时,Eclipse / STS似乎使用Maven目标来构建我的项目。这意味着AspectJ最终可以在Eclipse中正常工作。 更新4: 我最终仅使用Maven + AspectJ插件进行编译时编织,有效地绕过Eclipse的机制。 更新3: 看来AspectJ

  • 如果我使用的是基于AspectJ的Spring AOP,那么我是否需要配置我的方面来使用加载时间编织?或者Spring AOP在使用基于AspectJ的方法时也支持运行时/编译时编织吗?