简体   繁体   中英

Spring unresolvable circular reference

I know this has been brought up before and that this is a noob question, but I cant get my head aroud how to fix this. Im getting unresolvable circular reference errors when starting up my app. Structure below. What is wrong and how can it be fixed?

@Controller("AAA")
public class AAAImpl implements AAA {

    private final BBB BBB; //this is constructor injected

}

@Service
public class BBBImpl implements BBB {

    @Autowired
    CCC CCC;

}

@Service ( "CCC" )
public class CCCImpl extends AbstractQueryService<FinalSeminar, Long> implements CCC {

    @Resource
    AAA AAA;

}

1) You need not to inject controller in any other component. It should be only used to handle HTTP requests. Do not include any business logic in it. You can write it in service or manager layer.

2)The reason why you are getting exception for circular reference is that your class AAAImpl iclludes dependency to BBBImpl, which depends on CCCImpl which ultimately depends on AAA again. So, spring is unable to create any of these beans.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM