Appendix A. XML 스키마-기반 설정

A.1. 설정

이 추가된 부분은 Spring 2.0에서 소개된 XML스키마 기반의 설정을 상세하게 언급한다.

XML 스키마 기반의 설정파일로 이동하기 위한 중심이 되는 동기는 Spring XML설정을 좀더 쉽게 만들고자 함이다. 'classic' <bean/>-기반의 접근법도 좋지만, 설정이라는 개념에서 오버헤드라는 비용을 치루어야 한다.

Spring IoC 컨테이너 관점에서, 모든것은 bean이다. 모든것이 bean이라면 모든것은 정확히 같은 형태로 처리될수 있기 때문에 그것은 Spring IoC컨테이너를 위해 굉장히 좋은 소식이다. 어쨌든 이것은 개발자의 관점에서는 참이 되지 않는다. Spring XML설정파일내 정의된 객체는 모두 일반적이지는 않다. 언제나 각각의 bean은 몇가지 특정 설정의 단계를 요구한다.

Spring 2.0의 새로운 XML스키마-기반의 설정은 이러한 이슈를 할당한다. <bean/> 요소는 여전히 존재한다. 당신이 원한다면, 오직 <bean/> 요소를 사용하는 Spring XML설정을 계속 사용할수 있다. 어쨌든 새로운 XML스키마-기반 설정은 Spring XML설정파일을 특히 읽기 명백하도록 해준다. 추가적으로 이것은 bean정의의 목적을 표시하도록 해준다.

기억해야하는 핵심사항은 예를 들어, AOP, collection, transaction, Mule와 같은 이기종 프레임워크와의 통합과같이 새로운 사용자정의 태그가 하부조직(infrastructure)이나 통합(integration) bean을 위한 가장 잘 작동한다는 것이다. 현재 존재하는 bean태그는 DAO, 서비스 레이어 객체, validator등등 애플리케이션 특유의 bean에 가장 적합하다.

아래의 예제는 Spring 2.0의 XML스키마지원이 좋은 생각이라고 당신을 납득시킬것이다. 또한 이 새로운 설정기법이 전체적으로 사용자정의가능하고 확장가능하다는 것을 노트하라. 이것은 당신의 애플리케이션 도메인을 좀더 잘 표현할 자체적인 도메인 속성의 설정 태그를 작성할수 있다는 것을 의미한다. 이 절차는 Appendix B, 확장가능한 XML제작에서 다루어진다.

A.2. XML 스키마-기반 설정

A.2.1. 스키마 참조하기

DTD-스타일에서 새로운 XML스키마-스타일로의 전환을 위해, 당신은 다음을 변경할 필요가 있다.

<!-- DTD-style -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
    "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<beans>

<!-- <bean/> definitions here -->

</beans>

XML스키마-스타일에서 같은 파일은.....

<!-- XML Schema-style -->
<?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.0.xsd">

<!-- <bean/> definitions here -->

</beans>
[Note]Note

'xsi:schemaLocation' 조각은 실제로 필수는 아니지만, 스키마의 local복사 참조에 포함될수 있다.(개발하는 동안 유용하다.).

위 Spring XML설정 조각은 다소 반복적 어구를 사용한다. 기존에 한것처럼 이것을 간단히 사용하고 <bean/> 정의를 작성하는 것을 지속할수 있다. 어쨌든, 전체적인 전환은 새로운 Spring 2.0 XML태그의 장점을 가져서 좀더 설정이 쉽다. Section A.2.2, “util 스키마”는 당신이 몇가지 공통적인 유틸리티 태그를 사용하여 즉시 시작할수 있는 방법을 보여준다.

이 장의 나머지는 새로운 모든 태그의 사용을 적어도 한번은 하는 새로운 Spring XML스키마 기반의 설정의 예제를 보여준다. 형태는 before 과 after 스타일을 따른다. 여기서 before는 이전것을 보여주고 after는 새로운 XML스키마 기반의 스타일을 보여준다.

A.2.2. util 스키마

첫번째는 util 태그이다. 이름이 뜻하는 것처럼, util태그는 설정집합, 참조상수와 같은 utility 설정이슈를 공통으로 다룬다.

util 스키마내 태그를 사용하기 위해, Spring XML설정파일의 가장 위에 다음의 머릿말을 둘 필요가 있다. 아래의 텍스트는 정확한 스키마를 참조하기 때문에 util 명명공간내 태그는 사용가능하다.

<?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:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">

