[Solved] Springboot Startup Error: Consider defining a bean of type ‘XXX’ in your configuration.

I. Introduction:

The project was built using springboot automatic injection, but an error was reported when it started! ! ! , The error is as shown below:

Description: Field userEntityMapper in com.xxx.xxx.service.UserService required a bean of

 type'com.xxx.xxx.dao.UserEntityMapper' that could not be found.
 
Action: Consider defining a bean of

 type'com.xxx.xxx .dao.UserEntityMapper' in your configuration.

2. Solution:

1. Check whether the annotations you wrote are wrong, and not.

2. Find solutions on the Internet: as follows:

step one:

  Add in the configuration file of springboot, the configuration of mybatis is as follows:

mybatis: 
  typeAliasesPackage: com.xxx.xxx.dao.entity 
  mapperLocations: classpath:mapper/*.xml

 Step two:

  ① Put the interface and the corresponding implementation class in the same directory or its subdirectory as the application startup class , so that the annotations can be scanned, which is the most trouble-free way. (Not tested)
  ② Or add @MapperScan or @ComponentScan annotations to the startup class , and manually specify the annotations under which packages the application class should scan, as shown below: 

@SpringBootApplication
 @ComponentScan(basePackages = {"com.xxx.xxx.dao"})

③Or add @Mapper annotation   on the interface .

@Mapper
 public  interface UserMapper { 
}

ps: The reason why the corresponding Bean was not found is because @SpringBootApplication did not scan it.


Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *