Problem description

“Error creating the bean with name ‘userDAO ‘: Unsatisfied dependency expressed through field’ JDBCTemplate ‘”

Error creating bean with name “XXX” : Unsatisfied dependency expressed throuh field “XXXX”

⚠️ error under UserDAO and JDBCTemplate is red line error!

Error analysis

The bean that created the UserDAO does not satisfy the dependency field “JBDCTemplate”.

Annotations cannot be injected into the ICO container when the package is scanned without an annotation scanner

The main reason is that there are two Spring configuration files, one of which you need to use at this point, and the other one does not write the scanner and other bean configurations

<! - create a dataSource data source - > < bean id = "dataSource" class = "com.mchange.v2.c3p0.Com boPooledDataSource" / > <! - create a spring of JDBC support tools jdbcTemplate - > < bean id = "jdbcTemplate" class = "org. Springframework. JDBC. Core. JdbcTemplate" > <property name="dataSource" ref="dataSource" /> </bean>

⚠️ UserDAO is implemented by JDBCTemplate. If you did not write the above code, there would be no DataSource and JDBCTemplate, so there would be no UserDAO

💁 writer: This is using Spring to complete JDBC configuration, injection way rather than using Java native connection to JDBC

Problem solving

Adding Dependencies

<! - create a dataSource data source - > < bean id = "dataSource" class = "com.mchange.v2.c3p0.Com boPooledDataSource" / > <! - create a spring of JDBC support tools jdbcTemplate - > < bean id = "jdbcTemplate" class = "org. Springframework. JDBC. Core. JdbcTemplate" > <property name="dataSource" ref="dataSource" /> </bean>

To sum up is to rely on the question of whether or not


Error creating the bean with name ‘UserController ‘: Unsatisfied dependency expressed through field’ UserService ‘

Related Articles:

  • Error creating bean with name Unsatisfied dependency expressed through field
  • IntelliJ IDEA Could not autowire. No beans of Usermapper type found
  • UnsatisfiedDependencyException: Error creating bean with name ‘userController’: Unsatisfied dependency