今天一直在报这个错"Type definition error: [simple type, class org.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessor C u s t o m A n n o t a t i o n T r a n s a c t i o n A t t r i b u t e S o u r c e ] ; n e s t e d e x c e p t i o n i s c o m . f a s t e r x m l . j a c k s o n . d a t a b i n d . e x c . I n v a l i d D e f i n i t i o n E x c e p t i o n : N o s e r i a l i z e r f o u n d f o r c l a s s o r g . s p r i n g f r a m e w o r k . d a t a . r e p o s i t o r y . c o r e . s u p p o r t . T r a n s a c t i o n a l R e p o s i t o r y P r o x y P o s t P r o c e s s o r CustomAnnotationTransactionAttributeSource]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessor CustomAnnotationTransactionAttributeSource];nestedexceptioniscom.fasterxml.jackson.databind.exc.InvalidDefinitionException:Noserializerfoundforclassorg.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessorCustomAnnotationTransactionAttributeSource and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.sinosoft.web.rest.util.TmsInfoModel[“data”]->com.sun.proxy.$Proxy384[“advisors”]->org.springframework.aop.support.DefaultPointcutAdvisor[4]->org.springframework.aop.support.DefaultPointcutAdvisor[“advice”]->org.springframework.transaction.interceptor.TransactionInterceptor[“transactionAttributeSource”])",
查了之后说是实体类没有set方法,就是忘记set和get了,但是检查我自己是有的。还有的是说是json对象保存数据时候对时间类型转换有问题,原因是实体类继承AbstractAuditingEntity审计功能,其中的createdDate和lastModifiedDate字段是Instant类型的,json对其进行序列化和反序列化会报错。解决办法在审计类的字段加上@JsonIgnore注解就解决了。
最后这些问题都大概的查之后,只是因为我在接受的对象的时候应该用tmsInfoModel.setData(保存数据的表名类)不应该是数据库的repository类 。是tmsInfoModel.setData(ltYearStudyFlag);
而不是tmsInfoModel.setData(ltYearStudyFlagRepository);
附一段代码 :
/**
* 保存记录
* @return
*/
public TmsInfoModel saveYearFlagInfo(JSONObject body){
TmsInfoModel tmsInfoModel = new TmsInfoModel();
Integer bookCount = body.getInteger(“bookCount”);
Integer cityCount = body.getInteger(“cityCount”);
Integer studyTime = body.getInteger(“studyTime”);
Integer classCount = body.getInteger(“classCount”);
String goalText = body.getString(“goalText”);
List infos = ltYearStudyFlagRepository.findAllByTrainCode(PubFun.getCurrentUser());
if (infos.size() > 0) {
tmsInfoModel.setData(infos.get(0));
tmsInfoModel.setMsg(“已经存在该数据”);
}else{
LtYearStudyFlag ltYearStudyFlag = new LtYearStudyFlag();
ltYearStudyFlag.setTrainCode(PubFun.getCurrentUser());
ltYearStudyFlag.setBookCount(bookCount);
ltYearStudyFlag.setCityCount(cityCount);
ltYearStudyFlag.setStudyTime(studyTime);
ltYearStudyFlag.setClassCount(classCount);
ltYearStudyFlag.setGoalText(goalText);
ltYearStudyFlag.setCreatedDate(PubFun.getCurrentDate());
ltYearStudyFlag.setLastModifiedDate(PubFun.getCurrentDate());
ltYearStudyFlagRepository.save(ltYearStudyFlag);
tmsInfoModel.setMsg(“该用户数据保存成功”);
tmsInfoModel.setData(ltYearStudyFlag);//很关键的一行
}
return tmsInfoModel;
}