带有Spring @Conditional的类不是用AspectJ编织的

时间:2014-12-16 06:22:52

标签: spring aspectj

我想有条件地加载spring 4.0资源,所以下面的代码可以完成这项工作(How to achieve conditional resource import in a Spring XML context?):

@Configuration
@Conditional(MyConditionalConfiguration.Condition)
@ImportResource("/com/example/context-fragment.xml")
public class MyConditionalConfiguration {
    static class Condition implements ConfigurationCondition {
         @Override
         public ConfigurationPhase getConfigurationPhase() {
             return ConfigurationPhase.PARSE_CONFIGURATION;
         }
         @Override
         public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
             // only load context-fragment.xml if the system property is defined
             return System.getProperty("com.example.context-fragment") != null;
         }
    }
}

这个代码怎么不能用AspectJ编织,问题应该是@Conditional

跟踪

org.aspectj.weaver.BCException
at org.aspectj.ajdt.internal.core.builder.AjState.recordClassFile(AjState.java:1519)
at org.aspectj.ajdt.internal.core.builder.AjState.noteResult(AjState.java:1325)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager$3.acceptResult(AjBuildManager.java:1061)
at org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.afterProcessing(AjPipeliningCompilerAdapter.java:426)
at org.aspectj.ajdt.intern ... .0_21-64\jre\lib\ext\sunmscapi.jar;E:\jdk1.7.0_21-64\jre\lib\ext\zipfs.jar;D:\eclipse\\plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar;

0 个答案:

没有答案