Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

SimpleMongoRepository - No suitable constructor found #1487

Closed
atyamlalithya opened this issue Feb 8, 2022 · 8 comments
Closed

SimpleMongoRepository - No suitable constructor found #1487

atyamlalithya opened this issue Feb 8, 2022 · 8 comments
Assignees
Labels
type: regression A bug that is also a regression
Milestone

Comments

@atyamlalithya
Copy link

atyamlalithya commented Feb 8, 2022

I am trying to create a native executable using gaarlvm for my spring boot application that uses @EnableMongoRepositories to scan its repositories.
The build is successful and it is working fine as a spring boot application but running the exe file is throwing below exception. Also attaching a sample for reproducing the issue.
demo.zip

Error stacktrace:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is java.lang.IllegalStateException: No suitable constructor found on class org.springframework.data.mongodb.repository.support.SimpleMongoRepository to match the given arguments: org.springframework.data.mongodb.repository.support.MappingMongoEntityInformation, org.springframework.data.mongodb.core.MongoTemplate. Make sure you implement a constructor taking these
        at org.springframework.aot.beans.factory.InjectedFieldResolver.resolve(InjectedFieldResolver.java:50) ~[na:na]
        at org.springframework.aot.beans.factory.InjectedElementResolver.resolve(InjectedElementResolver.java:19) ~[na:na]
        at org.springframework.aot.beans.factory.InjectedElementResolver.invoke(InjectedElementResolver.java:37) ~[na:na]
        at com.example.demo.ContextBootstrapInitializer.lambda$registerUserController$3(ContextBootstrapInitializer.java:30) ~[na:na]
        at org.springframework.aot.beans.factory.ThrowableFunction.apply(ThrowableFunction.java:18) ~[na:na]
        at org.springframework.aot.beans.factory.BeanDefinitionRegistrar.lambda$instanceSupplier$0(BeanDefinitionRegistrar.java:97) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1249) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1191) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[na:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[na:na]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[na:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[na:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[na:na]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[na:na]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[na:na]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[na:na]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[na:na]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[demo.exe:0.0.1-SNAPSHOT]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) ~[demo.exe:0.0.1-SNAPSHOT]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[demo.exe:0.0.1-SNAPSHOT]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[demo.exe:0.0.1-SNAPSHOT]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) ~[demo.exe:0.0.1-SNAPSHOT]
        at com.example.demo.DemoApplication.main(DemoApplication.java:12) ~[demo.exe:0.0.1-SNAPSHOT]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is java.lang.IllegalStateException: No suitable constructor found on class org.springframework.data.mongodb.repository.support.SimpleMongoRepository to match the given arguments: org.springframework.data.mongodb.repository.support.MappingMongoEntityInformation, org.springframework.data.mongodb.core.MongoTemplate. Make sure you implement a constructor taking these
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[na:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[na:na]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[na:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[na:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[na:na]
        at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[na:na]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1389) ~[na:na]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309) ~[na:na]
        at org.springframework.aot.beans.factory.InjectedFieldResolver.resolve(InjectedFieldResolver.java:43) ~[na:na]
        ... 23 common frames omitted
Caused by: java.lang.IllegalStateException: No suitable constructor found on class org.springframework.data.mongodb.repository.support.SimpleMongoRepository to match the given arguments: org.springframework.data.mongodb.repository.support.MappingMongoEntityInformation, org.springframework.data.mongodb.core.MongoTemplate. Make sure you implement a constructor taking these
        at org.springframework.data.repository.core.support.RepositoryFactorySupport.lambda$instantiateClass$6(RepositoryFactorySupport.java:578) ~[na:na]
        at java.util.Optional.orElseThrow(Optional.java:408) ~[na:na]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport.instantiateClass(RepositoryFactorySupport.java:578) ~[na:na]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepositoryViaReflection(RepositoryFactorySupport.java:542) ~[na:na]
        at org.springframework.data.mongodb.repository.support.MongoRepositoryFactory.getTargetRepository(MongoRepositoryFactory.java:136) ~[demo.exe:0.0.1-SNAPSHOT]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:324) ~[na:na]
        at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:322) ~[demo.exe:0.0.1-SNAPSHOT]
        at org.springframework.data.util.Lazy.getNullable(Lazy.java:230) ~[na:na]
        at org.springframework.data.util.Lazy.get(Lazy.java:114) ~[na:na]
        at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:328) ~[demo.exe:0.0.1-SNAPSHOT]
        at org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean.afterPropertiesSet(MongoRepositoryFactoryBean.java:119) ~[demo.exe:0.0.1-SNAPSHOT]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[na:na]
        ... 33 common frames omitted
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 8, 2022
@snicoll snicoll changed the title Getting error - No suitable constructor found on class org.springframework.data.mongodb.repository.support.SimpleMongoRepository to match the given arguments: org.springframework.data.mongodb.repository.support.MappingMongoEntityInformation, org.springframework.data.mongodb.core.MongoTemplate. when using @EnableMongoRepositories SimpleMongoRepository - No suitable constructor found Feb 9, 2022
@snicoll
Copy link
Contributor