<!-- <bean/> definitions here -->

</beans>

A.2.2.1. <util:constant/>

Before...

<bean id="..." class="...">
  <property name="isolation">
    <bean id="java.sql.Connection.TRANSACTION_SERIALIZABLE"
    class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" />
  </property>
</bean>

위 설정은 bean의 'isolation' 프라퍼티 값을 'java.sql.Connection.TRANSACTION_SERIALIZABLE'상수의 값으로 셋팅하는 Spring FactoryBean 구현물인 FieldRetrievingFactoryBean을 사용한다. 이것은 모두 잘되고 좋지만, 다소 장황하고 마지막 사용자에게 Spring의 내부 작동을 보여준다.

다음의 XML 스키마-기반의 버전은 좀더 간결하고 명백하게 개발자의 의도('inject this constant value')를 표시한다. 그리고 이것은 읽기가 더 좋다.

<bean id="..." class="...">
  <property name="isolation">
    <util:constant static-field="java.sql.Connection.TRANSACTION_SERIALIZABLE"/>
  </property>
</bean>
A.2.2.1.1. 필드값으로 부터 bean프라퍼티나 생성자의 인자를 셋팅하기

FieldRetrievingFactoryBean정적이거나(static) 비-정적인 필드값을 가져오는 FactoryBean이다. 이것은 대개 다른 bean을 위한 프라퍼티 값이나 생성자의 인자를 셋팅하기 위해 사용된 public static final 상수를 가져오기 위해 사용된다.

staticField 를 사용하여 static 필드를 나타내는 방법을 보여주는 예제를 아래에서 보라. property:

<bean id="myField"
        class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
  <property name="staticField" value="java.sql.Connection.TRANSACTION_SERIALIZABLE"/>
</bean>

여기엔 또한 static 필드가 bean이름처럼 명시되는 편리한 사용형태가 있다.

<bean id="java.sql.Connection.TRANSACTION_SERIALIZABLE"
	class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"/>

이것은 bean id가 무엇인지 더이상 선택하지 않는다는 것을 의미한다(그래서 이것을 참조하는 다른 bean은 더 긴 이름을 사용할것이다.). 하지만 이 형태는 정의하기 위해 매우 간결하고 id는 bean참조를 명시할 필요가 없기 때문에 내부 bean처럼 사용하기 위해 매우 편리하다.

<bean id="..." class="...">
	<property name="isolation">
	<bean id="java.sql.Connection.TRANSACTION_SERIALIZABLE"
		  class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" />
	</property>
	</bean>

FieldRetrievingFactoryBean를 위한 API문서에서 언급하는 것처럼 다른 bean의 비-정적인 필드에 접근하는 것이 가능하다.

프라퍼티나 생성자의 인자처럼 bean으로 enum값을 삽입하는 것은 Spring에서 쉬운일이다. Spring내부(또는 FieldRetrievingFactoryBean와 같은 클래스에 대해)에 대해 어떤것을 하거나 알지 않는다. enum값을 쉽게 삽입하는 방법을 보여주는 예제를 보자. 이것은 JDK 5의 enum을 살펴보는 것이다.

package javax.persistence;
	 
	public enum PersistenceContextType {

	TRANSACTION,
	EXTENDED

	}

지금 PersistenceContextType타입의 setter를 생각해보자.

package example;

	public class Client {

	private PersistenceContextType persistenceContextType;

	public void setPersistenceContextType(PersistenceContextType type) { 
		this.persistenceContextType = type;
	}
	}

.. 그리고 일치하는 bean정의는

<bean class="example.Client">
	<property name="persistenceContextType" value="TRANSACTION" />
	</bean>

이것은 전통적인 방식의 type-safe모방의 enum(JDK 1.4와 JDK1.3)에 잘 작동한다. Spring은 string프라퍼티 값을 enum클래스의 상수에 일치시키도록 자동으로 시도할것이다.

A.2.2.2. <util:property-path/>

Before...

<!-- target bean to be referenced by name -->
<bean id="testBean" class="org.springframework.beans.TestBean" scope="prototype">
  <property name="age" value="10"/>
  <property name="spouse">
    <bean class="org.springframework.beans.TestBean">
      <property name="age" value="11"/>
    </bean>
  </property>
</bean>

<!-- will result in 10, which is the value of property 'age' of bean 'testBean' -->
<bean id="testBean.age" class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>

