In our code we have a number of Spring JPA repositories, one for each of our model classes. They are defined as (where <Name>
is the name of our modal class):
@Repository
public interface <Name>Repository implements JpaRepository<Name, Long> {
// …
}
We inject them in our beans using the @Inject
annotation from javax
:
@Inject
public void set<Name>Repository(<Name>Repository <name>Repo) {
this.<name>Repo = <name>Repo;
}
private <Name>Repository <name>Repo;
The issue is that IntelliJ underlines the <name>Repo
in the set<Name>Repository
function as an error with the text:
Could not autowire. There is more than one bean of 'Repository' type. Beans: Repo, Repo.
This is only a problem with the inspection. Compilation and running our app works fine, but in the effort of making the inspections in IJ usable this is a big problem. Anyone have suggestions on how to get IntelliJ to behave?
For reference, we are using Hibernate as our JPA provider, and the data source is set up in both the Database and Persistence tool windows.
5. Autowire Disambiguation. By default, Spring resolves @Autowired entries by type. If more than one bean of the same type is available in the container, the framework will throw a fatal exception.
I too have the same issue. I just commented out @Repository annotation on my Spring Data JPA repositories and everything is working fine and IntelliJ IDEA is also happy!
Turns out I had 2 contexts which were picking up the same classes twice in my spring applicationContext.xml
:
<mongo:repositories base-package="com.example.persistence.repositories.*"/>
...
<context:component-scan base-package="com.example.persistence.repositories.*"/>
Removing either of these lines fixed the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With