4

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?

Arne Burmeister
  • 20,046
  • 8
  • 53
  • 94
drame
  • 435
  • 1
  • 4
  • 14
  • I have the same problem. – ravshansbox Aug 06 '15 at 06:55
  • Did you find any solution to that? I am facing the same problem. – Maciej Nov 27 '15 at 14:51
  • @Maciej I worked around the problem by using the hibernate-jpamodelgen as mentioned in my original question. So far I had no problems using the metamodel generated by hibernate with Ecpliselink as the persistence provider. – drame Nov 30 '15 at 11:51

1 Answers1

0

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

Arne Burmeister
  • 20,046
  • 8
  • 53
  • 94