为什么我不能让弹簧加载时间进行编织工作
作者:互联网
我一直在尝试使@Configuration构建示例工作(以常规方式),因此我可以使用Spring容器触发依赖项注入,但是我所得到的只是关于-javaagent的错误,我似乎无法修复
我有一个像这样的beanConfig类
@组态
@EnableSpringConfigured //应该打开AnnotationBeanConfigurerAspect
@EnableLoadTimeWeaving(aspectjWeaving = AspectJWeaving.ENABLED)//为此上下文打开
BeanConfig类{
然后是一个示例类,我将调用new并尝试将注入替换为spring容器,在上述配置类中声明了diSource bean
`
@Configurable(autowire = Autowire.BY_TYPE,dependencyCheck = true)
类ExtDI {
@Autowired DISource diSource
def say () {
println "ExtDI : diSource set as " + diSource.name
}
}
`
在我的采样器类中,我称其为尝试触发进样
`
…
静态void main(String [] args){
AnnotationConfigApplicationContext ctx =新的AnnotationConfigApplicationContext(/BeanConfig.class/)
ctx.scan(“ com.softwood”)
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依赖列表
依赖项{
编译’org.codehaus.groovy:groovy-all:2.1.7′
编译组:“ commons-collections”,名称:“ commons-collections”,版本:“ 3.2”
testCompile组:’junit’,名称:’junit’,版本:’4. ‘
编译“ org.springframework:spring-core:${spring_version}”
编译“ org.springframework:spring-beans:${spring_version}”
编译“ org.springframework:spring-context:${spring_version}”
编译“ org.springframework:spring-aspects:${spring_version}”
编译“ org.springframework:spring-aop:${spring_version}”
编译“ org.springframework:spring-instrument:${spring_version}”
编译“ org.aspectj:aspectjrt:1.6.10”
编译“ org.aspectj:aspectjweaver:1.6.10”
编译“ cglib:cglib:2.2”
}
在Eclipse项目运行时中我有的vm args
-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)
...
`
这告诉我我的应用程序无法检测Java类加载器-尽管事实上我使用-javaagent:spring-instrument-xxx或Aspectjweaver.jar启动它-均失败
所以我在做什么错-这真的开始困扰我-我可以在上下文中进行普通注入工作(没有LTW),但我真的想在容器外部进行这种注入工作
我究竟做错了什么
解决方法:
花了一些时间,但找出了哪里出了问题
在春季论坛上的另一篇文章中更正,请参见
http://forum.spring.io/forum/spring-projects/container/724426-cant-get-aspectj-load-time-weaving-to-work
我也在这里在我的博客中添加了更长的注释
http://willwoodman.wordpress.com/
标签:groovy,spring-annotations,load-time-weaving,spring 来源: https://codeday.me/bug/20191122/2061168.html