How to solve CompletionFailure when using EclipseLink Modelgen processor and Spring Security?

跟風遠走 提交于 2019-12-10 17:27:23

问题


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

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

@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

public class SecurityConfig extends WebSecurityConfigurerAdapter {

}

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'
}

As soon as I remove

a) the @Entity from MyEntity

or

b) extends WebSecurityConfigurerAdapter from Security Config

or

c) use compile 'org.hibernate:hibernate-jpamodelgen:4.3.10.Final' instead of compile 'org.eclipse.persistence:org.eclipse.persistence.jpa.modelgen.processor:2.6.0'

everything compiles without problems.

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


回答1:


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.

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

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.

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).



来源:https://stackoverflow.com/questions/31832360/how-to-solve-completionfailure-when-using-eclipselink-modelgen-processor-and-spr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!