Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Boot 1.15.11: java.lang.ExceptionInInitializerError #129

Closed
nicholassmith opened this issue Jan 24, 2020 · 7 comments
Closed

Spring Boot 1.15.11: java.lang.ExceptionInInitializerError #129

nicholassmith opened this issue Jan 24, 2020 · 7 comments

Comments

@nicholassmith
Copy link

I'm trying to migrate a project over from Mongobee to Mongock, so far I've stripped all Mongobee refs out and dropped in Mongock like this:

@Autowired
  public MongockMigrator(final MongoClient mongoClient,
                         final MongoTemplate mongoTemplate) {
    this.mongoTemplate = mongoTemplate;
    this.mongoClient = mongoClient;
  }

  @Override
  public void run(final String... strings) throws Exception {
    final Mongock runner = buildRunner();
    applyMigrations(runner);
  }

  private Mongock buildRunner() {
    return new MongockBuilder(
        this.mongoClient,
        this.mongoTemplate.getDb().getName(),
        ROOT
    ).build();
  }

  private static void applyMigrations(final Mongock runner) {
    runner.execute();
  }

However whenever I start up Spring I get: java.lang.ExceptionInInitializerError: null (happy to share more of the stack trace). I've made sure all of our existing @ChangeLogs and @ChangeSets are pointing to Mongock, and I've binary searched through some of the Mongock releases (1.16.2, 2.0.0, 2.0.2, 3.1.0-BETA) but can't seem to get past it.

Currently importing like this:
dependency 'com.github.cloudyrock.mongock:mongock-spring:1.16.2' in a main gradle file, and compile 'com.github.cloudyrock.mongock:mongock-spring:1.16.2' in the module gradle file

@alexciornii
Copy link

@nicholassmith Please share more of the stack trace. Also try to use 3.2.2.BETA version of mongock-spring.

@dieppa
Copy link
Member

dieppa commented Jan 24, 2020

Thanks @nicholassmith.
At first I can see one important thing, you are mixing standalone mongock with springMongock,. You're probably using Springboot, so I suggest this:
new SpringBootMongockBuilder(mongoClient, "yourDbName", "com.package.to.be.scanned.for.changesets") .setApplicationContext(springContext) .setLockQuickConfig() .build();

SpringContext is optional, but very helpful if you require any other dependency than MongoTempalte/MongoDatabase in your changeSet.

The lock is also optional, but highly recommended as without this, the lock behaviour is the legacy one, and is very poor, if anything happens, doesn't unlock for 24hours, but doesn't throw any exception if lock cannot be acquired.

Also, if you use the last versión, 3.2.2.BETA, as @alexciornii suggest, you can initialise SpringBootMongockBuilder with MongoTemplate, having something like this:

new SpringBootMongockBuilder(mongotemplate,"com.package.to.be.scanned.for.changesets") .setApplicationContext(springContext) .setLockQuickConfig() .build();

Please have a try with that, and let us know ;)

@nicholassmith
Copy link
Author

Thanks for the replies! @alexciornii here's further stack trace:

Caused by: java.lang.IllegalArgumentException: null
	at org.objectweb.asm.ClassVisitor.<init>(Unknown Source)
	at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:49)
	at net.sf.cglib.core.DefaultGeneratorStrategy.getClassVisitor(DefaultGeneratorStrategy.java:30)
	at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)
	at net.sf.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:329)
	at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93)
	at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91)
	at net.sf.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at net.sf.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
	at net.sf.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
	at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116)
	at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291)
	at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221)
	at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:174)
	at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:153)
	at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:73)
	... 12 common frames omitted

I can't use 3.2.2.BETA however as it pulls in the latest version of some Spring dependencies which breaks a lot of our response layer code, even with them excluded as dependencies:

compile ('com.github.cloudyrock.mongock:mongock-core:3.2.1.BETA') {
    exclude group: 'org.springframework'
  }

  compile ("com.github.cloudyrock.mongock:mongock-spring:3.2.1.BETA") {
    exclude group: 'org.springframework'
  }

@dieppa
Copy link
Member

dieppa commented Jan 27, 2020

Hi @nicholassmith , we'll be looking at this evening. I will come back to you.

Cheers

@nicholassmith
Copy link
Author

Got further, the exclude has to be very specific org.springframework.data in my case, however I get snagged on A component required a bean of type 'com.mongodb.DB' that could not be found. instead. I suspect that because we're trying to use a much older version of Spring Boot there's some requirement mismatches.

@dieppa
Copy link
Member

dieppa commented Jan 28, 2020

Sorry @nicholassmith , I wasn't able to have a look yesterday. I will try today, but I cannot commit as we got something urgent. I will keep you posted.

However, it seems, as you say, you are using an older version.
On the bright side, we are refactoring the entire framework in such a way we are going to provide much better support for old versions of frameworks(spring, etc), driver and MongoDB(3.X, 4.X), etc.) But this hasn't been released yet and I don't this will be ready until next month. So, we'll try to fix your current issue and then, my suggestion is to move to the new refactored version(keeping the versions of Spring, etc you are using)

As said, I will keep you posted

@dieppa
Copy link
Member

dieppa commented Feb 13, 2020

Hello @nicholassmith , I don't know if you have worked it around or not. But Just for you to know that com.mongodb.DB is not supported in the new 3.X version( I just realised it now, after reading your message again). You should use MongoDatabase.

Let me know how it goes

@dieppa dieppa closed this as completed Feb 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants