Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaSpringAOP:我可以忽略Xlint:InvalidaBSolutionPename错误吗?该错误是由我不知道的类的切入点引起的';我没用?_Java_Classpath_Spring Aop - Fatal编程技术网

JavaSpringAOP:我可以忽略Xlint:InvalidaBSolutionPename错误吗?该错误是由我不知道的类的切入点引起的';我没用?

JavaSpringAOP:我可以忽略Xlint:InvalidaBSolutionPename错误吗?该错误是由我不知道的类的切入点引起的';我没用?,java,classpath,spring-aop,Java,Classpath,Spring Aop,我有一个关于通用组件和一个(十几个)应用程序的问题。我的组件有许多注释的切入点,可以在我的应用程序的类和方法中使用。当所有注释都出现在类路径上时,一切正常。但并非在我所有的应用程序中,我都有这些依赖项。当然,快速修复方法是添加它们,但这给了我的应用程序很多代码,而我在该应用程序中不需要这些代码。我正在寻找一种方法来忽略如下所述的Xlint:invalidabsolutionypename错误: 所以我有: 我有许多使用Soap/JMS连接的应用程序,所有应用程序都使用@Annotationor

我有一个关于通用组件和一个(十几个)应用程序的问题。我的组件有许多注释的切入点,可以在我的应用程序的类和方法中使用。当所有注释都出现在类路径上时,一切正常。但并非在我所有的应用程序中,我都有这些依赖项。当然,快速修复方法是添加它们,但这给了我的应用程序很多代码,而我在该应用程序中不需要这些代码。我正在寻找一种方法来忽略如下所述的
Xlint:invalidabsolutionypename
错误:

所以我有:

  • 我有许多使用Soap/JMS连接的应用程序,所有应用程序都使用@Annotation
    org.springframework.ws.server.endpoint.Annotation.endpoint
    进行注释
  • 我的通用组件(jar)中有切入点:
    @Around(“内部(@org.springframework.ws.server.endpoint.annotation.endpoint*)”
结果是:

  • 所有具有Spring WS依赖项和我的通用组件的应用程序都没有问题
  • 没有注释的应用程序无法启动,原因是
    java.lang.IllegalArgumentException:警告与此类型名称不匹配:org.springframework.ws.server.endpoint.annotation.endpoint[Xlint:invalidabsolutionpename]
    (很明显,请参见链接)
所以问题看起来像,但我不想添加我没有使用的Spring依赖项。我只想忽略这个AOP切入点。其他解决方法,如将切入点拆分到不同的jar,这样会产生太多开销。有没有办法让SpringAOP忽略这个切入点,或者将切入点设置为st like if exists(class)

为了说明为什么我认为分离会导致过多的开销,请查看我的方面结构:

@Aspect
public class PerformanceLoggingAspect {
    private LogWriter logWriter;

    @Inject
    public PerformanceLoggingAspect(LogWriter logWriter) {
        this.logWriter = logWriter;
    }

    @Around("within(@org.springframework.web.bind.annotation.RestController *)")
    public Object withinARestController(ProceedingJoinPoint pjp) throws Throwable {
        return proceedWithLogging(pjp, MetingType.REST);
    }

    @Around("within(@org.springframework.ws.server.endpoint.annotation.Endpoint *)")
    public Object withinAnEndpoint(ProceedingJoinPoint pjp) throws Throwable {
        return proceedWithLogging(pjp, MetingType.BERICHT);
    }

    @Around("within(@javax.inject.Named *)")
    public Object withinAService(ProceedingJoinPoint pjp) throws Throwable {
        return proceedWithLogging(pjp, MetingType.SERVICE);
    }

    private Object proceedWithLogging(ProceedingJoinPoint pjp, String metingType) throws Throwable {
        (... Working code (performance logging) if the annotation is on the classpath...)
    }
}
更新:我尝试创建一个
@NeedsClass(“any.package.Class”)
,这是一个来自spring上下文的
@Conditional
注释。condition类是一个
ClasspathCondition
,它检查类加载器是否可以加载给定的类。但是错误发生在条件被评估之前,所以我担心这是一条死胡同。但如果你好奇的话:

我尝试的
@NeedsClass
注释

    @Retention(RetentionPolicy.RUNTIME)
    @Target({ElementType.TYPE, ElementType.METHOD})
    @Documented
    @Conditional(ClasspathCondition.class)
    public @interface NeedsClass {
        String[] value();
    }
条件
实现。我在这里写过日志,但从来没有写过

    public class ClasspathCondition implements Condition {
        @Override
        public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
            try {
                String[] classes = (String[]) metadata.getAnnotationAttributes(NeedsClass.class.getName()).get("classes");
                for (String clazz : classes) {
                    ClassUtils.resolveClassName(clazz, context.getClassLoader());
                }
                return true;
            } catch (Throwable t) { /* noOp() */}
            return false;
        }
    }

目前,我有一个解决办法:

  • 我使用以下方法创建了一个超类:

    protected Object proceedWithLogging(ProceedingJoinPoint pjp, String metingType) throws Throwable {
        (... code which adds performance logging ...)
    }
    
  • 我创建了4个子类,每个子类都带有
    @Aspect
    注释,还有1个方法调用super。例如,这一个目标是JMS:

    @Aspect
    public class JmsPerformanceLogger extends PerformanceLoggingAspect {
        @Inject
        private LogWriter logWriter;
    
        @Around("within(@org.springframework.ws.server.endpoint.annotation.Endpoint *)")
        public Object withinAnEndpoint(ProceedingJoinPoint pjp) throws Throwable {
            return proceedWithLogging(pjp, MetingType.BERICHT);
        }
    }
    
  • 缺点是,我必须在我的应用程序中配置我需要的所有不同的bean,并且我无法添加一个简单的配置文件,如下所示,所有bean都已预配置:

    @Configuration
    public class PerformanceloggingConfig {
    
        @Bean
        public LogWriter performanceLogWriter(){
            return new DefaultLogWriter();
        }
    
        @Bean
        public JmsPerformanceLogger jmsPerformanceLogger(){
            return new JmsPerformanceLogger();
        }
        @Bean
        public RestPerformanceLogger restPerformanceLogger(){
            return new RestPerformanceLogger();
        }
        @Bean
        public ServicesPerformanceLogger servicesPerformanceLogger(){
            return new ServicesPerformanceLogger();
        }
        @Bean
        public DaoPerformanceLogger daoPerformanceLogger(){
            return new DaoPerformanceLogger();
        }
    }
    
    因此也不是自动配置类的方便注释:

    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.TYPE)
    @Import(PerformanceloggingConfig.class)
    public @interface EnablePerformanceLogging {
    
    }
    
    但就目前而言,在我需要的时候添加这4个bean,可以区分每个应用程序。当然,这仍然是一个解决方法,因为我想使用
    @EnablePerformanceLogging
    并完成它。如果有人有更好的答案,请告诉我

尝试注射豆类: