some of the concepts in the spring IOC

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




3: prototype and single-instance:
default is a single instance, if you use the prototype, you can use the following form

class = “”
singleton = “false” />

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 =”"/>

5: Set method by injecting dependencies
Bean usually there are some simple types of properties, to set the basic types of properties

class = “”>





6: References to other Bean
elements used to set the properties to other Bean . Sub-elements with Let achieve this.

class = “”>





7: Internal Bean
do not use another method of assembly Bean reference element is embedded in a element,


class = “”>



8: assembling a collection
Spring support collection type
XML type
java.awt.List, arrays
java.awt.Set


java.awt.Map
java.awt.Properties

class = “”>

barl




9: Assembly Map
In Spring
elements can be used to assemble a collection java.util.Map.

class = “”>


bar1



< / entry>



10: assembly Properties
java.util.Properties Spring is finally assembled in a collection of classes, to assemble it using elements, and
to use are very similar, they are the largest The difference is that the value can only be String type.
bar1
bar2



11: set null
If you need to explicitly set the value of an attribute to NULL, just use element on the line
12: an alternative to injection (constructor injection of dependencies)
sometimes attribute values ??can only be set once created, can not be changed later, Sometimes all the properties exposed by the set method is not possible. By constructor to set the value of the property instead.
use the Set injection, we injected element value of the property. Constructor is the same, but under the by element element to specify the instance of the bean needed parameters. One of these two methods in different places is: no name attribute, and have a name this property.


42





< br />

in the use of the constructor, the parameters will have a lot of uncertainty, there are two ways to deal with the uncertainty of the constructor: serial number and type element has an optional index attribute, the constructor can be used to specify the order, you can also use the type attribute to specify the exact type of each parameters, it can specify each parameter type.


http : / / www.manning.com


http://www.springinaction.com


The following is a type of form

< br />
http://www.manning.com


http://www.springinaction.com



If two parameters are the same data type (such as is String), then you can only use the index property
13 : automatic assembly:
Spring to get automatic assembly, automatic assembly as long as the need to set the autowire attribute .
There are four types of automatic assembly byName, byType, constructor, autodetect
14
distributed configuration in most cases, the Bean in a assembly system, you can assign it to a different file, you can configure the assembly file in the Bean Data Source.
15 custom property editor
getAsText (): Returns a string attribute value that
setAsText (String value): the string passed to it is assigned to Bean properties
custom editor includes ClassEditor, CustomDateEditor, FileEditor, LocalEdito r, StringArrayPropertyEditor, StringTrimmerEditor.

Posted: January 6th, 2012
at 11:18am by admin

Tagged with


Categories: Uncategorized

Comments: No comments


Think E-Cigarette, Think Kimree!