【发布时间】:2015-02-14 09:52:54
【问题描述】:
下面的代码没有与 aspectJ 正确兼容
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ConfigurationCondition;
import org.springframework.context.annotation.ImportResource;
import org.springframework.core.type.AnnotatedTypeMetadata;
@Configuration
@Conditional(ConditionalConfiguration.Condition)
@ImportResource("/com/example/context-fragment.xml")
public class ConditionalConfiguration {
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;
}
}
}
我正在使用 Eclipse Aspectj 工具。并为@Conditional 注释显示错误。
如@Conditional:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface Conditional {
/**
* All {@link Condition}s that must {@linkplain Condition#matches match}
* in order for the component to be registered.
*/
Class<? extends Condition>[] value();
}
错误是:
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;
任何想法我怎样才能让它工作,或者至少它是一种我可以设置 Eclipse AspectJ Tool 来简单地忽略这个文件的方法。
【问题讨论】:
-
如果您有 AspectJ 问题,请同时发布您的 aspect(s)。如果是 AspectJ 编译器问题,请告诉我们您用于编译的 AspectJ 版本(AJDT 插件版本,如果您在 Eclipse 中使用 AJDT)。最好提供一个可复制的SSCCE。