위 설정은 'testBean'bean의 'age' 프라퍼티와 같은 값을 가지는 'testBean.age'라고 불리는 bean(int 타입의)을 생성하기 위한 Spring FactoryBean 구현물인 PropertyPathFactoryBean를 사용한다.

After...

<!-- target bean to be referenced by name -->
<bean id="testBean" class="org.springframework.beans.TestBean" scope="prototype">
  <property name="age" value="10"/>
  <property name="spouse">
    <bean class="org.springframework.beans.TestBean">
      <property name="age" value="11"/>
    </bean>
  </property>
</bean>

<!-- will result in 10, which is the value of property 'age' of bean 'testBean' -->
<util:property-path id="name" path="testBean.age"/>

<property-path/>태그의 'path' 속성값은 'beanName.beanProperty'폼을 따른다.

A.2.2.2.1. bean 프라퍼티나 생성자의 인자를 셋팅하기 위해 <util:property-path/> 사용하기

PropertyPathFactoryBean은 대상 객체의 프라퍼티 경로를 평가하는 FactoryBean이다. 대상 객체는 직접적으로나 bean이름을 통해 명시될수 있다. 이 값은 프라퍼티 값이나 생성자의 인자로 다른 bean정의내 사용될수 있다.

이것은 경로가 이름에 의해, 다른 bean에 대해 사용되는 예제이다.

// target bean to be referenced by name
<bean id="person" class="org.springframework.beans.TestBean" scope="prototype">
  <property name="age" value="10"/>
  <property name="spouse">
    <bean class="org.springframework.beans.TestBean">
      <property name="age" value="11"/>
    </bean>
  </property>
</bean>

// will result in 11, which is the value of property 'spouse.age' of bean 'person'
<bean id="theAge"
    class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
  <property name="targetBeanName" value="person"/>
  <property name="propertyPath" value="spouse.age"/>
</bean>

이 예제에서, 경로는 내부 bean에 대해 평가된다.

<!-- will result in 12, which is the value of property 'age' of the inner bean -->
<bean id="theAge"
    class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
  <property name="targetObject">
    <bean class="org.springframework.beans.TestBean">
      <property name="age" value="12"/>
    </bean>
  </property>
  <property name="propertyPath" value="age"/>
</bean>

여기엔 또한 bean이름이 프라퍼티 경로인 단축형태가 존재한다.

<!-- will result in 10, which is the value of property 'age' of bean 'person' -->
<bean id="person.age"
    class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>

이 형태는 bean의 이름으로 더이상 선택하지 않는다는 것을 의미한다. 이것에 대한 참조는 경로인 같은 id를 사용할것이다. 물론, 내부 bean처럼 사용된다면, 이것에 대해 전혀 참조할 필요가 없다.

<bean id="..." class="...">
  <property name="age">
    <bean id="person.age"
        class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>
  </property>
</bean>

결과타입은 실제 정의내 명시적으로 셋팅될것이다. 이것은 대개의 경우를 위해 필요하지 않다. 하지만 몇가지 경우에 사용될수 있다. 이 기능의 좀더 많은 정보를 위해 Javadoc를 보라.

A.2.2.3. <util:properties/>

Before...

<!-- creates a java.util.Properties instance with values loaded from the supplied location -->
<bean id="jdbcConfiguration" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
  <property name="location" value="classpath:com/foo/jdbc-production.properties"/>
</bean>

위 설정은 제공된 Resource위치로부터 로그된 값을 가지는 java.util.Properties인스턴스를 구체적으로 나타내기 위한 Spring FactoryBean구현물인 PropertiesFactoryBean을 사용한다.

After...

<!-- creates a java.util.Properties instance with values loaded from the supplied location -->
<util:properties id="jdbcConfiguration" location="classpath:com/foo/jdbc-production.properties"/>

A.2.2.4. <util:list/>

Before...

<!-- creates a java.util.List instance with values loaded from the supplied 'sourceList' -->
<bean id="emails" class="org.springframework.beans.factory.config.ListFactoryBean">
  <property name="sourceList">
      <list>
        <value>pechorin@hero.org</value>
        <value>raskolnikov@slums.org</value>
        <value>stavrogin@gov.org</value>
        <value>porfiry@gov.org</value>
      </list>
  </property>
</bean>

위 설정은 제공된 'sourceList'로부터 얻어진 값을 가지고 초기화된 java.util.List인스턴스를 생성하기 위해 Spring FactoryBean 구현물인 ListFactoryBean을 사용한다.

After...

