Java Error creating bean with name:Bean with name has been injected into other beans in its raw

created at 09-30-2021 views: 99

problem

Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'userServiceImpl': Bean with name 'userServiceImpl' has been injected into other beans [userLogServiceImpl] 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.

problem analysis

1. When two services assemble each other's instances, there is a circular reference, which leads to an error.

package com.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private UserLogService userLogService;
}
package com.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserLogService {
    @Autowired
    private UserService userService;
}

solution

Remove the @Autowired annotation and service variable of one of the Services, and remove the mutual nested references.

created at:09-30-2021
edited at: 09-30-2021: