![](/img/trans.png)
[英]Apache Ignite with Spring Boot CrudRepo cannot be initialized
[英]Spring boot CrudRepo Define a bean
我在春季啟動時遇到有關存儲庫的問題。 我有一個服務:
@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);
}
當我運行應用程序時,我收到此消息:
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.
請幫幫我,我很絕望......這是我的主要課程:
@SpringBootApplication
@Configuration
@EnableWebMvc
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}
另一個問題是, @EnableJpaRepositories
無法識別!!
很可能你的Main
類是在一個包中定義的,而你的其他包沒有被掃描。
嘗試使用以下內容對Main
類進行注釋:
@ComponentScan("com.projectWS")
根據您的錯誤消息判斷並假設包級別的頂部從com.projectWS
開始
我不是Spring專家,但我懷疑這可能是因為這些類的名稱的情況。 只是為了安心測試,請:
@Service("userService")
public class UserServiceImpl implements UserService {
@Qualifier("userRepository")
@Autowired
private UserRepository userRepository;
@Qualifier("roleRepository")
@Autowired
private RoleRepository roleRepository;
}
您似乎沒有為JPA添加Spring數據,請將以下內容添加到您的pom.xml中
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.