snicoll commented Feb 9, 2022

@atyamlalithya this sounds like a duplicate of #1457. Unfortunately, we never got feedback from the report. Can you please attach a small sample that reproduces the issue so that we ca run this ourselves? You can do so by attaching a zip to this issue or sharing a link to a GitHub repository.

EDIT: apologizes,I didn't see the link to the sample.

@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 9, 2022
@atyamlalithya
Copy link
Author

@snicoll Yes the attached zip is a sample for this issue. Please let me know if you need more information to reproduce the issue. Thanks!

@sdeleuze sdeleuze self-assigned this Feb 15, 2022
@sdeleuze sdeleuze added this to the 0.11.3 milestone Feb 15, 2022
@sdeleuze sdeleuze added type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 15, 2022
@bechhansen
Copy link

bechhansen commented Mar 16, 2022

Hi @sdeleuze

I have the exact same issue just using Cassandra repository.

org.springframework.boot: 2.6.4.
org.springframework.experimental.aot: 0.11.3
io.spring.dependency-management: 1.0.11.RELEASE
Java: zulu11.54.25-ca-jdk11.0.14.1

Any solution or workarround?

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.6.4)

08:46:58.981 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'keyValueService': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'keyValueEntityRepository': Invocation of init method failed; nested exception is java.lang.IllegalStateException: No suitable constructor found on class org.springframework.data.cassandra.repository.support.SimpleCassandraRepository to match the given arguments: org.springframework.data.cassandra.repository.support.MappingCassandraEntityInformation, org.springframework.data.cassandra.core.CassandraTemplate. Make sure you implement a constructor taking these
        at org.springframework.aot.beans.factory.InjectedConstructionResolver.resolve(InjectedConstructionResolver.java:88) ~[?:?]
        at org.springframework.aot.beans.factory.InjectedElementResolver.resolve(InjectedElementResolver.java:35) ~[?:?]
        at org.springframework.aot.beans.factory.InjectedElementResolver.create(InjectedElementResolver.java:66) ~[?:?]
        at org.springframework.aot.beans.factory.BeanDefinitionRegistrar$BeanInstanceContext.create(BeanDefinitionRegistrar.java:211) ~[?:?]
        at com.example.nkvs.ContextBootstrapInitializer.lambda$registerKeyValueService$2(ContextBootstrapInitializer.java:15) ~[?:?]
        at org.springframework.aot.beans.factory.BeanDefinitionRegistrar$ThrowableFunction.apply(BeanDefinitionRegistrar.java:294) ~[?:?]
        at org.springframework.aot.beans.factory.BeanDefinitionRegistrar.lambda$instanceSupplier$0(BeanDefinitionRegistrar.java:115) ~[?:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1249) ~[?:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1191) ~[?:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[?:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[?:?]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[?:?]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[?:?]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[?:?]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[?:?]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[?:?]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[?:?]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[?:?]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) [com.example.widget.WidgetRestServiceApplication:2.6.4]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) [com.example.widget.WidgetRestServiceApplication:2.6.4]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [com.example.widget.WidgetRestServiceApplication:2.6.4]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) [com.example.widget.WidgetRestServiceApplication:2.6.4]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) [com.example.widget.WidgetRestServiceApplication:2.6.4]
        at com.example.widget.WidgetRestServiceApplication.main(WidgetRestServiceApplication.java:17) [com.example.widget.WidgetRestServiceApplication:?]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'keyValueEntityRepository': Invocation of init method failed; nested exception is java.lang.IllegalStateException: No suitable constructor found on class org.springframework.data.cassandra.repository.support.SimpleCassandraRepository to match the given arguments: org.springframework.data.cassandra.repository.support.MappingCassandraEntityInformation, org.springframework.data.cassandra.core.CassandraTemplate. Make sure you implement a constructor taking these
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[?:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[?:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[?:?]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[?:?]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[?:?]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[?:?]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[?:?]
        at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[?:?]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1389) ~[?:?]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309) ~[?:?]
        at org.springframework.aot.beans.factory.InjectedConstructionResolver.lambda$resolve$0(InjectedConstructionResolver.java:83) ~[?:?]
        at org.springframework.aot.beans.factory.InjectedConstructionResolver.resolveDependency(InjectedConstructionResolver.java:97) ~[?:?]
        at org.springframework.aot.beans.factory.InjectedConstructionResolver.resolve(InjectedConstructionResolver.java:83) ~[?:?]
        ... 23 more
