這是我的存盤庫:
@Repository
public interface GroupRepository extends JpaRepository<Group, Integer> {}
這就是我嘗試在我的服務類中使用它的方式:
@Service
public class GroupService {
private final GroupRepository groupRepository;
@Autowired
public GroupService(GroupRepository groupRepository) {
this.groupRepository = groupRepository;
}
得到這個錯誤:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'groupController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'groupService' defined in file [/Users/nathanxuan/Files/Project/ratingApp/target/classes/com/xjy/service/GroupService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'groupRepository' defined in com.xjy.mapper.GroupRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.xjy.pojo.Group
有誰知道為什么會這樣?當我注釋掉存盤庫類時,一切正常(我有另一個映射器類,那個也可以)。
--------編輯------------ 這是我的應用程式的結構:

uj5u.com熱心網友回復:
我認為問題出在模型類Group上,因為您使用的是 JPA ,所以它需要Entity注釋。試試這個:
@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Group {
....
}
注意:@Data @AllArgsConstructor @NoArgsConstructor來自 Lombok,所以如果你不使用它,只需創建常規的 Getter 和 Setter
uj5u.com熱心網友回復:
嘗試從您的存盤庫中洗掉 @Repository。通過從 JpaRepository 擴展應該就足夠了。
除非您真的需要在服務中定義您的存盤庫的 setter 注入,否則也應該更好更簡潔。
@Autowired
private GroupRepository groupRepository;
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/495505.html
上一篇:拖動后元素不可點擊
