2016-09-28 23 views
23

Tôi có một giao diện kho lưu trữ như sau:"đại diện thập lục phân không hợp lệ" cho mùa xuân Mongo giao diện kho lưu trữ dữ liệu

public interface ExcursionAttendeeRepository extends MongoRepository<ExcursionAttendee, String> { 

    ExcursionAttendee findByWorkflowItemId(String workflowItemId); 

    @Query("{ 'excursionEvent._id' : { '$oid' : ?0 } }") 
    List<ExcursionAttendee> findByExcursionId(String excursionId); 

    @Query("{ 'student._id' : {'$oid' : ?0} , 'excursionEvent._id' : { '$oid' : ?1 } }") 
    ExcursionAttendee findByStudentIdAndEventId(String studentId, String excursionId); 

    @Query("{ 'student._id' : { '$oid' : ?0 } }") 
    List<ExcursionAttendee> findByStudentId(String studentId); 
} 

Trong khi tạo Bean mùa xuân ném sau ngoại lệ.

Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#0.1': 
    Cannot create inner bean '(inner bean)#5172829b' of type [org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter] while setting bean property 'messageListener'; 
    nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#5172829b': 
    Cannot resolve reference to bean 'productDetailsEventConsumer' while setting bean property 'delegate'; 
    nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productDetailsEventConsumer': Injection of autowired dependencies failed; 
    nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.cinglevue.veip.service.excursion.ExcursionAttendeeService com.cinglevue.veip.service.erp.impl.ProductDetailsEventConsumer.excursionAttendeeService; 
    nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'excursionAttendeeServiceImpl': Injection of autowired dependencies failed; 
    nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.cinglevue.veip.repository.excursion.ExcursionAttendeeRepository com.cinglevue.veip.service.excursion.impl.ExcursionAttendeeServiceImpl.excursionAttendeeRepository; 
    nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'excursionAttendeeRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: invalid hexadecimal representation of an ObjectId: [_param_0] 

Lý tưởng ngoại lệ này sẽ bị ném khi cố gắng khởi tạo ObjectId bằng chuỗi không hợp lệ. [code]. Tôi tự hỏi làm thế nào lớp học được khởi tạo để cho một ngoại lệ để có được ném trong khi tạo ra đậu. Bất kỳ lời khuyên về điều này?

Trả lời

0

Tôi đã chạy vào cùng một câu hỏi và theo dõi sẽ hoạt động.

@Query("{ 'student' : { '$id': ?0 } }") 
List<ExcursionAttendee> findByStudentId(String studentId); 

Nếu nó là một DBRef nó phải như thế này, (Đây là những gì im sử dụng sau khi cùng một vấn đề, tôi có một DBRef trong trường hợp của tôi)

@Query("{ 'student': {'$ref': 'user', '$id': ?0} }") 
List<ExcursionAttendee> findByStudentId(String studentId); 

Đối DBRef này nên hoạt động như tốt,

List<ExcursionAttendee> findByStudentId(String studentId); 

Tôi tìm thấy câu trả lời từ here.

Các vấn đề liên quan