mongock: Use mongock with springboot 2.0.7 but do not work

I copy/pase your sample:

@Bean
public SpringBootMongock mongock(ApplicationContext springContext, MongoClient mongoClient) {
  return new SpringBootMongockBuilder(mongoClient, "yourDbName", "com.package.to.be.scanned.for.changesets")
      .setApplicationContext(springContext) 
      .setLockQuickConfig()
      .build();
}

but I need add a cast:

@Bean
public SpringBootMongock mongock(ApplicationContext springContext, MongoClient mongoClient) {
  return (SpringBootMongock) new SpringBootMongockBuilder(mongoClient, "yourDbName", "com.package.to.be.scanned.for.changesets")
      .setApplicationContext(springContext) 
      .setLockQuickConfig()
      .build();
}

and after I had this problem:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongock' defined in class path resource [com/myproject/user/configuration/MongoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.cloudyrock.mongock.SpringBootMongock]: Factory method 'mongock' threw exception; nested exception is java.lang.ExceptionInInitializerError
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:591) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1246) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:548) ~[spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]
	at com.myproject.user.UserServerApplication.main(UserServerApplication.java:19) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.cloudyrock.mongock.SpringBootMongock]: Factory method 'mongock' threw exception; nested exception is java.lang.ExceptionInInitializerError
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:583) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	... 18 common frames omitted
Caused by: java.lang.ExceptionInInitializerError: null
	at com.github.cloudyrock.mongock.ProxyFactory.createProxyClass(ProxyFactory.java:58) ~[mongock-core-1.16.1.jar:na]
	at com.github.cloudyrock.mongock.ProxyFactory.createProxyFromOriginal(ProxyFactory.java:99) ~[mongock-core-1.16.1.jar:na]
	at com.github.cloudyrock.mongock.SpringBootMongockBuilder.build(SpringBootMongockBuilder.java:80) ~[mongock-spring-1.16.1.jar:na]
	at com.github.cloudyrock.mongock.SpringBootMongockBuilder.build(SpringBootMongockBuilder.java:15) ~[mongock-spring-1.16.1.jar:na]
	at com.myproject.user.configuration.MongoConfiguration.mongock(MongoConfiguration.java:35) ~[classes/:na]
	at com.myproject.user.configuration.MongoConfiguration$$EnhancerBySpringCGLIB$$cc3decd7.CGLIB$mongock$0(<generated>) ~[classes/:na]
	at com.myproject.user.configuration.MongoConfiguration$$EnhancerBySpringCGLIB$$cc3decd7$$FastClassBySpringCGLIB$$c35f50f6.invoke(<generated>) ~[classes/:na]
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:365) ~[spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at com.myproject.user.configuration.MongoConfiguration$$EnhancerBySpringCGLIB$$cc3decd7.mongock(<generated>) ~[classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	... 19 common frames omitted
Caused by: java.lang.IllegalArgumentException: null
	at org.objectweb.asm.ClassVisitor.<init>(Unknown Source) ~[asm-5.0.4.jar:5.0.4]
	at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:49) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.DefaultGeneratorStrategy.getClassVisitor(DefaultGeneratorStrategy.java:30) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:329) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) ~[cglib-3.2.7.jar:na]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_191]
	at net.sf.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:174) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:153) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:73) ~[cglib-3.2.7.jar:na]
	... 34 common frames omitted

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 40 (22 by maintainers)

Most upvoted comments

OK, the sample work, I looking for the diff.

EDIT:

Now, MongoTemplate is fixed (changeSet2) but Mongodatabase does not work anymore.

I reput this:

    @ChangeSet(order = "001", id = "createUserCollection", author = "sgrillon")
    public void createUserCollection(final MongoDatabase db) {
           db.getCollection(COLLECTION_NAME).insertOne(createMongoDocument(new ClientDomain("Gerorge1 " + LocalDateTime.now().toString(), "Orwell")));
    }
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongock' defined in com.github.cloudyrock.mongock.springboot207sample.Springboot207SampleApplication: Invocation of init method failed; nested exception is com.github.cloudyrock.mongock.MongockException: Class com.github.cloudyrock.mongock.ProxyMethodInterceptor can not access a member of class com.mongodb.MongoDatabaseImpl with modifiers "public"
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1694) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:548) ~[spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]
	at com.github.cloudyrock.mongock.springboot207sample.Springboot207SampleApplication.main(Springboot207SampleApplication.java:15) [classes/:na]
Caused by: com.github.cloudyrock.mongock.MongockException: Class com.github.cloudyrock.mongock.ProxyMethodInterceptor can not access a member of class com.mongodb.MongoDatabaseImpl with modifiers "public"
	at com.github.cloudyrock.mongock.Mongock.executeMigration(Mongock.java:123) ~[mongock-core-2.0.0-BETA.jar:na]
	at com.github.cloudyrock.mongock.Mongock.execute(Mongock.java:67) ~[mongock-core-2.0.0-BETA.jar:na]
	at com.github.cloudyrock.mongock.SpringMongock.afterPropertiesSet(SpringMongock.java:30) ~[mongock-spring-2.0.0-BETA.jar:na]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1753) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1690) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	... 16 common frames omitted
Caused by: java.lang.reflect.InvocationTargetException: null
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
	at com.github.cloudyrock.mongock.Mongock.executeChangeSetMethod(Mongock.java:157) ~[mongock-core-2.0.0-BETA.jar:na]
	at com.github.cloudyrock.mongock.SpringMongock.executeChangeSetMethod(SpringMongock.java:48) ~[mongock-spring-2.0.0-BETA.jar:na]
	at com.github.cloudyrock.mongock.Mongock.executeIfNewOrRunAlways(Mongock.java:132) ~[mongock-core-2.0.0-BETA.jar:na]
	at com.github.cloudyrock.mongock.Mongock.executeMigration(Mongock.java:116) ~[mongock-core-2.0.0-BETA.jar:na]
	... 20 common frames omitted
Caused by: java.lang.IllegalAccessException: Class com.github.cloudyrock.mongock.ProxyMethodInterceptor can not access a member of class com.mongodb.MongoDatabaseImpl with modifiers "public"
	at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102) ~[na:1.8.0_191]
	at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296) ~[na:1.8.0_191]
	at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288) ~[na:1.8.0_191]
	at java.lang.reflect.Method.invoke(Method.java:491) ~[na:1.8.0_191]
	at com.github.cloudyrock.mongock.ProxyMethodInterceptor.invokeMethod(ProxyMethodInterceptor.java:50) ~[mongock-core-2.0.0-BETA.jar:na]
	at com.github.cloudyrock.mongock.ProxyMethodInterceptor.intercept(ProxyMethodInterceptor.java:38) ~[mongock-core-2.0.0-BETA.jar:na]
	at com.mongodb.MongoDatabaseImpl$$EnhancerByMongock$$89f7e5c2.getCollection(<generated>) ~[mongodb-driver-3.6.4.jar:na]
	at com.github.cloudyrock.mongock.springboot207sample.changesets.ClientChangeLog.createUserCollection(ClientChangeLog.java:24) ~[classes/:na]
	... 28 common frames omitted

I try use Mongock in a more simple projet. I looking for where from MongoDatabase db of public void someChange2(MongoDatabase db) {

I think in auto-configuration of spring-boot-starter-data-mongodb but I have this:

***************************
APPLICATION FAILED TO START
***************************
Description:
A component required a bean of type 'com.mongodb.client.MongoDatabase' that could not be found.
Action:
Consider defining a bean of type 'com.mongodb.client.MongoDatabase' in your configuration.

I find the problem:

spring-cloud-starter-netflix-hystrix import old version of asm, so I exclude this

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
            <exclusions>
            <exclusion>
             <groupId>org.ow2.asm</groupId>
                <artifactId>asm</artifactId>
            </exclusion>
            </exclusions>
        </dependency>