Caused by: java.lang.IllegalStateException: No suitable constructor found on class org.springframework.data.cassandra.repository.support.SimpleCassandraRepository to match the given arguments: org.springframework.data.cassandra.repository.support.MappingCassandraEntityInformation, org.springframework.data.cassandra.core.CassandraTemplate. Make sure you implement a constructor taking these
        at org.springframework.data.repository.core.support.RepositoryFactorySupport.lambda$instantiateClass$6(RepositoryFactorySupport.java:579) ~[?:?]
        at java.util.Optional.orElseThrow(Optional.java:408) ~[?:?]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport.instantiateClass(RepositoryFactorySupport.java:579) ~[?:?]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepositoryViaReflection(RepositoryFactorySupport.java:543) ~[?:?]
        at org.springframework.data.cassandra.repository.support.CassandraRepositoryFactory.getTargetRepository(CassandraRepositoryFactory.java:90) ~[com.example.widget.WidgetRestServiceApplication:3.3.2]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:324) ~[?:?]
        at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:322) ~[com.example.widget.WidgetRestServiceApplication:2.6.2]
        at org.springframework.data.util.Lazy.getNullable(Lazy.java:230) ~[?:?]
        at org.springframework.data.util.Lazy.get(Lazy.java:114) ~[?:?]
        at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:328) ~[com.example.widget.WidgetRestServiceApplication:2.6.2]
        at org.springframework.data.cassandra.repository.support.CassandraRepositoryFactoryBean.afterPropertiesSet(CassandraRepositoryFactoryBean.java:75) ~[com.example.widget.WidgetRestServiceApplication:3.3.2]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[?:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[?:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[?:?]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[?:?]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[?:?]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[?:?]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[?:?]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[?:?]
        at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[?:?]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1389) ~[?:?]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309) ~[?:?]
        at org.springframework.aot.beans.factory.InjectedConstructionResolver.lambda$resolve$0(InjectedConstructionResolver.java:83) ~[?:?]
        at org.springframework.aot.beans.factory.InjectedConstructionResolver.resolveDependency(InjectedConstructionResolver.java:97) ~[?:?]
        at org.springframework.aot.beans.factory.InjectedConstructionResolver.resolve(InjectedConstructionResolver.java:83) ~[?:?]
        ... 23 more

@atyamlalithya
Copy link
Author

A workaround would be to add the hints manually.
We added something like this in our springboot application class for time being.
@NativeHint(types = {@typehint(types = {
org.springframework.data.mongodb.core.mapping.event.BeforeConvertCallback.class,
org.springframework.data.mongodb.core.mapping.event.AfterConvertCallback.class,
org.springframework.data.mongodb.repository.support.SimpleMongoRepository.class}, access = {
TypeAccess.DECLARED_CONSTRUCTORS, TypeAccess.PUBLIC_METHODS})})
May be try to identify the cassandra classes you need and add similar hints. Hope this helps!

@sdeleuze
Copy link
Contributor

Cassandra is currently not supported, and since we are focusing most of our effort on Spring Boot 3, we are unlikely to provide such support in Spring Native unless you provide a PR, getting inspiration from other Spring Data supported technologies.

@bechhansen
Copy link

Hi @atyamlalithya and @sdeleuze

Thank you both for that. I looked at the hint code for MongoDB and made a similar hint class for Cassandra. That made the error go away, but I have not been able to test it as I'm now struggling with this: #1053 (comment)

@snicoll
Copy link
Contributor

snicoll commented Mar 18, 2022

@bechhansen as I've indicated there, please create a separate issue once you have a small sample we can use to reproduce.

@bechhansen
Copy link

@snicoll thank you.

I'm currently working on that. I have not yet found the smoking gun, coursing this issue. I'm trying to convert an existing service, with some dependencies probable responsible for the issue.

I have tried a small service made using the Spring Initializr and that works .

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: regression A bug that is also a regression
Development

No branches or pull requests

6 participants