Spring Class_04.2020_CORE_IoC Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is Spring Framework?

A

It’s enormous amount of libraries which help build web apps

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

How many libraries does Spring consists?

A

near 250

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

Why spring is lightweight framework?

A

Because it minimizes amount of written code by developer

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

Basic idea behind Spring is

A

Simplify traditional approach to designing J2EE apps

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

Who is the creator of Spring?

A

Rod Johnson

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

What is Rob Johnson specialization?

A

enterprise java architect

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

Difference between library and framework

A

you code call LIBRARY
FRAMEWORK call your code
(* and contains library functions)

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

How Spring Framework reduce time of development?

A

Spring handles the infrastructure

so you can focus on your application

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

What is POJO?

A

plain old java object

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

How Spring work with POJOs?

A

apply enterprise services to POJO

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

Spring implements various design …

A

patterns

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

…, Builder, Proxy - patterns were implemented in Spring

A

Factory

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

What is IoC purpose?

A

compose fully disparate components into a working app

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

Когда невозможно использовать другие реализации зависимого класса и тестировать главный и зависимый классы раздельно?

A

Когда главный класс инициализирует зависимый класс в конструкторе

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

Как разделить главный и зависимый классы?

A

Создавать раздельно

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

Как можно связать классы при раздельном создании?

A

установить сеттером или передать параметр в конструктор

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

какие проблемы могут быть при установке сеттером

A

переменная до установки сеттером= null

при этом к ней могут обратиться

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

основные проблемы раздельного создания экземпляров классов: порядок создания, установка сеттером всех экземпляров, …

A

порядок параметров в конструкторе

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

How to automate creating of objects and their connections?

A

Dependency Injections

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

How does Dependency Injections work?

A

define dependencies and inject them

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

How to configure dependencies?

A

xml, annotations, java

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

Who can inject dependencies?

A

application context can make it

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

Which file do we use to configure objects via xml?

A

application-context.xml

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

How does tag for class called?

A

bean

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

attribute of “bean” tag for connection with other beans

A

id

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

attribute of “bean” tag for class name

A

class

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

tag inside “bean” tag for filling properties of bean

A

property

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

attribute of “property” tag to find field in bean

A

name

should be exactly the same as field variable in class

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

attribute of “property” tag for filling simple type value into field

A

value

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

attribute of “property” tag for filling reference type value into field

A

ref

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

how to fill ref attribute of “property” tag?

A

use id attribute of appropriate bean

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q
how to create java class by application context
(xml config)
A

Use an instance of ApplicationContext

to call method getBean with id of bean as parameter

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

how application context recognize about beans?

A

application-context.xml

config file is placed as constructor parameter

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

what is internal structure of application context?

A

it contains map for managed objects

key id
value reference to managed objects

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

The creation of the object’s relationships is managed by the container through …

A

Dependency Injections

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

How can you formulate “Hollywood principle”?

A

Don’t call me, I’ll call you

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

What is basic idea of “Hollywood principle”?

A

eliminate dependencies of application components from certain implementation

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

How “Hollywood principle” is realized in IoC?

A

Dependency Injection container instantiate and initialize objects and their dependencies

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

IoC Containers can simplify …

A

unit testing

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

IoC Containers can make code …

A

cleaner

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

IoC Containers give us facilities of …

A

reusing classes or components

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

IoC Containers provide applying changes …

A

without recompiling

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

The … is a central Ioc container into the Spring Framework

A

BeanFactory

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

Which pattern is implemented in BeanFactory?

A

factory pattern

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

Most common implementation of BeanFactory is …

A

XmlBeanFactory

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

ApplicationContext extends BeanFactory and adds …

A

Event handling

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

ApplicationContext extends BeanFactory ability to work with many languages that is called …

A

Internationalization

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

ApplicationContext works with … and messages

A

resources

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

ApplicationContext simply integrates with

A

Spring AOP

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

ApplicationContext differs from BeanFactory by …

A

Specific application contexts

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

Central point of the context module is …

A

Application Context interface

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

… are used in real life

