Search code examples
javajakarta-eequalifiers

The annotation @Qualifier is disallowed for this location


@Override
@Autowired(required = true)
@Qualifier("hibernateCriteriaBuilder")
public void setCriteriaBuilder(IQueryCriteriaBuilder<Entity> criteriabuilder)
{
  super.setCriteriaBuilder(criteriaBuilder):
}

This in the code I have in a java file and i keep getting a error saying: "The annotation @qualifier is diallowed for this location." Can someone explain to me how I can fix this error? I have it twice in my code and have had trouble finding a solution.


Solution

  • I believe you'll have more luck using it on the parameter of your method, like so:

    @Override
    @Autowired
    public void setCriteriaBuilder(
        @Qualifier("hibernateCriteriaBuilder") IQueryCriteriaBuilder<Entity> criteriabuilder)
    {
        super.setCriteriaBuilder(criteriaBuilder):
    }
    

    You cannot use @Qualifier on a method, because what if you wanted to autowire two beans instead of just one -- how would it know which one is which?