Springメモ1
一.配置Spring:
1、スプリング依存ライブラリ * SPRING_HOME/dist/spring.jar * SPRING_HOME/lib/jakata-commons/commons-loging.jar * SPRING_HOME/lib/log 4 j/log 4 j-1. 2、springプロファイルをsrcの下にコピーして3、logl 4 jプロファイルをsrcの下にコピーして4、UserManagerImplに構築関数またはsetter方法を提供して、springは実用化されたUserDaoを注入して5、springに私達のオブジェクトの作成と依存を管理させて、spring配置で定義して6、クライアントを作成しなければなりません.
スプリングIoc容器のポイント: * 管理されているオブジェクトをspringプロファイルに定義しなければなりません. * 立体関数またはsetter方法を定義して、springにオブジェクトを注入する必要があります.
二.インスタンス1:カスタム属性エディタ
1、スプリングの普通属性注入 参照:spring文書3.3章 属性エディタとは何ですか? * カスタム属性エディタ、springプロファイルの文字列を対応するオブジェクトに変換して注入します. springにはすでに内蔵のプロパティエディタがあります.必要に応じて自分で属性エディタを定義できます. * 属性エディタはどのように定義しますか? * PropertyEditors Support類を継承し、set AstText()を上書きする方法 * プロパティエディタをspringに登録します.
オブジェクトに依存する注入方式は、 * ref属性 * ラベル * 内部を定義します. どうやって公共の注入定義を説明しますか? * ラベルで共通の属性を定義し、abstract=trueを指定します.
* 同じ属性を持つクラスは、タブでそのparent属性を指定します.
ビーンのスコープ
scopeは値を取ることができます * singleton:getBenを呼び出すたびに同じ例を返します. * prototype:getBenを呼び出すたびに異なるインスタンスを返します.
名称により自動組立
タイプによって自動組立
1、スプリング依存ライブラリ * SPRING_HOME/dist/spring.jar * SPRING_HOME/lib/jakata-commons/commons-loging.jar * SPRING_HOME/lib/log 4 j/log 4 j-1. 2、springプロファイルをsrcの下にコピーして3、logl 4 jプロファイルをsrcの下にコピーして4、UserManagerImplに構築関数またはsetter方法を提供して、springは実用化されたUserDaoを注入して5、springに私達のオブジェクトの作成と依存を管理させて、spring配置で定義して6、クライアントを作成しなければなりません.
スプリングIoc容器のポイント: * 管理されているオブジェクトをspringプロファイルに定義しなければなりません. * 立体関数またはsetter方法を定義して、springにオブジェクトを注入する必要があります.
二.インスタンス1:カスタム属性エディタ
1、スプリングの普通属性注入 参照:spring文書3.3章 属性エディタとは何ですか? * カスタム属性エディタ、springプロファイルの文字列を対応するオブジェクトに変換して注入します. springにはすでに内蔵のプロパティエディタがあります.必要に応じて自分で属性エディタを定義できます. * 属性エディタはどのように定義しますか? * PropertyEditors Support類を継承し、set AstText()を上書きする方法 * プロパティエディタをspringに登録します.
<!-- -->
<bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="java.util.Date">
<bean class="com.bjsxt.spring.UtilDatePropertyEditor">
<property name="format" value="yyyy-MM-dd"/>
</bean>
</entry>
</map>
</property>
</bean>
<!-- -->
オブジェクトに依存する注入方式は、 * ref属性 * ラベル * 内部
<bean id="beanAbstract" abstract="true">
<property name="id" value="1000"/>
<property name="name" value="Jack"/>
</bean>
* 同じ属性を持つクラスは、
<bean id="bean3" class="com.spring.Bean3" parent="beanAbstract">
<!-- -->
<property name="name" value="Tom"/>
<property name="password" value="123"/>
</bean>
ビーンのスコープ
scopeは値を取ることができます * singleton:getBenを呼び出すたびに同じ例を返します. * prototype:getBenを呼び出すたびに異なるインスタンスを返します.
<bean id="bean1" class="com.spring.Bean1" scope="prototype"/>
名称により自動組立
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
<!-- -->
default-autowire="byName"
>
タイプによって自動組立
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
<!-- -->
default-autowire="byType"
>