Autowiring for Bean Class inspection in Spring Boot project

Answered

I use IDEA 2016.1.1 and do have a Spring Boot project that uses spring-boot-starter-jdbc and therefore "automagically" instantiates a JdbcTemplate bean during startup when a JDBC driver is found in the class path.

As soon as I declare an autowired field of type JdbcTemplate in a self written Spring bean, the "Autowiring for Bean Class" inspection triggers and shows an error.

Is there any way to tell IDEA that at runtime there will be a JdbcTemplate Bean except from annotate each autowiring with @SuppressWarnings("SpringJavaAutowiringInspection")?

Regards

Stefan

3 comments
Comment actions Permalink

Hello Stefan,

sorry for late reply.

This is caused by not yet complete support of using auto-configured setup in SB applications, please watch https://youtrack.jetbrains.com/issue/IDEA-139669. You might want to try the workaround for 2016.1.2 given in issue description.

 

 

0
Comment actions Permalink

Thank you very much for the response!

 

0
Comment actions Permalink

I'd still like to know the answer to this question. In my case, I am creating a test implementation of a JpaRepository in order to test an algorithm that uses the repository. Rather than mocking the interface I want to implement the interface in a test class and provide my test class with a test dataset in the constructor. IntelliJ is reporting an inspection error: "Could not autowire. No beans of type x found". I would like to annotate this constructor to disable this inspection. Is that possible?

 

Additionally, it would be nice when using the keyboard shortcut CTRL+F1 to see the inspection information, if part of the information displayed in the tooltip would be to explain what annotation could be used to disable the inspection.

0

Please sign in to leave a comment.