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 kotlin unit test alway fail with spring data jpa + mongodb In spring version 2.0.0.RELEASE [DATACMNS-1575] #2001

Closed
spring-projects-issues opened this issue Aug 31, 2019 · 2 comments
Assignees
Labels
in: repository status: declined type: bug

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Aug 31, 2019

Promswas Pitakmetakul opened DATACMNS-1575 and commented

You can see environment in my git hub 

 

It been occur for month with no reason.

I try to switch to another git commit on real code project which work before but it doesn't work at all at this time.

And also in pom I try to chang to another version of every configuration either, But got the same error.

Every single git commit error when @Autowrite repository found in unit test.

 

Error occur run a unit test only and also happen in main application test.

If I run project up normally every thing just work fine.

 

My project can't be continue without TDD and test coverage test because it super wider of conception, Please.

I'm gonna recheck this all again either, Thank you.

!image-2019-09-01-00-45-22-239.png!


Reference URL: https://github.com/MrParkerZ7/demo-kotlin-test.git

Attachments:

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 31, 2019

Oliver Drotbohm commented

Your repository declaration is invalid. Demo is annotated with @Document which indicates it's supposed to be handled by a MongoDB repository. Your DemoRepository on the other hand extends JpaRepository. In DemoKotlinTestApplicationTests this causes a bean definition to be created both for MongoDB and JPA, which is clearly warned in the log output and fails with a message describing the exact problem:

2019-08-31 21:08:01.631 DEBUG 53961 --- [           main] o.s.d.r.c.RepositoryComponentProvider    : Identified candidate component class: file [/Users/odrotbohm/temp/demo-kotlin-test/target/classes/com/example/demo/kotlin/test/demokotlintest/DemoRepository.class]
2019-08-31 21:08:01.637  WARN 53961 --- [           main] o.s.w.c.s.GenericWebApplicationContext   : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'demoRepository' defined in null: Cannot register bean definition [Root bean: class [org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] for bean 'demoRepository': There is already [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] bound.
2019-08-31 21:08:01.811  INFO 53961 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-08-31 21:08:01.813 ERROR 53961 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'demoRepository', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

DemoControllerTest you use @WebMvcTest that clearly states that it does not bootstrap repositories at all so that the test case of course fails with the repository instance missing

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 1, 2019

Promswas Pitakmetakul commented

Oh, My mistake!

I must carefully than this.

Thank you so much for help me out :)

@spring-projects-issues spring-projects-issues added type: bug status: declined in: repository labels Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: repository status: declined type: bug
Projects
None yet
Development

No branches or pull requests

2 participants