-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
29 lines (21 loc) · 1.2 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Creating a bean after application initialization and inserting it into
the context so that it becomes a Spring-managed bean.
https://docs.spring.io/spring/docs/4.3.14.RELEASE/spring-framework-reference/htmlsingle/#beans-definition
In addition to bean definitions that contain information on how to
create a specific bean, the ApplicationContext implementations also
permit the registration of existing objects that are created outside
the container, by users. This is done by accessing the
ApplicationContext’s BeanFactory via the method getBeanFactory()
which returns the BeanFactory implementation
DefaultListableBeanFactory. DefaultListableBeanFactory supports this
registration through the methods registerSingleton(..) and
registerBeanDefinition(..).
(1) ApplicationContext doesn't have a .getBeanFactory() method. I used
AbstractApplicationContext instead.
(2) getBeanFactory() doesn't return a DefaultListableBeanFactory, it
returns a ConfigurableListableBeanFactory. I used
ConfigurableListableBeanFactory instead, seemed to work.
To run this:
./mvnw spring-boot:run
Somewhere in the output, this line should appear:
Book: Book [title=Craig Walls, author=Spring in Action]