<!-- creates a java.util.List instance with values loaded from the supplied 'sourceList' -->
<util:list id="emails">
    <value>pechorin@hero.org</value>
    <value>raskolnikov@slums.org</value>
    <value>stavrogin@gov.org</value>
    <value>porfiry@gov.org</value>
</util:list>

<util:list/> 요소의 'list-class' 속성의 사용을 통해 인스턴스화되고 활성화될 List의 정확한 타입을 명시적으로 제어할수 있다. 예를 들어, 인스턴스화되는 java.util.LinkedList가 필요하다면, 우리는 다음의 설정을 사용할수 있다.

<util:list id="emails" list-class="java.util.LinkedList">
    <value>jackshaftoe@vagabond.org</value>
    <value>eliza@thinkingmanscrumpet.org</value>
    <value>vanhoek@pirate.org</value>
    <value>d'Arcachon@nemesis.org</value>
</util:list>

'list-class' 속성이 제공되지 않는다면, List 구현물은 컨테이너에 의해 선택될것이다.

마지막으로, 당신은 <util:list/> 요소의 'merge' 속성을 사용하여 병합(merge)행위를 제어할수 있다. collection병합은 Section 3.3.3.4.1, “Collection 병합”에서 좀더 상세하게 언급된다.

A.2.2.5. <util:map/>

Before...

<!-- creates a java.util.Map instance with values loaded from the supplied 'sourceMap' -->
<bean id="emails" class="org.springframework.beans.factory.config.MapFactoryBean">
  <property name="sourceMap">
      <map>
        <entry key="pechorin" value="pechorin@hero.org"/>
        <entry key="raskolnikov" value="raskolnikov@slums.org"/>
        <entry key="stavrogin" value="stavrogin@gov.org"/>
        <entry key="porfiry" value="porfiry@gov.org"/>
      </map>
  </property>
</bean>

위 설정은 제공된 'sourceMap'로부터 얻어진 key-value쌍으로 초기화된 java.util.Map 인스턴스를 생성하기 위해 Spring FactoryBean 구현물인 MapFactoryBean을 사용한다.

After...

<!-- creates a java.util.Map instance with values loaded from the supplied 'sourceMap' -->
<util:map id="emails">
    <entry key="pechorin" value="pechorin@hero.org"/>
    <entry key="raskolnikov" value="raskolnikov@slums.org"/>
    <entry key="stavrogin" value="stavrogin@gov.org"/>
    <entry key="porfiry" value="porfiry@gov.org"/>
</util:map>

<util:map/> 요소의 'map-class' 속성의 사용을 통해 인스턴스화되고 활성화될 Map의 정확한 타입을 명시적으로 제어할수 있다. 예를 들어, 인스턴스화되는 java.util.TreeMap가 필요하다면, 다음의 설정을 사용할수 있다.

<util:map id="emails" map-class="java.util.TreeMap">
    <entry key="pechorin" value="pechorin@hero.org"/>
    <entry key="raskolnikov" value="raskolnikov@slums.org"/>
    <entry key="stavrogin" value="stavrogin@gov.org"/>
    <entry key="porfiry" value="porfiry@gov.org"/>
</util:map>

'map-class' 속성이 제공되지 않는다면, Map 구현물은 컨테이너에 의해 선택될것이다.

마지막으로, <util:map/> 요소의 'merge' 속성을 사용하여 병합행위를 제어할수 있다. collection병합은 Section 3.3.3.4.1, “Collection 병합”에서 상세히 언급된다.

A.2.2.6. <util:set/>

Before...

<!-- creates a java.util.Set instance with values loaded from the supplied 'sourceSet' -->
<bean id="emails" class="org.springframework.beans.factory.config.SetFactoryBean">
  <property name="sourceSet">
      <set>
        <value>pechorin@hero.org</value>
        <value>raskolnikov@slums.org</value>
        <value>stavrogin@gov.org</value>
        <value>porfiry@gov.org</value>
      </set>
  </property>
</bean>

위 설정은 제공된 'sourceSet'으로부터 얻어진 값으로 초기화된 java.util.Set 인스턴스를 생성하기 위해 Spring FactoryBean 구현물인 SetFactoryBean을 사용한다.

After...

<!-- creates a java.util.Set instance with values loaded from the supplied 'sourceSet' -->
<util:set id="emails">
    <value>pechorin@hero.org</value>
    <value>raskolnikov@slums.org</value>
    <value>stavrogin@gov.org</value>
    <value>porfiry@gov.org</value>
</util:set>

