当前位置: 首页 > 知识库问答 >
问题:

REST API:org.SpringFramework.Beans.Factory.UnsatisfiedDependencyException:

养俊驰
2023-03-14

附注:使用mongo DB进行此操作

首先是完全错误

2020-05-04 01:16:31.468  WARN 14412 
--- [           main] ConfigServletWebServerApplicationContext : 
Exception encountered during context initialization - 
cancelling refresh attempt: 
org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'productController': 
Unsatisfied dependency expressed through field 'productService'; 
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
 Error creating bean with name 'productServiceImpl':
 Unsatisfied dependency expressed through field 'productRepo'; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'productRepo': 
Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException:
 No property id found for type Product!

public class Product {

    @Id
    private int ProductId;

// and other variables plus setters and getters 
@Repository
public interface ProductRepo extends MongoRepository<Product, String> {

   // methods
}

public interface ProductService {
 // methods
}


@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductRepo productRepo;

// implementations
}

共有1个答案

胡向阳
2023-03-14

尝试将product类更改为:

@Entity
public class Product {

    @Id
    private String productId; // MongoRepository<Product, String>

    // methods
}

product类中,缺少@entity批注,并且productID应该是存储库中指定的string

或者更改为extends mongorepository

 类似资料:

相关问答

相关文章

相关阅读