A

Application Contexts

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

… could be used in exceptional cases

A

BeanFactory

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

possible exceptional cases when it’s possible to use BeanFactory

A
  1. Resources are critical and only IoC container is required.
  2. Integrating Spring with framework
    (backward compatibility is necessary)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

… is traditional way to configure a container

A

XML

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

Most widely used implementations of ApplicationContext are GenericXmlApplicationContext, … , FileSystemXmlApplicationContext

A

ClassPathXmlApplicationContext

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

This prefix can be added to config file’s name to say context to find out it in class path

A

classpath:

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

Spring IoC Container uses POJOs and …

A

Configuration Metadata

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

Spring IoC Container produces …

A

Fully configured system

ready to use

60
Q

name of IoC library as maven dependency

A

spring-context

61
Q

It’s possible to get bean from application context by id and by …

A

class

context.getBean(Ex1TestBean.class)

62
Q

How many config files is possible to use?

A

One or more

63
Q

How application context can use several config files?

A

Use array with config file’s names

(new ClassPathXmlApplicationContext (new String[]{
“example2/services.xml”,”example2/dao.xml”
} )

64
Q

How does no-args constructor looks like in xml file?

A

bean tag without properties sub tags

65
Q

What does factory-method attribute in bean tag do?

A

Create new bean like constructor

66
Q

How can we pass parameter in factory method?

A

by constructor-arg tag (value attribute)

67
Q

Factory class can build bean that uses … and factory-method attributes in config files

A

factory-bean

68
Q

What is lazy initialization is used to?

A

to postpone bean creation to the time it is first addressed

69
Q

When is lazy bean created?

A

after the call to getBean()

70
Q

How can we combine several config files in one?

A

using tag import in main config file

71
Q

How does placeholders look like in Spring config files?

A

${variable_name}

72
Q

Spring reads properties files declared by …

A

PPC (PropertyPlaceholderConfigurer) bean

M1-core, page 43

73
Q

By default, Spring looks for the property files in the …

A

application’s directory

74
Q

We can use prefix … to tell Spring to load a properties file in the application’s classpath

A

classpath:

75
Q

We use prefix … to load a properties file from the absolute path

A

file:/// (or file:)

76
Q

How does Spring externalize it’s application context by property files?

A

using placeholders

use keys from property files for filling placeholders in spring config files

77
Q

what is alias?

A

tag that allows to call one bean using different id

78
Q

how we can use alias?

A

override bean definitions are inherited from external sources

79
Q

For using constructor dependency injection we need constructor-arg tags and …

A

constructor in class

80
Q

What is cyclic dependency?

A

2 linked classes take each other in contructor

81
Q

What exception will we get using Dependency Injection for cyclic dependency?

A

BeanCurrentlyInCreationException

82
Q

How to avoid BeanCurrentlyInCreationException?

A

replace constructor di with setter di

in one or both classes

83
Q

For using setter dependency injection we need property tags and …

A

setters

84
Q

Ability of Spring to resolve and add dependencies automatically is

A

autowiring

85
Q

How can autowiring change the volume of configuration?

A

significantly reduce

86
Q

Autowiring can cause configuration to keep itself …

A

up to date

87
Q

Autowiring … can only work if application context contains exactly one bean of a property type

A

by type

88
Q

One of the biggest disadvantages of Autowiring is

A

harder to read and check dependencies

89
Q

Default mode of autowiring is

A

no

no autowiring

90
Q

Mode of autowiring when container looks for a bean with id the same as the property

A

byName

91
Q

Mode of autowiring when container looks for a bean of specific class

A

byType

92
Q

byType autowire can find more then one bean of the same class then … exception wil be thrown

A

UnsatisfiedDependencyException

93
Q

byType autowire that use constructor

A

constructor autowire

94
Q

what is the tag in config file that provides initialization of collections?

A

property

95
Q

Tags list, …, map contains entities for initialization of collections

A

set

96
Q

Bean tag attribute … allow to inherit attributes of other bean

A

parent

97
Q

Tag property allows to … or inherit parent bean’s attributes

A

override

98
Q

What does tag contains elements of Property class?

A

props

99
Q

Sub tag … of property tag set null value for bean attribute

A

null

100
Q

Basic supported annotations are

A

@Autowired and @Component

101
Q

Annotation … applies to bean property setter method

A

@Autowired

102
Q

@Autowired is applied to setters, … and …

A

constructors and methods

103
Q

@Autowired is applied to properties, … and

A

arrays and typed collections

104
Q

How is it possible to avoid throwing exception if there isn’t appropriate bean for @Autowired

A

@Autowired (required=false)

105
Q

How many constructors in bean class may carry annotation?

A

one

106
Q

Which access modifier should be for constructor in bean class ?

A

not public

107
Q

When are fields injected in bean?

A

right after constructions

108
Q

Which access modifier should be for config fields in bean class ?

A

not public

109
Q

For specifying Spring components without xml use annotation …

A

@Component

110
Q

@Component applies to …

A

classes

111
Q

@Component serves as a … for every Spring-managed component

A

generic stereotype

112
Q

More specific stereotypes more @Component are

A

@Service, @Repository, @Controller

113
Q

Which command should you specify to automatically register beans through annotations?

A

context: component-scan base-package=””

114
Q

General bean scopes are singleton and …

A

prototype

115
Q

Web-specific bean scopes are … and session

A

request

116
Q

default bean scope is …

A

singleton

117
Q

Only .. instance is injected into each collaborating object with singleton bean scope

A

one

118
Q

in order to create new bean when it’s injected into another bean use … bean scope

A

prototype

119
Q

You can also use … to define bean scope

A

annotation

@Scope (“prototype”)

120
Q

Which interface should you implement for managing bean creation?

A

InitializingBean

121
Q

Which method should you override for managing bean creation?

A

afterPropertiesSet()

122
Q

Which interface should you implement for managing bean deletion?

A

DisposableBean

123
Q

Which method should you override for managing bean deletion?

A

destroy()

124
Q

Which are attributes of bean tag to indicate overridden methods to manage bean lifecycle?

A

init-method

destroy-method

125
Q

How to access bean context?

A

implement ApplicationContextAware

126
Q

How to create event listener in Spring?

A

implement ApplicationListener

127
Q

How to create event in Spring?

A

Extend ApplicationEvent

128
Q

Which class can publish events?

A

ApplicationContext

129
Q

Annotation to subscribe event is …

A

@EventListener

130
Q

Which class is responsible for working with message.properties files?

A

RBMS (ResourceBundleMessageSource)

131
Q

What parameters do you send in method getMessage of application context to get localized message?

A

1-st: messages with empty spaces
2-nd: array with parameters
3-rd: language

context.getMessage(“customer.name”, new Object[]{28,”www.luxoft.com”}, Locale.English)

132
Q

What is configuration profile?

A

It’s attribute of beans tag that allows you to use 2 beans with the same id and class but different values.

133
Q

How does java-based configuration looks like?

A

java class is marked @Configuration

134
Q

How can you configure bean in java based configuration?

A

mark factory method @Bean

135
Q

Which does app context work with java-based configuration?

A

ACAC (AnnotationConfigApplicationContext)

136
Q

What does @ComponentScan do?

A

Scan all classes with @Component and set appropriate bean in fields with @Autowire.

137
Q

What does @Import do?

A

combine several configurations

138
Q

What does @ImportResource do?

A

combine java-based configuration and application-contex.xml

139
Q

What does @Value do?

A

set value from properties file in field

140
Q

What does @PropertySource do?

A

adds property file to Spring environment

141
Q

What does @Order do?

A

define sort order for annotated component

142
Q

How does @Order work with Autowire?

A

allows to set collection

143
Q

XML configuration doesn’t need more additional dependencies to the …

A

Dependencies Injection framework

144
Q

Java based configuration is a … configuration

A

type safe

145
Q

Why is Java based configuration type safe?

A

compiler reports issues if you are configuring in a wrong way