I've written java for eight years, from mono-to micro-services, spring is almost a default option. However, no more than 10 per cent of those who can really explain the principle of spring and the mechanisms for its realization are interviewed. Most people turned over the ioc container and the aop agent, asking how beanfactory was exemplified and what was being done in the refresh method, were vague. It's not a concept. It's just how it got up。
What exactly is the spin principle about
One thing at the heart of the spin theory is to take the object from you for creation, assembly, and management. You write a class of @service notes, frame scanned to it, registered as bean defense, stored in a map. When really needed, the container is exemplified in the order of dependence and injected where required. You don't get the whole process, you don't get the set, but what that map looks like, what sort of logic, you know. Otherwise, the bean cycle depends on you, and you can't catch it。
And to the bottomLevel 3 cache to address cycle dependenceNot encyclopedia. Singletonobjects, early singletonobjects, pre-exposed semi-finished, and singleton actories, packaged with objectfactory. When one bean is still initializing and the other is already relying on it, the container is removed from the earlysingletonobjects for use. Looks like it's actually a hashmap plus priority strategy, and that's how it works。
How do you understand the spring mechanism
I suggest that we get in from applicationcontext#refresh. It did more than a dozen steps: refreshing the context, running bean factory postprocessor, exemplifying the case, knitting aop agents, registering listening devices, and sending refreshevent. If you look at the source code, you'll find a lot of hooks -- the way the father leaves the blanks, the child rewrite. This is itTemplate method modeIn the frame, the word "design mode" doesn't pass。
The aop, jdk dynamic agent and cglib switch logic deserves attention. The interface takes jdk agents, and the specific class takes cglib, but spring boot 2. X then defaults to cglib. The essence of the agent is that your service method, actually, is an agent who's trying to do it for you, and there's an incisive logic. Understand this layer@transactional's internal calls are not workingIt's no longer about the hard-on。
Instead of reading the whole source code from the beginning to the end, choosing beanfactory and aop proxy lines, and going over the invoke method of refresh and proxy, it is much better than brushing the eight of the 10 lines. It's an iterative frame, but it hasn't changed much. It's full. You can catch anything new。










