@Repository类中的java自引用导致循环引用
我发现@Repository
中的自引用不起作用,例如:
@Repository
public class HelloService {
static final Logger Log = LoggerFactory.getLogger(HelloService.class);
@Autowired
HelloService self; // <----- self reference
...
}
有循环参考误差
o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'helloService': Bean with name 'helloService' has been injected into other beans [helloService] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
然而,当把Repository
更改为@Component
或@Service
时,这个技巧可能会起作用。作为一种解决方法,我必须在self
中添加一个@Lazy
共 (0) 个答案