Spring Flashcards

1
Q

What is Spring?

A
  • Framework created to address the complexity of enterprise level application
  • Includes an Inversion of Control container
  • Involves layered architecture that users can select which aspects of Spring to use
  • Components/Modules - Test, Core Container, Web, Data Access and Integration, AOP
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Bean Scopes.

A

Prototype - Properties changed in one instance won’t affect other instances of that bean
Singleton - Properties changed on a global level
Request - (web service) scope of a single HTTP request
Session - (web service) within a session
GlobalSession - (web service) lifecycle of a global HTTP session

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Spring Modules

A
Spring Web
Spring Core
Spring Context
Spring Data
Spring Security
Spring AOP
Spring MVC
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Spring bean lifecycle

A
  • Instantiate
  • Populate properties
  • setBeanName
  • setBeanFactory
  • setApplicationContext
  • Preinitialization
  • Initializing Bean
  • Custom init
  • Post Initialization
  • Destroy
  • Custom Destroy
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the Spring Container?

A

IOC Container
Application Context
Bean Factory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

ApplicationContext vs BeanFactory.

A

Bean Factory - no longer in use; lazy initialization for beans (created upon request)
ApplicationContext - supports Spring’s newer modules; eager initialization for beans (can also tell it to do lazy initialization); includes new features such as messaging

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Inversion of Control.

A
  • The idea that parts of the architecture you set up yourself, you pass on to some other entity to other handle for you.
  • Don’t worry about the implementation, focus on the business logic.
  • Spring uses dependency injection, which implements inversion of control.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Types of Dependency Injection

A

Constructor and setter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Different types of Bean wiring.

A

manual or autowiring

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Types of autowiring?

A

byName and byType

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do I create a bean in the container?

A
  • If you are using XML-based configuration metadata, you can specify the type (or class) of object that is to be instantiated using the ‘class’ attribute of the element.
  • You can declare beans using the @Bean annotation in a configuration class.
  • Or you can mark the class with one of the annotations from the org.springframework.stereotype package and leave the rest to component scanning.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

@Autowired.

A
Marks a constructor, field, setter method or config method as to be autowired by Spring's dependency injection facilities.
Only one constructor (at max) of any given bean class may carry this annotation, indicating the constructor to autowire when used as a Spring bean. Such a constructor does not have to be public.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

@Autowired vs @Inject vs @Resource.

A
  • @Autowired - Spring property annotation that inject a resource by-type, i.e. by the class or by the interface of the annotated field or constructor.
  • @Inject - Identifies injectable constructors, methods, and fields. This annotation is an almost complete drop-in replacement for Spring’s @Autowired annotation. So, instead of using the Spring-specific @Autowired annotation, you might choose to use @Inject. One of the differences between @Autowired and @Inject is that @Inject does not have the required field so in case we fail to find a suitable object to injected it will fail while @Autowired can used required=false and allow null-able field (only if required!).
  • @Resource - Is quite similar to @Autowired and @Inject, but the main difference is the execution paths taken to find out the required bean to inject. @Resource will narrow down the search first by name then by type and finally by Qualifiers (ignored if match is found by name). @Autowired and @Inject will narrow down the search first by type then by qualifier and finally by the name.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is @RequestMapping?

A

Marks a method as an endpoint to which a client can connect, where you can specify the request type it will handle and the path of the endpoint.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

@controller vs @restcontroller

A

Rest Controller annotation is the same as Controller annotation, but assuming that @ResponseBody is active by default, so all the json are parsed to java objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is AOP?

A
  • Aspect Oriented Programming
  • Address cross-cutting concerns
    • Transactions
    • Authorization
    • Logging
  • Aspect, Advice, JoinPoint, Pointcut
17
Q

Cross Cutting Concerns.

A

-concerns that cut across multiple layers of an application

18
Q

Aspect

A
  • The encapsulation of a cross cutting concern

- The combination of Pointcut and Advice

19
Q

Types of Advice

A
  • Before
  • After (Finally)
  • After Returning
  • After Throwing
  • Around
20
Q

JoinPoint vs Pointcut.

A
  • Pointcut - point of execution in which a cross cutting concern needs to be applied
  • Joinpoint - where you’re looking for your pointcut
21
Q

Transaction propagation strategies

A
  • Required - supports a transaction and creates a new one if it none exists
  • Mandatory - supports a current transaction and will throw an exception if none exists
  • Never - executes non-transactionally and throws an exception if a transaction exists
  • Supported - Supports a current transaction if one exists but will execute non-transactionally if none exists.
  • Not Supported - executes non-transactionally and suspends the current transaction if none exists
  • Requires New - Will suspend the current transaction and create a new transaction if it exists
  • Nested - it’s nested, part of the transaction