It is found that when springboot starts, the following log is printed:
2021-10-13 17:20:47.549 [main] INFO ... Bean 'xxx' of type [xxx] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
This is because a service implements the beanpostprocessor interface and depends on other services. Examples are as follows:
@Service public class RandomIntProcessor implements BeanPostProcessor { @Autowired private RandomIntGenerator randomIntGenerator; @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { Field[] fields = bean.getClass().getDeclaredFields(); for (Field field : fields) { RandomInt injectRandomInt = field.getAnnotation(RandomInt.class); if (injectRandomInt != null) { int min = injectRandomInt.min(); int max = injectRandomInt.max(); int randomValue = randomIntGenerator.generate(min, max); field.setAccessible(true); ReflectionUtils.setField(field, bean, randomValue); } } return bean; } }
The randomintprocessor class depends on the randomintgenerator class, which will cause the randomintprocessor.postprocessbeforeinitialization method to fail to receive the randomintgenerator initialization event.
It can be modified as follows:
@Service public class RandomIntProcessor implements BeanPostProcessor { private final RandomIntGenerator randomIntGenerator; @Lazy public RandomIntProcessor(RandomIntGenerator randomIntGenerator) { this.randomIntGenerator = randomIntGenerator; } @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { //... } }
Use lazy annotation to delay initialization and break the circular dependency.
Start the test again, and the previous prompt information will not be output.
Similar Posts:
- [Solved] NoSuchMethodError: org.springframework.boot.web.servlet.error.ErrorController.getErrorPath
- [Solved] java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null”
- Access permission problem caused by object. Clone() method
- Java Thread wait, notify and notifyAll Example
- Consider defining a bean of type ‘xxx’ in your configuration. Autowired(required=true)
- [Solved] Using JDK dynamic agent to customize SPI Error: UndeclaredThrowableException
- Quartz: add transaction rollback error [How to Solve]
- Android Exception: UncaughtException detected: java.lang.RuntimeException: Parcelable encountered IOExcepti
- [Solved] failure to inject AuthenticationManager directly Error
- Cannot resolve reference to bean ‘entityManagerFactory’ while setting constructor argument