September 28, 2010
java2010-09-28 13:06:23 0 comments Word Count: Spring container supports the use of the XML bean factory assembly class
XmlBeanFactory: a simple BeanFactory, it uses java.io.InputStream
ClassPathXmlApplicationContext: an application context, it is loaded from the classpath, context definition file
FileSystemXmlApplicationContext : an application context, it is loaded from the file system context file
XmlWebApplicationContext: Spring-based Web applications up and down the file, file it down from the Web application context definition file loaded.
2: Basic format
beans>
3: prototype and single-instance:
default is a single instance, if you use the prototype, you can use the following form
class = “”
singleton = “false” />
beans>
4: instantiated and destroyed
can use the init-method, the Bean is instantiated when Hou was immediately called, and you can set destory -method, remove from the window in the Bean before calling. Spring also provides two interfaces to achieve the same functionality: InitializingBean and DisposableBean.
InitializingBean provides a method afterPropertiesSet (), after setting all properties used in the call, DisposableBean provides a destroy -method for the destruction of Bean
class = “”
init-method = “” destroy-method =”"/>
beans>
5: Set method by injecting dependencies
Bean usually there are some simple types of properties,
to set the basic types of properties
class = “”>
value>
propery>
bean>
beans>
6: References to other Bean
elements used to set the properties to other Bean . Sub-elements with
[ Let achieve this. ]
class = “”>
propery>
bean>
beans>
7: Internal Bean
do not use another method of assembly Bean reference element is embedded in a
element,
class = “”>
propery>
bean>
8: assembling a collection
Spring support collection type
XML type
java.awt.List, arrays
java.awt.Set