<util:set/> 요소의 'set-class' 속성의 사용을 통해 인스턴스화되고 활성화될 Set의 정확한 타입을 명시적으로 제어할수 있다. 예를 들어, 인스턴스화되는 java.util.TreeSet가 필요하다면, 다음의 설정을 사용할수 있다.

<util:set id="emails" set-class="java.util.TreeSet">
    <value>pechorin@hero.org</value>
    <value>raskolnikov@slums.org</value>
    <value>stavrogin@gov.org</value>
    <value>porfiry@gov.org</value>
</util:set>

'set-class' 속성이 제공되지 않는다면, Set 구현물은 컨테이너에 의해 선택될것이다.

마지막으로, <util:set/> 요소의 'merge' 속성을 사용하여 병합행위를 제어할수 있다. collection병합은 Section 3.3.3.4.1, “Collection 병합”에서 상세히 언급된다.

A.2.3. jee 스키마

jee 태그는 JNDI객체를 룩업하고 EJB참조를 정의하는 것과 같은 EE (Java Enterprise Edition)에 관련된 설정이슈를 다룬다.

jee 스키마에 태그를 사용하기 위해, Spring설정파일의 가장 상위에 다음의 서문을 둘 필요가 있다. 다음의 텍스트는 정확한 스키마를 참조해서 jee 명명공간내 태그는 사용가능하다.

<?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:jee="http://www.springframework.org/schema/jee"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">

<!-- <bean/> definitions here -->

</beans>

A.2.3.1. <jee:jndi-lookup/> (simple)

Before...

<bean id="simple" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/MyDataSource"/>
</bean>

After...

<jee:jndi-lookup id="simple" jndi-name="jdbc/MyDataSource"/>

A.2.3.2. <jee:jndi-lookup/> (하나의 JNDI환경셋팅으로)

Before...

<bean id="simple" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/MyDataSource"/>
    <property name="jndiEnvironment">
        <props>
            <prop key="foo">bar</prop>
        </props>
    </property>
</bean>

After...

<jee:jndi-lookup id="simple" jndi-name="jdbc/MyDataSource">
    <jee:environment>foo=bar</jee:environment>
</jee:jndi-lookup>

A.2.3.3. <jee:jndi-lookup/> (다중 JNDI환경셋팅으로)

Before...

<bean id="simple" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/MyDataSource"/>
    <property name="jndiEnvironment">
        <props>
            <prop key="foo">bar</prop>
            <prop key="ping">pong</prop>
        </props>
    </property>
</bean>

After...

<jee:jndi-lookup id="simple" jndi-name="jdbc/MyDataSource">
    <!-- newline-separated, key-value pairs for the environment (standard Properties format) -->
    <jee:environment>
        foo=bar
        ping=pong
    </jee:environment>
</jee:jndi-lookup>

A.2.3.4. <jee:jndi-lookup/> (complex)

Before...

<bean id="simple" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/MyDataSource"/>
    <property name="cache" value="true"/>
    <property name="resourceRef" value="true"/>
    <property name="lookupOnStartup" value="false"/>
    <property name="expectedType" value="com.myapp.DefaultFoo"/>
    <property name="proxyInterface" value="com.myapp.Foo"/>
</bean>

After...

<jee:jndi-lookup id="simple"
             jndi-name="jdbc/MyDataSource"
             cache="true"
             resource-ref="true"
             lookup-on-startup="false"
             expected-type="com.myapp.DefaultFoo"
             proxy-interface="com.myapp.Foo"/>

A.2.3.5. <jee:local-slsb/> (simple)

<jee:local-slsb/> 태그는 EJB 비상태유지 세션빈에 대한 참조를 설정한다.

Before...

<bean id="simple"
      class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean">
  <property name="jndiName" value="ejb/RentalServiceBean"/>
  <property name="businessInterface" value="com.foo.service.RentalService"/>
</bean>

After...

<jee:local-slsb id="simpleSlsb" jndi-name="ejb/RentalServiceBean"
    business-interface="com.foo.service.RentalService"/>

A.2.3.6. <jee:local-slsb/> (complex)

<bean id="complexLocalEjb"
      class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean">
  <property name="jndiName" value="ejb/RentalServiceBean"/>
  <property name="businessInterface" value="com.foo.service.RentalService"/>
  <property name="cacheHome" value="true"/>
  <property name="lookupHomeOnStartup" value="true"/>
  <property name="resourceRef" value="true"/>
</bean>

