Spring Flashcards

(4 cards)

1
Q

Dependency Injection

A
  • A design pattern that achieves loose coupling
  • The process of passing one instantiated object to another that needs it (has-a relationship) via constructor or a setter

Steps

  1. Have at least 2 classes [and their interfaces] (one is a dependency of another)
  2. Write one class to accept an instance in the constructor
  3. Write the bean of the dependency
  4. Write the bean of the other class
  5. Pass the dependency as a constructor argument
    1.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Bean

A
  • basic java object that is created and managed by the Spring Container
  • must have getters and setters
  • must have parametrized constructor (?)

In XML

  • id
    • unique identifier for that bean
    • Used when retrieving bean from Spring Container
  • class
    • the fully-qualified name of the class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Inversion of Control

A
  • paradigm in which ocnstructor and management of objects is outsourced to an object factory

Steps

  1. Create beans in XML file
    • Must include both id and class
  2. Create Spring Container (Application Context)
    • Initialize context by referencing xml file
    • ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(“file.xml”);
  3. Retrieve bean from Spring Container
    1. Get bean using id and interface
    2. Obj myObj = context.getBean(“theBean”, Obj.class)
  4. Use new object
  5. Close context
    • context.close();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Spring Container

A
  • Also known as an Application Context
  • Essecially an special object that can be used for both IoC and DI
  • Object that is used to perform important Spring functionality
How well did you know this?
1
Not at all
2
3
4
5
Perfectly