micronaut-projects / micronaut-groovy

Projects that enhance the Micronaut + Groovy experience
Apache License 2.0
17 stars 10 forks source link

ApplicationContext.getBeansOfType returns duplicate references to same instance #393

Closed wetted closed 1 year ago

wetted commented 2 years ago

Expected Behavior

micronaut-groovy PR 365: "fix(deps): update micronautversion to v3.6.0" is failing due to a broken test GormConfigSpec in the hibernate-gorm subproject.

It should pass, and has for versions up micronaut 3.5.

Actual Behaviour

Starting with Micronaut 3.5, GormConfigSpec."verity PlatformTransactionManager is qualified with name hibernate"() fails at line 66 where it calls applicationContext.getBeansOfType(PlatformTransactionManager).size() == 2 and the result is 4 instead of 2.

The call to applicationContext.getBeansOfType(PlatformTransactionManager) results in three references to the same instance of PlatformTransactionManager instead of one. The following is a copy of evaluating the statement debugging the test case. Note the three copies of GrailsHibernateTransactionManager with the same address.

result = {ArrayList@11553}  size = 4
 0 = {MockPlatformTransactionManager@11556} 
 1 = {GrailsHibernateTransactionManager@11557} 
 2 = {GrailsHibernateTransactionManager@11557} 
 3 = {GrailsHibernateTransactionManager@11557} 

Steps To Reproduce

Clone the branch at https://github.com/micronaut-projects/micronaut-groovy/tree/renovate/micronautversion Execute the task :hibernate-gorm:test or just run the GormConfigSpec

Setting micronautVersion to 3.4.4 or less works Setting micronautVersion to 3.5.0 or later fails

Environment Information

macOS 12.5 JDK 11 or 17 (I did not try 8)

Example Application

No response

Version

3.5.0+

graemerocher commented 2 years ago

@dstepanov think this is due to the changes to the bean resolution. Could you take a look?

dstepanov commented 2 years ago

I will check

sdelamo commented 1 year ago

@dstepanov @wetted is this fixed?

wetted commented 1 year ago

@dstepanov @wetted is this fixed?

The PR I referenced in the issue description was merged to master; however, I cannot build master. It now points to core 4.0.0-SNAPSHOT and the build fails to compile due to a removed class in groovy-inject. I have not investigated further.

.../micronaut-groovy/function-groovy/src/main/groovy/io/micronaut/function/groovy/FunctionTransform.groovy: 19: unable to resolve class io.micronaut.ast.groovy.utils.AstAnnotationUtils
 @ line 19, column 1.
   import io.micronaut.ast.groovy.utils.AstAnnotationUtils
dstepanov commented 1 year ago

Found a bug https://github.com/micronaut-projects/micronaut-core/pull/8182

dstepanov commented 1 year ago

https://github.com/micronaut-projects/micronaut-groovy/compare/444

I fixed the problem but now I see I get multiple route error because /max hits this methods:

12 = {AbstractExecutableMethodsDefinition$DispatchedExecutableMethod@6412} "Long get()" 10 = {AbstractExecutableMethodsDefinition$DispatchedExecutableMethod@6417} "Long max()" 8 = {AbstractExecutableMethodsDefinition$DispatchedExecutableMethod@6428} "Object get(String arg0)"

Any idea how does it work?

dstepanov commented 1 year ago

This should be fixed