Java Springデータユニット構成過程解析
基本原理-容器とbean
Springでは、あなたのアプリケーションを構成する主体(backbone)やSpring IoC容器によって管理されている対象をbeanと呼びます。簡単に言えば、beanはSpring容器から初期化され、組み立て及び管理される対象であり、それ以外に、beanはアプリケーションの他のオブジェクトと区別がない。
つまり、springとは、設定ファイルのbeans.xmlをロードする際に、反射メカニズムによってラベルの中のクラスを実際化する過程です。ここではクラスのデフォルトの無参構造方法に何かを書くことで判断できます。
1.メタデータの設定
XMLベースの構成メタデータの基本構成:beans.xml
配置ファイルの名前はIDとnameは同じです。
Application Contect context=new Class PathXml Application Contect(
new String[]{beans.xml}
3.べンの別名
<!--nameはすでにこのidが存在するbeanを指しています。aliasはこのbeanに命を与える別名です。
<alias name=「user Service」alias=「user」/>
呼び出しは以下の通りです。
Springでは、あなたのアプリケーションを構成する主体(backbone)やSpring IoC容器によって管理されている対象をbeanと呼びます。簡単に言えば、beanはSpring容器から初期化され、組み立て及び管理される対象であり、それ以外に、beanはアプリケーションの他のオブジェクトと区別がない。
つまり、springとは、設定ファイルのbeans.xmlをロードする際に、反射メカニズムによって
1.メタデータの設定
XMLベースの構成メタデータの基本構成:beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="..." class="...">
<!-- collaborators and configuration for this bean go here -->
</bean>
<bean id="..." class="...">
<!-- collaborators and configuration for this bean go here -->
</bean>
<!-- bean xml spring dtd -->
<import resource="services.xml"/>
</beans>
services.xml配置ファイルの名前はIDとnameは同じです。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="userService" name="userService" class="com.sun.service.UserService">
<property name="name">
<value>sunxin</value>
</property>
</bean>
</beans>
2.実用化容器Application Contect context=new Class PathXml Application Contect(
new String[]{beans.xml}
3.べンの別名
<!--nameはすでにこのidが存在するbeanを指しています。aliasはこのbeanに命を与える別名です。
<alias name=「user Service」alias=「user」/>
呼び出しは以下の通りです。
UserService us = (UserService) app.getBean("user");
以上が本文の全部です。皆さんの勉強に役に立つように、私たちを応援してください。