Spring Flashcards
Primary functions of the spring container.
Create & manage objects (IoC) and inject object’s dependencies (DI).
3 ways of configuring a spring container.
- XML config file (legacy)
- Java annotations (modern)
- Java source code (modern)
How to create a spring container.
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (“configFileName.xml”);
How to retrieve beans from container.
Coach theCoach = context.getBean (“myCoach”, Coach.class);
What is dependency injection?
The spring object factory will basically give you the objects you requested fully assembled. You outsource the construction & injection of your object to an external entity.
3 types of dependency injection.
- constructor injection
- setter injection
- autowiring
what is setter injection?
inject dependencies by calling setter method on your class
what is bean scope?
the life cycle of a bean.
what does bean scope tell you?
How long the bean lives, how many instances are created, how the bean is shared.
what is the default scope for a bean?
singleton
what is a singleton with respect to beans?
The spring container creates only one instance of the bean. all requests for the bean will return a shared reference to the SAME bean.
What type of custom code can be added?
Bean init & Bean destruction code.
what are java annotations?
special labels/markers added to java classes that provide meta-data about the class.