运行 mongo 模板组操作时出现 NullPointerException。
代码如下所示:
GroupByResults<Recommendation> recommendations
= mongoTemplate.group("recommendation",
GroupBy.key("doctor"),
Recommendation.class
);
POJO是:
package med.rec.model;
@Document
public class Recommendation extends BaseModel {
public Recommendation(){
}
@Indexed
@DBRef
private Doctor doctor;
@Indexed
private String specialty;
private String x;
private int y;
private int z;
private int w;
private String f;
/*All getter and setters */
}
堆栈跟踪似乎根本没有信息,但这里是:
ava.lang.NullPointerException
org.springframework.data.mongodb.core.MongoTemplate.group(MongoTemplate.java:1225)
org.springframework.data.mongodb.core.MongoTemplate.group(MongoTemplate.java:1199)
med.rec.controller.api.v1.RecommendationController.all(RecommendationController.java:43)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:690)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
请指教。
谢谢你,罗伊