Spring boot CrudRepo 定义一个bean [英] Spring boot CrudRepo Define a bean
本文介绍了Spring boot CrudRepo 定义一个bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Spring Boot 中遇到了有关存储库的问题.我有一项服务:
I have a problem in spring boot concerning repositories. I have a service :
@Service("userService")
public class UserServiceImpl implements UserService {
@Autowired
private UserRepository userRepository;
@Autowired
private RoleRepository roleRepository;
}
和这里的回购:
@Repository("userRepository")
public interface UserRepository extends CrudRepository<User, Long> {
User findByEmail(String email);
}
当我运行应用程序时,我收到此消息:
When I run the app I get this message :
Description:
Field userRepository in com.projectWS.service.UserServiceImpl required a
bean of type 'com.projectWS.repo.UserRepository' that could not be found.
Action:
Consider defining a bean of type 'com.projectWS.repo.UserRepository' in your
configuration.
请帮帮我,我太绝望了...这是我的主要课程:
Please help me I'm so desperate... this is my main class:
@SpringBootApplication
@Configuration
@EnableWebMvc
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}
另一个问题是,@EnableJpaRepositories
没有被识别!!
Another problem is , @EnableJpaRepositories
doesn't get recognized !!
推荐答案
很可能你的 Main
类是在一个包中定义的,而你的其他包没有被扫描.
most likely your Main
class is defined within a package and your other packages are not getting scanned.
尝试注释您的 Main
类:
@ComponentScan("com.projectWS")
根据您的错误消息判断并假设您的包级别的顶部从 com.projectWS
judging by your error message and assuming that the top of your package level starts at com.projectWS
这篇关于Spring boot CrudRepo 定义一个bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文