Spring+HibernateEntityManager(XMLからの外部リソース参照編)
SpringFramework や Hibernate の定義ファイルには、スキーマの定義等、外部の URL を参照すると思しき箇所があります。本番環境では、外部への HTTP 接続が不可能な場合や、ネットワーク障害で外部にアクセスできなくなったりする可能性がありますので、それがシステムに影響するのは避けたいところです。
そのため、SpringFramework や Hibernate では、独自の EntityResolver 実装により、HTTPによる外部へのアクセスを避けて、クラスパスリソース等を参照する仕組みを提供しています。
通常は、あまり意識する必要はありませんが、カスタムのスキーマを追加する場合などは、クラスパス上の xsd ファイルを参照するようにしたいところです。
Spring Framework の場合
参考:B.5.2. 'META-INF/spring.schemas'
http://static.springframework.org/spring/docs/2.5.x/reference/extensible-xml.html
PluggableSchemaResolverにて、META-INF/spring.schemas 中で指定された xsd ファイルについてはクラスパスを参照するようになっています。
META-INF/spring.schemas は、URL とクラスパスリソースのマッピングを指定するようになっていて、イコールの左側が URL で、右側がその URL に対応するクラスパスリソースの指定になっています。
http\://www.springframework.org/schema/aop/spring-aop-2.0.xsd=org/springframework/aop/config/spring-aop-2.0.xsd http\://www.springframework.org/schema/aop/spring-aop-2.5.xsd=org/springframework/aop/config/spring-aop-2.5.xsd http\://www.springframework.org/schema/aop/spring-aop.xsd=org/springframework/aop/config/spring-aop-2.5.xsd http\://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd http\://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd http\://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd http\://www.springframework.org/schema/context/spring-context-2.5.xsd=org/springframework/context/config/spring-context-2.5.xsd http\://www.springframework.org/schema/context/spring-context.xsd=org/springframework/context/config/spring-context-2.5.xsd http\://www.springframework.org/schema/jee/spring-jee-2.0.xsd=org/springframework/ejb/config/spring-jee-2.0.xsd http\://www.springframework.org/schema/jee/spring-jee-2.5.xsd=org/springframework/ejb/config/spring-jee-2.5.xsd http\://www.springframework.org/schema/jee/spring-jee.xsd=org/springframework/ejb/config/spring-jee-2.5.xsd http\://www.springframework.org/schema/jms/spring-jms-2.5.xsd=org/springframework/jms/config/spring-jms-2.5.xsd http\://www.springframework.org/schema/jms/spring-jms.xsd=org/springframework/jms/config/spring-jms-2.5.xsd http\://www.springframework.org/schema/lang/spring-lang-2.0.xsd=org/springframework/scripting/config/spring-lang-2.0.xsd http\://www.springframework.org/schema/lang/spring-lang-2.5.xsd=org/springframework/scripting/config/spring-lang-2.5.xsd http\://www.springframework.org/schema/lang/spring-lang.xsd=org/springframework/scripting/config/spring-lang-2.5.xsd http\://www.springframework.org/schema/tx/spring-tx-2.0.xsd=org/springframework/transaction/config/spring-tx-2.0.xsd http\://www.springframework.org/schema/tx/spring-tx-2.5.xsd=org/springframework/transaction/config/spring-tx-2.5.xsd http\://www.springframework.org/schema/tx/spring-tx.xsd=org/springframework/transaction/config/spring-tx-2.5.xsd http\://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd http\://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd http\://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd http\://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd http\://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd http\://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd
独自に xsd 設定したい場合は、独自に、META-INF/spring.schemas を作成すれば OK です。配置は、SpringFramework の jar ファイルを上書きするような必要はなく、自前のクラスと同じクラスパス上の META-INF/spring.schemas として配置すれば OK です。
Hibernateの場合
参考:http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#mapping-declaration-entity-resolution
- hibernate ネームスペース
- systemId が http://hibernate.sourceforge.net/ で始まるものは、クラスパスリソースを参照します。
- 例:systemId が http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd ならば、org/hibernate/hibernate-mapping-3.0.dtd を参照します。
- ユーザーネームスペース
- systemId が、classpath:// で始まるものは、クラスパスリソースを参照します。
links
第1回 Spring+HibernateEntityManager(HibernateEntityManager単体編)
第2回 Spring+HibernateEntityManager(とりあえずSpring編)
第3回 Spring+HibernateEntityManager(宣言的トランザクション編)
第4回 Spring+HibernateEntityManager(Spring+DDDっぽく編)
第5回 Spring+HibernateEntityManager(Spring+DDDっぽく編 その2)
第6回 Spring+HibernateEntityManager(Spring+DDDっぽく編 その3)
第7回 Spring+HibernateEntityManager(Spring+DDDっぽく編 その4)
第8回 Spring+HibernateEntityManager(@Transactionalアノテーション編)
第9回 Spring+HibernateEntityManager(@Required編)
第10回 Spring+HibernateEntityManager(XMLからの外部リソース参照編)
第11回 Spring+HibernateEntityManager(AspectJ AOP with Load-Time-Weaver編)
第12回 Spring+HibernateEntityManager(DBCPのvalidationQuery編)
第13回 Spring+HibernateEntityManager(@Resource編)
第14回 Spring+HibernateEntityManager(コンポーネント自動検出 with アノテーション編)
第15回 Spring+HibernateEntityManager(コンポーネント自動検出 without アノテーション編)