现在,我使用aop通过mongoTemplate进行日志记录,但是我使用的是SpringBoot 2.2.0.RELEASE, 我遇到了一个我从未遇到过的问题:
org.springframework.data.mapping.MappingException: Ambiguous field mapping detected! Both protected javax.management.MBeanFeatureInfo org.apache.tomcat.util.modeler.FeatureInfo.info and transient javax.management.MBeanNotificationInfo org.apache.tomcat.util.modeler.NotificationInfo.info map to the same field name info! Disambiguate using @Field annotation!
这是我的文档
@Data
@ToString
@Document("competition_log")
public class Log {
@Id
private String id;
private String author;
private String time;
private String content;
private String className;
private String method;
private String uri;
private String url;
private Object[] params;
private Long date;
private Integer year;
private Integer month;
private Integer day;
}
这是我的控制器:
@RequestMapping("/add")
@ResponseBody
@OperateLogger("add new blog")
public Integer add(HttpServletRequest request,@RequestBody Blog blog) {
Blog save = mongoTemplate.save(blog);
if (save.getId() != null) {
return TypeContains.SUCCESS_MESSAGE;
}
return TypeContains.FAILED_MESSAGE;
}
这是我的aop arround剪辑,它仅使用mongoTemplate记录日志:
@Around("cutMethod()")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
OperateLogger logger = getDeclaredAnnotation(joinPoint);
Log log = new Log();
log.setDate(new Date().getTime());
log.setTime(DateUtils.formatDateByDay(LocalDateTime.now()));
log.setYear(DateUtils.getYear());
log.setMonth(DateUtils.getMonth());
log.setDay(DateUtils.getDay());
log.setClassName(joinPoint.getTarget().getClass().getName());
log.setMethod(joinPoint.getSignature().getName());
log.setParams(joinPoint.getArgs());
log.setUrl(request.getRequestURL().toString());
log.setUri(request.getRequestURI());
mongoTemplate.save(log);
LOGGER.info(JsonUtils.objectToJsonString(log));
return proceed;
}
我真的希望有一个朋友可以帮忙回答,非常感谢。