@Autowired: Why IntelliJ detects more than one bean of 'XXX' type?

Answered

Hi,

I don't know why IntelliJ always shows the following warning (SpringJavaAutowiringInspection) on field/constructor/method annotated by Spring's @Autowired:

  • 'Could not autowire. There are more than one bean of 'OrderApplication' type. Beans: orderApplicationImpl, orderApplicationImpl* <- yes, it's duplicated!


I have only one type of bean annotated with Spring's stereotypes (like @Service) and it works fine during runtime (Spring's component scanner detects correctly). No bean is declared in any application context's XML file.
I noticed that IntelliJ shows just one icon 'Navigate to autowired dependencies.'... when I click this icon, the correct dependency class is opened (i.e.: OrderApplicationImpl).

How does IntelliJ detect the beans?

EDIT: I'm using the latest build #9008.

Edited by: Gerson K. M. on Nov 6, 2008 5:20 PM

0
13 comments

Which IDEA version do you use?


0

I'm using version 8, build #9008. It is an old bug.

0

Yes, it looks like a regression for
http://www.jetbrains.net/jira/browse/IDEADEV-29719. I'll find out what
happened.


0

It seems you have more than one spring.jar in your classpath. Please check
it.


0
Avatar
Permanently deleted user

Hi Dmitry --

I just wanted to let you know that I have not seen this particular issue
that I reported in this JIRA issue in 8.0 final. So in the very least, the
original issue isn't a regression :). Sounds like Gerson has a similar yet
different issue.

Thanks!
Grant


"Dmitry Avdeev" <Dmitry.Avdeev@jetbrains.com> wrote in message
news:gf0q87$kbp$1@is.intellij.net...

Yes, it looks like a regression for
http://www.jetbrains.net/jira/browse/IDEADEV-29719. I'll find out what
happened.


0

I managed to reproduce the problem by adding another spring library to the
classpath :)


0
Avatar
Permanently deleted user

Interesting :) Nice find!! :)


"Dmitry Avdeev" <Dmitry.Avdeev@jetbrains.com> wrote in message
news:gf19l0$s54$1@is.intellij.net...
>I managed to reproduce the problem by adding another spring library to the
>classpath :)


0
Avatar
Permanently deleted user

We are having the same type of problem on our project, though, the circumstances are slightly different.

We are using Maven to control our project and libraries, and Intellij for development.  It seems that when Intellij automatically detects and adds a facet, it is causing this same problem.  We are using the 2.5.6 Spring libraries, though, i'm not sure that matters.

When I remove the facet from the project, this error disappears as well.  It would be nice to also get confirmation of this.

Thanks,
Rob

0

+1, this is very annoying.

I have a project that has been the same forever, worked in previous versions of intellij. in 11, i have red markings all over the place. "could not autowire" on beans in a module that has no external dependencies whatsoever, the two application-context files it marks out as duplications are in the module and in another, unrelated module with no connections to it from the core module.

Would be great with a fix.

EDIT: to me it seems to be two problems:

1. the autodetected "spring facet" adds its own dependencies in my module, even though its already been added through my maven import, resulting in multiple jars. This did not occur prior to 11.

2. I also notice that the icon you have in the left gutter, when clicked, seem show all beans in the project that match, in any module, regardless of whether the module in question has a dependency to the module with the bean with the same name. This did not, as far as i know, occur prior to 11.

0
Avatar
Permanently deleted user

I currently have this problem with IntelliJ 2017.2, but only with "DataSource". Indeed there might be more than one DataSource, but at runtime there's no problem.

Is there a way to tell IntelliJ to ignore this particular finding?

0

For the Datasource i had to explicitly add the Bean  in my Application class so I was able to add @Primary to it and remove the warning

@Primary
@Bean
@ConfigurationProperties(prefix="spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
1

I had the same problem,so I using @Resource in all code =.=

Please fix this bug!

0
Avatar
Yaroslav Bedrov

Please report new issue on YouTrack attaching sample project example: http://youtrack.jetbrains.com/issues/IDEA.

0

Please sign in to leave a comment.