Spring Flashcards
What is the Spring Framework?
The Spring Framework is an application framework and inversion of control container for the Java platform. One of the core functions of the Spring Framework is dependency injection, which is accomplished through the use of a inversion of control container, known as the ApplicationContext. The framework integrates with other specifications, namely:
Dependency Injection (JSR 330) Servlet API (JSR 340) Bean Validation (JSR 303) JPA (JSR 338)
What are the goals of Spring?
Lightweight development with Java POJOs
Dependency injection to promote loose coupling
Declarative programming with Aspect-Oriented Programming (AOP)
Minimize boilerplate Java code
What is Dependency Injection?
The process of the Spring Framework actually injecting an instance of a dependency into a component (through auto-wiring or manual bean wiring)
What is Autowiring?
The process in which the Spring Framework identifies dependencies within a component, finds the corresponding component implementations and instantiates the dependency (or grabs an existing instance)
How manual wiring works?
Manual bean wiring is the process in which a bean’s dependencies are associated with the parent bean through explicit configuration. If leveraging constructor injection, this is done in XML configuration by including a constructor-arg tag with a bean id specified in the ref attribute.
How automatic wiring works?
If we let Spring scan our packages for us, using component scanning, we do not need to provide explicit bean definitions in an XML file, nor within some configuration class. Instead, Spring will scan the specified package for classes annotated with @Component (or another stereotype annotation) and create the bean definitions for them from the class declaration.
What are the bean scopes?
Singleton, Prototype, Request, Session, Application, WebSocket
What is ApplicationContext?
It is an interface that describe the Inversion of Control Container. The most important implementations of this interface are:
ClassPathXmlApplicationContext
AnnotationConfigApplicationContext
WebApplicationContext
What is a BeanFactory?
A bean factory is just that, a implementation of the factory design pattern which is used to create Spring beans. The BeanFactory interface is implemented by objects that hold a number of bean definitions, each uniquely identified by a String name. Depending on the bean definition, the factory will return either an independent instance of a the object, or a single shared instance (a singleton scoped to the factory instance). The point of this approach is that the BeanFactory is a central registry of application components, and centralizes configuration of application components.
What is the Bean lifecycle
Instantiate Populate Properties setBeanName setBeanFactory setApplicationContext PreInitialization afterPropertiesSet() custom init-method PostInitialization Disposable Bean's destroy Custom destroy method
What is Spring MVC?
Spring Web MVC is a model-view-controller web framework built on the Servlet API. This framework is useful for creating flexible web applications to handle HTTP requests from clients. Packaging for Spring MVC projects will be war packaging.
What is the Dispatcher Servlet?
The Spring MVC web framework is designed around the front controller pattern where a central servlet, the DispatcherServlet, provides a shared algorithm for request processing, while actual work is performed by configurable delegate components. This model is flexible and supports diverse workflows.
The DispatcherServlet, as any Servlet, needs to be declared and mapped according to the Servlet specification by using Java configuration or in web.xml. In turn, the DispatcherServlet uses Spring configuration to discover the delegate components it needs for request mapping, view resolution, exception handling, and more.
What is Spring AOP?
The Spring Framework has its own Aspect-Oriented Programming framework, which is based on AspectJ. Aspect-oriented Programming (AOP) complements Object-oriented Programming (OOP) by providing another way of thinking about program structure. The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity is the aspect.
What is an Aspect?
A modularization of a concern that cuts across multiple classes. Transaction management is a good example of a crosscutting concern in enterprise Java applications. In Spring AOP, aspects are implemented by using regular classes (the schema-based approach) or regular classes annotated with the @Aspect annotation (the AspectJ style).
What is a Join Point?
A point during the execution of a program