控制台报错信息:
Description: Field userRepository in
com.example.demo.controller.UserController required a bean of type
'com.example.demo.repository.UserRepository' that could not be found. Action:
Consider defining a bean of type 'com.example.demo.repository.UserRepository'
in your configuration.
UserRepository:
@Repository public interface UserRepository extends JpaRepository<User, Long> {
}
UserController:
@RestController public class UserController { @Autowired private
UserRepository userRepository; @GetMapping("/simple/{id}") public User findById(
@PathVariable Long id) { return this.userRepository.findOne(id); } }
使spring 扫描到文件
解决方法:启动类进行扫描
@SpringBootApplication @ComponentScan("com")//扫描com下所有文件 public class
Application { public static void main(String[] args) { SpringApplication.run(
Application.class,args); } }

翻译自https://stackoverflow.com/questions/40384056/consider-defining-a-bean-of-type-package-in-your-configuration-spring-boot