After...

<jee:local-slsb id="complexLocalEjb"
    jndi-name="ejb/RentalServiceBean"
    business-interface="com.foo.service.RentalService"
    cache-home="true"
    lookup-home-on-startup="true"
    resource-ref="true">

A.2.3.7. <jee:remote-slsb/>

<jee:remote-slsb/> 태그는 remote EJB 비상태유지 세션빈에 대한 참조를 설정한다.

Before...

<bean id="complexRemoteEjb"
      class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
  <property name="jndiName" value="ejb/MyRemoteBean"/>
  <property name="businessInterface" value="com.foo.service.RentalService"/>
  <property name="cacheHome" value="true"/>
  <property name="lookupHomeOnStartup" value="true"/>
  <property name="resourceRef" value="true"/>
  <property name="homeInterface" value="com.foo.service.RentalService"/>
  <property name="refreshHomeOnConnectFailure" value="true"/>
</bean>

After...

<jee:remote-slsb id="complexRemoteEjb"
    jndi-name="ejb/MyRemoteBean"
    business-interface="com.foo.service.RentalService"
    cache-home="true"
    lookup-home-on-startup="true"
    resource-ref="true"
    home-interface="com.foo.service.RentalService"
    refresh-home-on-connect-failure="true">

A.2.4. lang 스키마

lang태그는 Spring컨테이너내에서 bean처럼 JRuby나 Groovy와 같은 동적언어내 작성되는 노출된 객체를 다룬다.

이러한 태그(와 동적언어지원)는 Chapter 24, 동적 언어 지원에서 완벽하게 다루어진다. 이 지원과 lang 태그 자체에 대한 상세정보를 위해서는 그 장을 참조하라.

lang 스키마내 태그를 사용하기 위해, Spring XML설정파일의 가장 상위에 다음의 서문을 둘 필요가 있다. 다음의 텍스트는 정확한 스키마를 참조해서 lang 명명공간내 태그는 당신에게 사용가능하다.

<?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:lang="http://www.springframework.org/schema/lang"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd">

<!-- <bean/> definitions here -->

</beans>

A.2.5. tx (트랜잭션) 스키마

tx태그는 트랜잭션을 위한 Spring의 완벽한 지원을 위한 모든 bean의 설정을 다룬다. 이러한 태그는 Chapter 9, 트랜잭션 관리에서 상세히 다루어진다.

[Tip]Tip

Spring배포판에 포함된 'spring-tx-2.0.xsd' 파일을 보는것을 강력히 권한다. 이 파일은 Spring의 트랜잭션 설정을 위한 XML스키마이고 tx 명명공간내 다양한 모든 태그를 다룬다. 이 파일은 그때마다 문서화되었고 정보는 여기서 반복되지 않는다.

tx 스키마에서 태그를 사용하기 위해, Spring XML설정파일의 가장 위에 다음의 서문을 둘 필요가 있다. 다음의 텍스트가 정확한 스키마를 참조해서 tx 명명공간내 태그는 사용가능하다.

<?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: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/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

<!-- <bean/> definitions here -->

</beans>
[Note]Note

tx 명명공간내 태그를 사용할때 (Spring내 선언적인 트랜잭션 지원이 AOP를 사용하여 구현되었기 때문에)당신은 aop 명명공간으로부터 태그를 사용할것이다. 위 XML은 aop 스키마를 참조할 필요가 있는 관련된 줄을 포함해서 aop 명명공간내 태그는 사용가능할것이다.

A.2.6. aop 스키마

aop 태그는 Spring내 모든 AOP 설정을 다룬다. 이것은 Spring 자체의 프록시-기반 AOP프레임워크와 AspectJ AOP 프레임워크와의 통합을 포함한다. 이 태그는 Chapter 6, Spring을 이용한 Aspect 지향 프로그래밍에서 상세히 다루어진다.

aop 스키마내 태그를 사용하기 위해, 당신은 Spring XML 설정파일의 가장 위에 다음의 서문을 둘 필요가 있다. 다음의 텍스트는 정확한 스키마를 참조해서 aop 명명공간내 태그는 사용가능하다.

<?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:aop="http://www.springframework.org/schema/aop"
	   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">

<!-- <bean/> definitions here -->

</beans>

A.2.7. tool 스키마

tool 태그는 사용자정의 설정 요소에 툴성격의 메타데이타를 추가하길 원할때 사용하기 위한 것이다. 이 메타데이타는 이 메타데이타를 인식하는 툴에 의해 소비될수 있고 툴은 하고자 하는 것(유효성 체크및 기타)이 무엇이든지 잘 수행할수 있다.

