1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .context .weaving ;
18
18
19
-
20
19
import java .lang .instrument .ClassFileTransformer ;
21
20
import java .lang .instrument .IllegalClassFormatException ;
22
21
import java .security .ProtectionDomain ;
44
43
public class AspectJWeavingEnabler
45
44
implements BeanFactoryPostProcessor , BeanClassLoaderAware , LoadTimeWeaverAware , Ordered {
46
45
46
+ public static final String ASPECTJ_AOP_XML_RESOURCE = "META-INF/aop.xml" ;
47
+
48
+
47
49
private ClassLoader beanClassLoader ;
48
50
49
51
private LoadTimeWeaver loadTimeWeaver ;
50
52
51
- public static final String ASPECTJ_AOP_XML_RESOURCE = "META-INF/aop.xml" ;
52
-
53
53
54
54
@ Override
55
55
public void setBeanClassLoader (ClassLoader classLoader ) {
@@ -71,6 +71,12 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
71
71
enableAspectJWeaving (this .loadTimeWeaver , this .beanClassLoader );
72
72
}
73
73
74
+
75
+ /**
76
+ * Enable AspectJ weaving with the given {@link LoadTimeWeaver}.
77
+ * @param weaverToUse the LoadTimeWeaver to apply to (or {@code null} for a default weaver)
78
+ * @param beanClassLoader the class loader to create a default weaver for (if necessary)
79
+ */
74
80
public static void enableAspectJWeaving (LoadTimeWeaver weaverToUse , ClassLoader beanClassLoader ) {
75
81
if (weaverToUse == null ) {
76
82
if (InstrumentationLoadTimeWeaver .isInstrumentationAvailable ()) {
@@ -80,8 +86,8 @@ public static void enableAspectJWeaving(LoadTimeWeaver weaverToUse, ClassLoader
80
86
throw new IllegalStateException ("No LoadTimeWeaver available" );
81
87
}
82
88
}
83
- weaverToUse .addTransformer (new AspectJClassBypassingClassFileTransformer (
84
- new ClassPreProcessorAgentAdapter ()));
89
+ weaverToUse .addTransformer (
90
+ new AspectJClassBypassingClassFileTransformer ( new ClassPreProcessorAgentAdapter ()));
85
91
}
86
92
87
93
@@ -108,4 +114,5 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
108
114
return this .delegate .transform (loader , className , classBeingRedefined , protectionDomain , classfileBuffer );
109
115
}
110
116
}
117
+
111
118
}
0 commit comments