使用EclipseLink Modelgen处理器和Spring Security时如何解决CompletionFailure? [英] How to solve CompletionFailure when using EclipseLink Modelgen processor and Spring Security?

查看:103
本文介绍了使用EclipseLink Modelgen处理器和Spring Security时如何解决CompletionFailure?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一个使用eclipselink作为modelgen处理器来生成静态元模型的项目中使用Spring Security。
当我尝试执行此操作时,出现奇怪的编译错误,例如:

I am trying to use Spring Security in a project where I use eclipselink as the modelgen processor to generate the static meta model. When I try to do this I get strange compilation errors like:

> java.lang.RuntimeException: com.sun.tools.javac.code.Symbol$CompletionFailure: class file for org.springframework.security.ldap.DefaultSpringSecurityContextSource not found

即使我不使用LDAP。如果我添加了jar,则会遇到其他错误,例如缺少sl4j,缺少openid等。
如果我将使用的modelgen处理器与休眠实现进行交换,则所有编译都不会出现问题。

even though I do not use LDAP. If I add the jars I get other errors like missing sl4j, missing openid, etc etc. If I exchange the used modelgen processor with the hibernate implementation everything compiles without problems.

我找到了一个最小的项目来重现该问题:

I found a minimal project to reproduce the problem:

MyEnity.java

MyEnity.java

@Entity
public class MyEntity {

    private String name;
    private Long id;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

}

SecurityConfig.java

SecurityConfig.java

public class SecurityConfig extends WebSecurityConfigurerAdapter {

}

build.gradle

build.gradle

apply plugin: 'war'
apply plugin: 'maven'

group = 'com.demo'
version = 'alpha'

sourceCompatibility = 1.8
targetCompatibility = 1.8

[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

repositories {
    maven { url "http://repo.maven.apache.org/maven2" }
    maven { url "http://download.eclipse.org/rt/eclipselink/maven.repo/" }
}


dependencies {
    compile 'org.eclipse.persistence:org.eclipse.persistence.jpa.modelgen.processor:2.6.0'//latest stable @06.07.2015


    compile "org.springframework:spring-beans:4.1.6.RELEASE"
    compile "org.springframework:spring-core:4.1.6.RELEASE"
    compile "org.springframework:spring-web:4.1.6.RELEASE"
    compile "org.springframework:spring-context:4.1.6.RELEASE"
    compile 'org.springframework:spring-jdbc:4.1.6.RELEASE'
    compile 'org.springframework.security:spring-security-core:4.0.2.RELEASE'
    compile 'org.springframework.security:spring-security-web:4.0.2.RELEASE'
    compile 'org.springframework.security:spring-security-config:4.0.2.RELEASE'

    providedCompile 'javax:javaee-api:7.0@jar'
}

我删除

a) @Entity from MyEntity

a) the @Entity from MyEntity

b)从Security Config扩展了WebSecurityConfigurerAdapter

b) extends WebSecurityConfigurerAdapter from Security Config

c)使用编译'org.hibernate:hibernate-jpamodelgen:4.3.10.Final'
而不是编译'org.eclipse.persistence:org.eclipse.persistence.jpa.modelgen.processor:2.6.0'

所有内容都能正常编译。

everything compiles without problems.

所以w为何使用eclipselink modelgen处理器会导致编译错误?

So why does the use of the eclipselink modelgen processor cause compilation errors?

推荐答案

问题是 CanonicalModelProcessor EclipseLink modelgen,甚至使用版本2.7.4。它可以作为 Java代理来获取类路径上的所有类进行处理。在某个时候,它命中了一个Spring Security类(例如我的 HttpSecurity ),它间接依赖于在类路径中找不到的库(通常来自内部类或由于Spring设计得很好,因此可以返回工厂返回类型, HttpSecurity.openidLogin()返回的 OpenIDLoginConfigurer OpenIDAttribute 等)(在这种情况下,整个代理崩溃,而不是跳过类型。

The problem is the CanonicalModelProcessor of EclipseLink modelgen, even using version 2.7.4. It works as a Java Agent getting all classes on the classpath to process. At some point it hits a Spring Security class (like HttpSecurity in my case) which has a indirect dependency on a library not found on the classpath (typically from an inner class or a factory return type as Spring is designed fine, OpenIDLoginConfigurer returned by HttpSecurity.openidLogin() referencing OpenIDAttribute etc. in my case) - at that point the whole agent crashes instead of skipping the type.

问题并非特定于Spring)或Spring Security,但任何在类路径上缺少可选依赖项的项目!

The problem is not specific to Spring or Spring Security but any project using optional dependencies missing on the classpath!

令人惊讶的是,它似乎可以在OpenJDK 11上运行,但不能在OpenJDK 8上运行。 $ c> CanonicalModelProcessor 有问题。最后,我将生成的元模型添加到我们的项目存储库中,并暂时删除了modelgen。

Surprisingly it seems to work using OpenJDK 11 but not using OpenJDK 8. From my point the CanonicalModelProcessor is buggy. At the end I added the generated meta model to our project repo and dropped modelgen for now.

更新:我知道这不是真正的答案(如果您不能使用OpenJDK, 11),但至少我想弄清楚这是EclipseLink的错误,没有解决方法(据我所知)。

UPDATE: I know this is no real answer (if you cannot move to OpenJDK 11) but at least I wanted to make clear it is a bug of EclipseLink without a workaround (as far as I know).

这篇关于使用EclipseLink Modelgen处理器和Spring Security时如何解决CompletionFailure?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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