tool 태그는 Spring의 이 버전에 문서화되지 않았기 때문에 현재는 리뷰를 제공한다. 당신이 이기종 툴 업체거나 이 리뷰 프로세스에 기여하고자 한다면, Spring메일링 리스트에 메일을 보내달라. 현재 지원되는 tool 태그는 Spring소스 배포판의 'src/org/springframework/beans/factory/xml' 디렉토리의 'spring-tool-2.0.xsd' 파일에서 찾을수 있다.

A.2.8. beans 스키마

마지막이지만 적어도 우리는 beans 스키마내 태그를 가진다. 프레임워크가 발달한 이후 Spring에서 bean을 가지는 같은 태그가 있다. 예를 들어 Section 3.3.3, “상세화된 bean프라퍼티와 생성자의 인자” (그리고 전체 에서는 말할것도 없이)에서 포괄적으로 다루어지기 때문에 beans 스키마내 다양한 태그는 여기서 보여지지 않는다.

Spring 2.0내 bean태그 자체에 새로운 것은 임의의 bean메타데이타에 대한 생각이다. Spring 2.0에서, <bean/> XML정의에 키/값의 쌍을 추가하지 않거나 여러개를 추가하는 것이 가능하다. 어떤것이라도 발생한다면, 이 추가적인 메타데이타는 자체적인 사용자정의 로직에 수행한다(그래서 Appendix B, 확장가능한 XML제작에 언급된 사용자정의 태그를 작성하면 사용된다).

둘러싸는 <bean/>의 문구내 <meta/> 태그의 예제를 아래에서 보라.

<?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.0.xsd">

    <bean id="foo" class="x.y.Foo">
        <meta key="cacheName" value="foo"/>
        <property name="name" value="Rick"/>
    </bean>

</beans>

위 예제의 경우, bean정의를 소비할 몇가지 로직과 제공된 메타데이타를 사용하여 몇가지 캐싱 내부구조를 셋텅한다고 가정할것이다.

A.3. 당신의 IDE 셋업하기

이 마지막 부분은 Spring의 XML 스키마-기반의 설정파일의 편집을 좀더 쉽게 하도록 해주는 많은 수의 Java IDE를 셋업하는 단계를 보여준다. 만일 당신이 선호하는 Java IDE 나 편집기가 다음의 문서화된 부분에 포함되지 않았다면, Spring 프레임워크 JIRA 이슈 관리시스템에 이슈화하고 다음 릴리즈에 기능화될 예제를 달라.

A.3.1. eclipse 셋업하기

다음 단계는 XSD 를 인식하도록 Eclipse 를 셋업하는 것을 보여준다. 다음 단계는 당신이 이미 eclipse 프로젝트를 열었다고 가정한다.

[Note]Note

다음 단계는 eclipse 3.2를 사용하여 만들었다. 셋업방법은 아마 이전버전과 차후버전에도 같거나 유사할것이다.

  1. 1 단계

    새 XML파일을 생성한다. 당신이 원하는 파일명을 지정한다. 아래의 예제에서는, 파일명이 'context.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"
           xmlns:util="http://www.springframework.org/schema/util"
           xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
    
    </beans>

  2. 2 단계

    위 화면에서 본것처럼(어떤 플러그인으로 설치한 사용자정의된 eclipse를 사용하지 않는한) XML파일은 일반 텍스트로 처리될것이다. eclipse에는 특별한 XML편집 지원이 없다. 그래서 요소나 속성의 문법적인 하이라이트가 없다. 이것을 할당하기 위해, 당신은 eclipse를 위한 XML편집기를 설치해야할것이다.

    Table A.1. eclipse XML 편집기

    XML EditorLink

    Eclipse Web Tools Platform (WTP)

    http://www.eclipse.org/webtools/

    eclipse XML플러그인 목록

    http://eclipse-plugins.2y.net/eclipse/plugins.jsp?category=XML

    불행히도, eclipse를 위한 표준적인 XML편집기가 없기 때문에, eclipse내 XML 스키마 지원을 설정하는 방법을 보여줄 그 이상의 단계를 없다. 각각의 XML 편집기는 전용으로 할당된 부분에서 요구될것이고 이것은 eclipse XML편집기 문서가 아닌 Spring 참조문서이다. 당신은 XML편집기 플러그인을 사용한 문서를 읽을것이고 자체적으로 설정할것이다.

  3. 3 단계

    eclipse 를 위한 WTP(Web Tools Platform)를 사용한다면, WTP 플랫폼의 XML편집기를 사용하여 Spring XML설정파일을 열수 있다. 아래의 화면에서 보듯이, 당신은 태그를 자동완성하기 위한 IDE레벨의 지원을 얻게 된다. “[WTP] rocks!

