springboot project started Consider error of defining a bean of type 'XXX' in your configuration. springboot project started Consider error of defining a bean of type 'XXX' in your configuration.

springboot error of the project started Consider defining a bean of type 'XXX' in your configuration.

I. Introduction:

Use springboot automatic injection of a project to build a good way, when the results start being given! ! ! Error follows:

Copy the code
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.
Copy the code

Second, the solution:

1. Check whether to write their own notes wrong, and did not.

2. In the Internet to find solutions: as follows:

step one:

  In adding springboot profile, shown mybatis is as follows:

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

 Step two:

  ① the same directory interfaces and corresponding implementation and application start classes in the class or his sub-directory, so notes can be scanned, this is the most easy way. (Not tested)
  ② or plus or @ComponentScan @MapperScan start annotation on the class, the class annotated manually specify the application in which the package to be scanned, as follows: 

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

  ③ @Mapper or add annotations on the interface.

@Mapper
public interface UserMapper {
}

ps: The reason why the corresponding Bean did not find because, @ SpringBootApplication not scanned.

Guess you like

Origin www.cnblogs.com/wasbg/p/11416507.html
Recommended