Tradionally The java grammer usually use the ‘new’ keyword when you want to make the new object something. but It’s really different in The Spring Framework. If you want to create new instance then The Spring Framework always recommands to use the Spring Container or IoC. (Actually they are same thing.) and This coding style named as ‘IoC’. It means Inversion of Control. Actually It includes many meaningful concepts but the most important thinking is that we don’t need to make the new instance at the inner code anymore. So It’s Inversion of Control.
POJO (Plain Old Java Object)
Do you know the correct definition of POJO Class? actually I don’t know either. but I can understand just little bit about this. It’s the really pure java code style without any annotation or somthing make more complexible. The below is simple example for understaing.
Many Spring Project existed over the world usually use the ‘xml’ file for setiing the meta information for Spring Container. So We can make some misconception of SpringFramework. It’s ‘Spring Container Setiing Information must be made by xml files’ but It’s not true.
Spring Framework has the BeanDefinition Interface. Fundamentally any type of files for setting the Information of Spring Container can be converted to this interface using BeanDefinitionReader Interface. and Actually The type of Spring Container setting information is always BeanDefinition.
1 2
Meta Resource file(.xml) > BeanDefinitionReader > BeanDefinition
publicclassMain { publicstaticvoidmain(String[] args) { StaticApplicationContextac=newStaticApplicationContext(); // create Spring Container ac.registerSingleton("hello1", Hello.class); // register the Hello POJO Class in Spring Container as the method of Singleton // create the bean using the setting information offered StaticApplicationContext basically without BeanDefinition
Hellohello1= ac.getBean("hello1", Hello.class); // get the Hello instance using the Spring Container assertThat(hello1, is(notNullValue())); // It like one of the unit test, It is for checking whether the hello1 object is taken an instance from Spring Container or not
BeanDefinitionhelloDef=newRootBeanDefinition(Hello.class); // proclaim the BeanDefinition for controlling the setting information of IoC Container directly helloDef.getPropertyValues().addPropertyValue("name", "Spring"); // add the attributes ac.registerBeanDefinition("hello2", helloDef); // create the object using the BeanDefinition meta information and StaticApplicationContext BeanDefinition