A.3.2. IntelliJ IDEA 셋업하기

다음 단계는 XSD를 인식하도록 IntelliJ IDEA를 셋업하는 방법을 보여준다. 그 방법은 매우 간단하다.

다음 단계는 당신이 이미 IDEA 프로젝트를 열었다고 가정한다.

다른 Spring XSD파일을 참조하는 IDEA를 셋업하기 위해 반복하라.

  1. 1 단계

    새로운 XML파일을 생성한다. 당신이 원하는 파일명을 사용할수 있다. 아래의 예제에서, 파일명은 'context.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"
           xmlns:util="http://www.springframework.org/schema/util"
           xsi:schemaLocation="
           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
    
    </beans>

  2. 2 단계

    위 화면에서 본것처럼, XML파일은 많은 수의 빨간색의 에러 표시자를 가진다. 이것을 고치기 위해, IDEA는 참조된 XSD명명공간의 위치를 인식해야만 한다.

    이것을 하기 위해, (아래의 화면에서 보듯이)빨간색 영역으로 커서를 옮기고 Alt-Enter 기 조합을 누른다. 그리고 나서 팝업이 외부자권을 가져오기 위해 활성화될때 Enter 키를 다시 누른다.

  3. 3 단계

    만약 외부 자원을 가져올수 없다면(아마도 실질적인 인터넷 연결이 사용가능하지 않을때), 관련 XSD파일의 로컬 복사본을 참조하도록 자원을 수동으로 설정할수 있다. 간단히 'Settings' 다이얼로그를 열고(Ctrl-A-S 키조합을 사용하거나 'File|Settings' 메뉴를 통해) 'Resources' 버튼을 클릭한다.

  4. 4 단계

    다음 화면에서 볼수 있는것처럼, 이것은 util 스키마 파일의 로컬 복사본을 명시적으로 참조하도록 추가하는 것을 허용하는 다이얼로그를 가져올것이다(당신은 Spring배포판의 'src' 디렉토리의 다양한 Spring XSD파일을 찾을수 있을것이다.).

  5. 5 단계

    'Add' 버튼을 클릭하는 것은 관련 XSD파일을 위한 경로를 가진 명명공간 URI 관련시키도록 하는 다른 다이얼로그를 가져올것이다. 다음 화면에서 볼수 있듯이, 'http://www.springframework.org/schema/util' 명명공간은 'C:\bench\spring\src\org\springframework\beans\factory\xml\spring-util-2.0.xsd' 파일 자원과 관련된다.

  6. 6 단계

    'OK' 버튼을 클릭하여 내포된 다이얼로그를 빠져나가는 것은 메인 편집창으로 돌아갈것이다. 다음 화면에서 볼수 있듯이, 문법적 에러 표시자는 사라진다. 지금 편집창에서 '<' 문자를 타이핑하면 util 명명공간으로 부터 가져온 태그를 모두 포함하는 드랍다운 형태의 박스를 보게될것이다.

A.3.3. 통합 이슈

이 마지막 부분은 Spring 2.0설정을 위해 XSD스타일을 사용하는 것으로 교체할때 발생할수 있는 통합 이슈를 언급한다.

이 부분은 지금 시점에서는 매우 작다. 이것은 Spring사용자에게 편리하도록 Spring문서에 포함된다. 그래서 몇가지 환경에서 XSD스타일로 교체할때 이슈가 발생한다면, 그에 대한 방법을 보기 위해 이 부분을 참조할수 있다.

A.3.3.1. Resin v.3 애플리케이션 서버의 XML파일 에러

Spring 2.0 XML설정을 위해 XSD스타일을 사용하고 Caucho의 Resin애플리케이션서버의 v.3에 배치한다면, 애플리케이션 서버 시작시 XSD을 인식하는 파서가 Spring에서 사용가능하도록 셋팅할 필요가 있을것이다.

좀더 많은 정보를 위해 Caucho Resin웹사이트의 다음 자원을 참조하라.

http://www.caucho.com/resin-3.0/xml/jaxp.xtp#xerces