I need your help and help. The point, I think, in some trifles, which I do not see at all. I am picking Spring on the sly according to the lecture by Evgeny Borisov ( https://www.youtube.com/watch?v=BmBr5diz8WA ) and I encountered such a problem (repository with the project on the githaba https://github.com/redbeard3/SpringProject/tree/master / src / main ) - code execution crashes with the error:

апр 20, 2019 6:21:16 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [common_beans.xml] Exception in thread "main" java.lang.NullPointerException at redbeard.Runner.main(Runner.java:8) Process finished with exit code 1 

And:

 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("common_beans.xml"); 

it works fine, the bin from common_beans.xml with id = 'terminatorQuoter' is configured, that is, the required value is set in the repeat bin field of the terminatorQuoter: enter image description here

The error is in

 context.getBean(TerminatorQuoter.class).sayQuote(); 

because:

  context.getBean(TerminatorQuoter.class) выдает null 

enter image description here

However, if I remove everything related to the InjectRandomInt annotation, that is, I don’t use it at all, and in the sayQuote () method I simply output the message:

 System.out.println(message); 

then everything works. Tell me where that missed. Although the lecture was revised several times, I carefully verified everything I did.

    1 answer 1

    InjectRandomIntAnnotationBeanPostProcessor in the method PostProcessAfterInitialization returns null - replace with o. In general, as far as I remember, Eugene just wanted to show why you need to pull the bins on the interface, and not on the class. Because of the BeanPostProcessor class may return a completely different, but implementing the same interface.

    • Thank! Indeed, the problem was that postProcessAfterInitialization returns null - Red Beard