我有这些课程:

RuleId:

@JsonIdentityInfo(
          generator = ObjectIdGenerators.PropertyGenerator.class, 
          property = "Name" 
          /*, scope=FabConfigStruct.class*/)
//@JsonIdentityReference(alwaysAsId=true)
//@JsonIgnoreProperties
public class RuleId implements Serializable {
    private static final long serialVersionUID = 1L;

    public enum Type {
        RULE,
        SET
    }

    public String Name;
    public RulerType Type;
    public RuleId ParentId;
    public RuleId ChildId;

    public RuleId(){}

FabConfigStruct:

//@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="Name") //TODO
public class FabConfigStruct implements Serializable {
    private static final long serialVersionUID = 1L;

    public String Name;
    public String Description;
    public boolean Valid;
    public String ErrorDescription;
    public ParamId[] Params;
    public TableFabConfigStruct[] Tables;
    public RuleId[] Rulers;

    public FabConfigStruct(){}

我有2个控制器:

ProjectEditorController:

@RestController
@RequestMapping(value = { "/db/ProjectEditor" })
//@SessionAttributes("projectEditor")
public class DbProjectEditorController {

    protected IProjectEditor projectEditorService = null;
    private UserSessionId sessionId = new UserSessionId("admin", "0");
    private static final Log logger = LogFactory.getLog(DbProjectEditorController.class);


    private IProjectEditor getProjectEditorService(UserSessionId sessionId) throws ProjectManagementException {
        try {
            projectEditorService = ServicePlatform.getInstance().getService(IProjectEditor.class, sessionId);
        } catch (ServicePlatformException e) {
            String msg = e.getMessage(); 
            logger.error(msg, e);
            throw new ProjectManagementException(msg);
        }
        return projectEditorService; 
    }

@RequestMapping (method = RequestMethod.POST, value= "open")
    private ResponseEntity<Void> openProject(@RequestParam(value="name", required = true) String name) 
            throws ProjectManagementException, SpecificationException, LanguagesException { 

        logger.info("Open Project: " + name );

        projectEditorService = getProjectEditorService(sessionId);
        try {
            projectEditorService.openProject(name);
        } catch (IOException e) {
            throw new ProjectManagementException(e.getMessage());
        }

        return new ResponseEntity<Void>(HttpStatus.NO_CONTENT);
    }

FabricationConfigEditorController:

@RestController
@RequestMapping(value = { "/db/ProjectEditor/FabricationConfigEditor" })
public class DbFabricationConfigEditorController {

    private static final Log logger = LogFactory.getLog(DbFabricationConfigEditorController.class);
    private IFabricationConfigEditor fabConfigEditor = null;
    private UserSessionId sessionId = new UserSessionId("admin", "0"); //Temporary

//  @Autowired
//  private DbProjectEditorController projectEditor;

    private IFabricationConfigEditor getFabConfigEditor(UserSessionId sessionId) throws SpecificationException  {
        try {
            IProjectEditor projectEditorService = ServicePlatform.getInstance().getService(IProjectEditor.class, sessionId);
            fabConfigEditor = (IFabricationConfigEditor) projectEditorService.editFabricationConfig();

//          fabConfigEditor = projectEditor.projectEditorService.editFabricationConfig();
        } catch (ServicePlatformException e) {
            String msg = e.getMessage(); 
            logger.error(msg, e);
            throw new SpecificationException(msg);
        }
        return  fabConfigEditor; 
    }

@RequestMapping (method = RequestMethod.GET, value= "getFabricationConfig")
    public FabConfigStruct getFabricationConfig(@RequestParam(value="configName", required = true) String configName)
             /*,@ModelAttribute("projetcEditor") IProjectEditor projetcEditor)*/ 
            throws SpecificationException {
        logger.info("Get Fabrication Config: " + configName);

        return getFabConfigEditor(sessionId).getFabricationConfig(configName);
    }

ProjectEditor应该打开一个项目并使用FabricationConfigEditor(嵌套对象)填充projectEditorService成员 .

从FabConfigEditorController我应该得到FabCofigEditor对象(已经填充)并从中检索FabConfigStruct(getFabricationConfig()方法)

我仍然不清楚如何在ProjectEditorController中创建的ProjectEditorService对第二个控制器可见 . 一开始我认为我应该通过共享该对象来手动处理它(正如您在注释代码中看到的,带有anotations @SessionAttributes(“projectEditor”)和@ModelAttribute(“projetcEditor”)),但它没有它的工作!

无论如何我的问题是在DbFabricationConfigEditorController中检索getFabricationConfig()时 . 我越来越:

2019年12月9日下午5:25:04 org.apache.catalina.core.StandardWrapperValve调用SEVERE:Servlet.service()for servlet [rest]在上下文中,路径[/ DataFabWebServices]引发异常[请求处理失败;嵌套异常是org.springframework.http.converter.HttpMessageNotWritableException:无法写入内容:无限递归(StackOverflowError)(通过引用链:com .... RuleId [“ParentId”] - > com .... RuleId [“ChildId “] - > java.lang.IllegalStateException:已经有id的POJO(java.lang.String)[[ObjectId:key = CR_CITY,type = com.fasterxml.jackson.databind.deser.impl.PropertyBasedObjectIdGenerator,scope = java . lang.Object]

尝试使用带有/不带范围的RuleId对象上的@JsonIdentityInfo但没有帮助 . 尝试了其他注释,但仍然没有成功 .

如何使其与此层次结构一起使用?