Consider defining a bean of type 'app.mapper.UserMapper' in your configuration.
3026 ワード
バグの内容:
Description:Parameter 0 of constructor in app.controller.IndexControllerMaYi required a bean of type 'app.mapper.UserMapper' that could not be found.Action:Consider defining a bean of type 'app.mapper.UserMapper' in your configuration.
解決策
mainメソッドに追加
まとめ:
@SpringBootApplicatoin=@Configuration+@EnableAutoConfiguration+@ComponentScan
@SpringBootApplicatoinは@ComponentScanでスキャンされ、@Component、@Controller、@Service、@Repositoryなどを含むComponentでスキャンされます
Mybatisの自動スキャン構成では、注記構成を使用する場合、@MapperScanでスキャンする必要があるMapperの位置を構成すれば、ほとんどの場合、ニーズを満たします.
Description:Parameter 0 of constructor in app.controller.IndexControllerMaYi required a bean of type 'app.mapper.UserMapper' that could not be found.Action:Consider defining a bean of type 'app.mapper.UserMapper' in your configuration.
解決策
mainメソッドに追加
@MapperScan({"app.mapper","app.test01.dao","app.test02.dao"})
// *******
package app;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan(basePackages = "app")
@MapperScan({"app.mapper","app.test01.dao","app.test02.dao"})
@SpringBootApplication //
public class BooklistApplication {// ,
public static void main(String[] args) {
SpringApplication.run(BooklistApplication.class, args);//
System.out.println("main...");
}
}
まとめ:
@SpringBootApplicatoin=@Configuration+@EnableAutoConfiguration+@ComponentScan
@SpringBootApplicatoinは@ComponentScanでスキャンされ、@Component、@Controller、@Service、@Repositoryなどを含むComponentでスキャンされます
Mybatisの自動スキャン構成では、注記構成を使用する場合、@MapperScanでスキャンする必要があるMapperの位置を構成すれば、ほとんどの場合、ニーズを満たします.