对于类没有工作的动画,Aspectj [英] Aspectj for anotations with classes not working

查看:153
本文介绍了对于类没有工作的动画,Aspectj的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码未正确使用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实现ConfigurationCondition {
@Override

public ConfigurationPhase getConfigurationPhase(){
return ConfigurationPhase.PARSE_CONFIGURATION;
}
@Override
public boolean matches(ConditionContext context,AnnotatedTypeMetadata metadata){
//仅在系统属性定义时才加载context-fragment.xml
返回System.getProperty(com.example.context-fragment)!= null;
}
}
}

我正在使用Eclipse Aspectj工具。并且错误显示为 @Conditional 注释。



正如 @Conditional

  @Retention(RetentionPolicy.RUNTIME)
@ Target({ElementType.TYPE,ElementType.METHOD})
public @interface条件{

/ **
*所有{@link条件}必须{@linkplain条件#matches match}
*,以便组件被注册。
* /
Class<? extends Condition> [] value();

}

错误是:

  org.aspectj.weaver.BCException 
在org.aspectj.ajdt.internal.core.builder.AjState.recordClassFile (AjState.java:1519)
在org.aspectj.ajdt.internal.core.builder.AjState.noteResult(AjState.java:1325)
在org.aspectj.ajdt.internal.core.builder .AjBuildManager $ 3.acceptResult(AjBuildManager.java:1061)
在org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.afterProcessing(AjPipeliningCompilerAdapter.java:426)
在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。更改您的注释值:

  @Conditional(ConditionalConfiguration.Condition.class)

你只是忘了使用 .class 后缀。修复你自己的代码,那么编译器就不会再抱怨了。



更新:因为你的错误不应该杀死AspectJ编译器,所以我创建了一个 bug ticket ,但事实依然是你自己的代码是伪造的。 / p>

Below code is not complied correctly with 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;
         }
    }
}

I am using Eclipse Aspectj Tool. and the error is shown for @Conditional annotation.

The is as @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();

}

The error is:

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;

Any Idea how can I make it work, Or at least is it a way which I can set Eclipse AspectJ Tool to simply ignore this file.

解决方案

I was just able to reproduce your problem. Your code is wrong, not AspectJ. Change your annotation value like this:

@Conditional(ConditionalConfiguration.Condition.class)

You just forgot to use the .class suffix. Fix your own code, then the compiler will not complain anymore. ;-)

Update: Because your bug should not kill the AspectJ compiler anyway, I created a bug ticket for it, but the fact remains that your own code was bogus.

这篇关于对于类没有工作的动画,Aspectj的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