Grails

@Qualifier annotation is ignored in Grails application

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.2 final
  • Fix Version/s: 1.2.1
  • Component/s: Configuration
  • Labels:
    None

Description

Use of @Qualifier has no impact in Grails 1.2 on Spring beans that rely on @Autowired for dependency injection. I spent some time tracing it. Note that this used to work in 1.1.x. Here is what I've seen so far.

In Spring, the GenericApplicationContext creates a DefaultListableBeanFactory in its default constructor and sets it up with an QualifierAnnotationAutowireCandidateResolver, which is what detects @Qualifier.

In Grails, a GrailsApplicationContext can be created by DefaultRuntimeSpringConfiguration with a ReloadAwareAutowireCapableBeanFactory, which is not set up with the QualifierAnnotationAutowireCandidateResolver and therefore there is nothing to detect @Qualifier.

In my case I was able to work around the issue by adding primary="true" to one of my two SessionFactory bean instances thus helping to resolve the ambiguity but this will not work for every case.

Activity

Hide
Graeme Rocher added a comment -

fixed by http://github.com/grails/grails/commit/d9046e294ecda2ad46f1c94aaefe259a7e2790aa

I also added the LocalVariableTableParameterNameDiscoverer as GenericApplicationContext does

Show
Graeme Rocher added a comment - fixed by http://github.com/grails/grails/commit/d9046e294ecda2ad46f1c94aaefe259a7e2790aa I also added the LocalVariableTableParameterNameDiscoverer as GenericApplicationContext does

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: