spring-lifecycle-xsd---2013-08-07

3487 ワード

Lifecycle callbacksInitializingBean and DisposableBean interfaces.The container callsafterPropertiesSet() for the former and destroy() for the latter to allow the bean to performcertain actions upon initialization and destruction of your beans.prototypeと一緒に使わないでください
Initialization callbacks
<bean id="exampleInitBean" class="examples.ExampleBean" init-method="init"/>
public class ExampleBean {
public void init() {
// do some initialization work
}
}

 
...is exactly the same as...
<bean id="exampleInitBean" class="examples.AnotherExampleBean"/>
public class AnotherExampleBean implements InitializingBean {
public void afterPropertiesSet() {
// do some initialization work
}
}

 
Destruction callbacks
<bean id="exampleInitBean" class="examples.ExampleBean" destroy-method="cleanup"/>
public class ExampleBean {
public void cleanup() {
// do some destruction work (like releasing pooled connections)
}
}

 
...is exactly the same as...
<bean id="exampleInitBean" class="examples.AnotherExampleBean"/>
public class AnotherExampleBean implements DisposableBean {
public void destroy() {
// do some destruction work (like releasing pooled connections)
}
}

 
Default initialization and destroy methods
<beans default-init-method="init">
<bean id="blogService" class="com.foo.DefaultBlogService">
<property name="blogDao" ref="blogDao" />
</bean>
</beans>

 
The presence of the default-init-method attribute on the top-level element attributecauses the Spring IoC container to recognize a method called init on beans as the initialization methodcallback.
Where existing bean classes already have callback methods that are named at variance with theconvention, you can override the default by specifying (in XML, that is) the method name using theinit-method and destroy-method attributes of the itself.
 
 
 
 
 
Annotation-based container configuration
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
<!--     ="http://www.springframework.org/schema/beans"
 xsd -->
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config/>
</beans>

 .xsdファイル(メタデータファイル)定義xmlファイル構文このxmlファイルに現れる要素を制御
1つのxmlファイルに複数のxsdを導入できます
myeclipseのxml catalogで構成しないと、ネット上で探す速度が遅くなります.
schemaLocation
xmlns:xml name space