Springboot constant setting IntelliJ idea solution could not autowire

Time:2022-5-16

Transfer from https://blog.csdn.net/u012453…
Original blog delete this record

1. Problem description
In idea’s spring project, we often encounter court not autowire No beans of ‘XXXX’ type found. However, there is no problem with the compilation and operation of the program, and this error prompt will not have an impact. But the red error prompt is more or less uncomfortable in the eyes of some OCD programmers.

Springboot constant setting IntelliJ idea solution could not autowire

  1. reason

    There may be two reasons. The first is the problem of IntelliJ idea's own tools. The second is caused by the import package error when we import the @ service package

    The first reason is the spring auto scan configuration. When editing, the corresponding bean cannot be found, so the error that the corresponding bean cannot be found is prompted. Common mappers in mybatis are as follows:

<!– mapper scanner configurer –>
<bean id=”mapperScannerConfig” class=”org.mybatis.spring.mapper.MapperScannerConfigurer”>

<property name="basePackage" value="com.adu.spring_test.mybatis.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />

</bean>

  1. Solution
    For the first reason, the solution is to reduce the level of Autowired detection and change the level of severity from the previous error to warning or other negligible levels.
    Springboot constant setting IntelliJ idea solution could not autowire
For the second reason, the solution is of course to import the correct package. First, let's take a look at the error packages that are easiest to import, as shown below:

import com.alibaba.dubbo.config.annotation.Service;
The correct package should be the following
import org.springframework.stereotype.Service;
Remember!!!!

Recommended Today

Front end basic functions, native JS implementation of rotation map example tutorial

Rotation chart is the most basic and common function of the front end. No matter web or mobile terminal, large platform or small website, most of them will put a rotation chart effect on the home page. This tutorial explains how to achieve a simple rotation effect. Before learning this tutorial, readers need to have […]