Spring Class_04.2020_CORE_IoC Flashcards

(145 cards)

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
attribute of "bean" tag for connection with other beans
id
26
attribute of "bean" tag for class name
class
27
tag inside "bean" tag for filling properties of bean
property
28
attribute of "property" tag to find field in bean
name should be exactly the same as field variable in class
29
attribute of "property" tag for filling simple type value into field
value
30
attribute of "property" tag for filling reference type value into field
ref
31
how to fill ref attribute of "property" tag?
use id attribute of appropriate bean
32
``` how to create java class by application context (xml config) ```
Use an instance of ApplicationContext | to call method getBean with id of bean as parameter
33
how application context recognize about beans?
application-context.xml | config file is placed as constructor parameter
34
what is internal structure of application context?
it contains map for managed objects key id value reference to managed objects
35
The creation of the object's relationships is managed by the container through ...
Dependency Injections
36
How can you formulate "Hollywood principle"?
Don't call me, I'll call you
37
What is basic idea of "Hollywood principle"?
eliminate dependencies of application components from certain implementation
38
How "Hollywood principle" is realized in IoC?
Dependency Injection container instantiate and initialize objects and their dependencies
39
IoC Containers can simplify ...
unit testing
40
IoC Containers can make code ...
cleaner
41
IoC Containers give us facilities of ...
reusing classes or components
42
IoC Containers provide applying changes ...
without recompiling
43
The ... is a central Ioc container into the Spring Framework
BeanFactory
44
Which pattern is implemented in BeanFactory?
factory pattern
45
Most common implementation of BeanFactory is ...
XmlBeanFactory
46
ApplicationContext extends BeanFactory and adds ...
Event handling
47
ApplicationContext extends BeanFactory ability to work with many languages that is called ...
Internationalization
48
ApplicationContext works with ... and messages
resources
49
ApplicationContext simply integrates with
Spring AOP
50
ApplicationContext differs from BeanFactory by ...
Specific application contexts
51
Central point of the context module is ...
Application Context interface
52
... are used in real life
Application Contexts
53
... could be used in exceptional cases
BeanFactory
54
possible exceptional cases when it's possible to use BeanFactory
1. Resources are critical and only IoC container is required. 2. Integrating Spring with framework (backward compatibility is necessary)
55
... is traditional way to configure a container
XML
56
Most widely used implementations of ApplicationContext are GenericXmlApplicationContext, ... , FileSystemXmlApplicationContext
ClassPathXmlApplicationContext
57
This prefix can be added to config file's name to say context to find out it in class path
classpath:
58
Spring IoC Container uses POJOs and ...
Configuration Metadata
59
Spring IoC Container produces ...
Fully configured system | ready to use
60
name of IoC library as maven dependency
spring-context
61
It's possible to get bean from application context by id and by ...
class | context.getBean(Ex1TestBean.class)
62
How many config files is possible to use?
One or more
63
How application context can use several config files?
Use array with config file's names (new ClassPathXmlApplicationContext (new String[]{ "example2/services.xml","example2/dao.xml" } )
64
How does no-args constructor looks like in xml file?
bean tag without properties sub tags
65
What does factory-method attribute in bean tag do?
Create new bean like constructor
66
How can we pass parameter in factory method?
by constructor-arg tag (value attribute)
67
Factory class can build bean that uses ... and factory-method attributes in config files
factory-bean
68
What is lazy initialization is used to?
to postpone bean creation to the time it is first addressed
69
When is lazy bean created?
after the call to getBean()
70
How can we combine several config files in one?
using tag import in main config file
71
How does placeholders look like in Spring config files?
${variable_name}
72
Spring reads properties files declared by ...
PPC (PropertyPlaceholderConfigurer) bean | M1-core, page 43
73
By default, Spring looks for the property files in the ...
application's directory
74
We can use prefix ... to tell Spring to load a properties file in the application's classpath
classpath:
75
We use prefix ... to load a properties file from the absolute path
file:/// (or file:)
76
How does Spring externalize it's application context by property files?
using placeholders | use keys from property files for filling placeholders in spring config files
77
what is alias?
tag that allows to call one bean using different id
78
how we can use alias?
override bean definitions are inherited from external sources
79
For using constructor dependency injection we need constructor-arg tags and ...
constructor in class
80
What is cyclic dependency?
2 linked classes take each other in contructor
81
What exception will we get using Dependency Injection for cyclic dependency?
BeanCurrentlyInCreationException
82
How to avoid BeanCurrentlyInCreationException?
replace constructor di with setter di | in one or both classes
83
For using setter dependency injection we need property tags and ...
setters
84
Ability of Spring to resolve and add dependencies automatically is
autowiring
85
How can autowiring change the volume of configuration?
significantly reduce
86
Autowiring can cause configuration to keep itself ...
up to date
87
Autowiring ... can only work if application context contains exactly one bean of a property type
by type
88
One of the biggest disadvantages of Autowiring is
harder to read and check dependencies
89
Default mode of autowiring is
no | no autowiring
90
Mode of autowiring when container looks for a bean with id the same as the property
byName
91
Mode of autowiring when container looks for a bean of specific class
byType
92
byType autowire can find more then one bean of the same class then ... exception wil be thrown
UnsatisfiedDependencyException
93
byType autowire that use constructor
constructor autowire
94
what is the tag in config file that provides initialization of collections?
property
95
Tags list, ..., map contains entities for initialization of collections
set
96
Bean tag attribute ... allow to inherit attributes of other bean
parent
97
Tag property allows to ... or inherit parent bean's attributes
override
98
What does tag contains elements of Property class?
props
99
Sub tag ... of property tag set null value for bean attribute
null
100
Basic supported annotations are
@Autowired and @Component
101
Annotation ... applies to bean property setter method
@Autowired
102
@Autowired is applied to setters, ... and ...
constructors and methods
103
@Autowired is applied to properties, ... and
arrays and typed collections
104
How is it possible to avoid throwing exception if there isn't appropriate bean for @Autowired
@Autowired (required=false)
105
How many constructors in bean class may carry annotation?
one
106
Which access modifier should be for constructor in bean class ?
not public
107
When are fields injected in bean?
right after constructions
108
Which access modifier should be for config fields in bean class ?
not public
109
For specifying Spring components without xml use annotation ...
@Component
110
@Component applies to ...
classes
111
@Component serves as a ... for every Spring-managed component
generic stereotype
112
More specific stereotypes more @Component are
@Service, @Repository, @Controller
113
Which command should you specify to automatically register beans through annotations?
context: component-scan base-package=""
114
General bean scopes are singleton and ...
prototype
115
Web-specific bean scopes are ... and session
request
116
default bean scope is ...
singleton
117
Only .. instance is injected into each collaborating object with singleton bean scope
one
118
in order to create new bean when it's injected into another bean use ... bean scope
prototype
119
You can also use ... to define bean scope
annotation | @Scope ("prototype")
120
Which interface should you implement for managing bean creation?
InitializingBean
121
Which method should you override for managing bean creation?
afterPropertiesSet()
122
Which interface should you implement for managing bean deletion?
DisposableBean
123
Which method should you override for managing bean deletion?
destroy()
124
Which are attributes of bean tag to indicate overridden methods to manage bean lifecycle?
init-method | destroy-method
125
How to access bean context?
implement ApplicationContextAware
126
How to create event listener in Spring?
implement ApplicationListener
127
How to create event in Spring?
Extend ApplicationEvent
128
Which class can publish events?
ApplicationContext
129
Annotation to subscribe event is ...
@EventListener
130
Which class is responsible for working with message.properties files?
RBMS (ResourceBundleMessageSource)
131
What parameters do you send in method getMessage of application context to get localized message?
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
What is configuration profile?
It's attribute of beans tag that allows you to use 2 beans with the same id and class but different values.
133
How does java-based configuration looks like?
java class is marked @Configuration
134
How can you configure bean in java based configuration?
mark factory method @Bean
135
Which does app context work with java-based configuration?
ACAC (AnnotationConfigApplicationContext)
136
What does @ComponentScan do?
Scan all classes with @Component and set appropriate bean in fields with @Autowire.
137
What does @Import do?
combine several configurations
138
What does @ImportResource do?
combine java-based configuration and application-contex.xml
139
What does @Value do?
set value from properties file in field
140
What does @PropertySource do?
adds property file to Spring environment
141
What does @Order do?
define sort order for annotated component
142
How does @Order work with Autowire?
allows to set collection
143
XML configuration doesn't need more additional dependencies to the …
Dependencies Injection framework
144
Java based configuration is a ... configuration
type safe
145
Why is Java based configuration type safe?
compiler reports issues if you are configuring in a wrong way