복붙노트

[SPRING] Spring DI applicationContext.xml xsi : schemaLocation은 정확히 어떻게 사용됩니까?

SPRING

Spring DI applicationContext.xml xsi : schemaLocation은 정확히 어떻게 사용됩니까?

참고 : 제가 언급 한 테스트 프로젝트는 다음과 같이 다운로드 할 수 있습니다 :

git clone https://github.com/mperdikeas/so-spring-di-appcontext-schemalocation.git

.. 'ant run'으로 실행하십시오.

나는 XML 네임 스페이스 이름이 단지 불투명 식별자로 사용되며 URI (위키 피 디아)로 사용되지 않는다는 것을 이해한다. 또한 XML 스키마 위치는 스키마 문서의 실제 위치에 대한 힌트를 제공하고 실제로 사용되지 않는 힌트입니다 (w3.org). 이를 염두에두고 applicationContext.xml을 수정하여 간단한 J2EE 환경에서 사용되는 간단한 DI DI 애플리케이션을 실험 해왔다. 다음은 시작 버전입니다.

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

<context:component-scan base-package="atm"/>                                                                       
<context:property-placeholder location="classpath:META-INF/spring/atm.properties"/>                                

<bean id="soapTransport_" class="atm.SoapATMTransport" p:retries="${transport.retries}"/>                          

내가 'sudo ifconfig eth0 down'을했을 때 프로젝트는 완벽하게 실행되었고 이는 런타임과 일치하여 schemaLocations에서 아무 것도 가져 오지 않아도됩니다. 그러나 각 쌍의 두 번째 URL에 간단한 밑줄을 추가하여 schemaLocations를 변형 시켰을 때 다음과 같은 불만 사항이있었습니다.

 [java] org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 10 in XML document from class path resource [META-INF/spring/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 10; columnNumber: 100; cvc-elt.1: Cannot find the declaration of element 'beans'.
 [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:194)
 [java]     at org.apache.tools.ant.taskdefs.Java.run(Java.java:771)
 [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:221)
 [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:135)
 [java]     at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
 [java]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
 [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 [java]     at java.lang.reflect.Method.invoke(Method.java:601)
 [java]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
 [java]     at org.apache.tools.ant.Task.perform(Task.java:348)
 [java]     at org.apache.tools.ant.Target.execute(Target.java:390)
 [java]     at org.apache.tools.ant.Target.performTasks(Target.java:411)
 [java]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
 [java]     at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
 [java]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
 [java]     at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
 [java]     at org.apache.tools.ant.Main.runBuild(Main.java:809)
 [java]     at org.apache.tools.ant.Main.startAnt(Main.java:217)
 [java]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
 [java]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

이것은 스프링 DI 런타임이 xsi : schemaLocation에서 각 쌍의 두 번째 URL을 일종의 식별자 (네트워크 액세스가 없기 때문에 논리에 하드 코딩 됨)로 사용한다는 것을 보여줍니다. 따라서 스프링 DI 런타임은 각 네임 스페이스에 대해 두 종류의 식별자, 즉 네임 스페이스 (불투명 한 문자열로 사용됨)를 고유하게 식별하는 xmlns 식별자와 해당 네임 스페이스에 대한 스키마 버전을 고유하게 식별하는 schemaLocation 식별자를 사용한다고 가정합니다 불투명 한 문자열). 나. schemaLocation은 네임 스페이스를 버전 화하기 위해 실제로 (w3c 문서의 의도처럼 보이지 않으므로 변형 된 방식으로) 사용됩니다. 게다가, 이런 경우, 왜 Spring DI 런타임은 "p"네임 스페이스에 대한 schemaLocation의 부족에 대해 불평하지 않습니다. 내 정신 모델이 맞습니까?

해결법

  1. ==============================

    1.다음과 같은 일이 발생합니다.

    다음과 같은 일이 발생합니다.

    프로젝트 라이브러리를 검색하면 spring.schemas라는 파일이 여러 개 있습니다. 이 파일들은 아래와 비슷한 줄을 포함하고 있습니다 (spring-context.jar에있는 파일에서 추출한 것, 정렬을 추가했습니다) :

    http\://www.springframework.org/schema/context/spring-context.xsd= org/springframework/context/config/spring-context-3.1.xsd
    http\://www.springframework.org/schema/jee/spring-jee.xsd=         org/springframework/ejb/config/spring-jee-3.1.xsd
    http\://www.springframework.org/schema/lang/spring-lang.xsd=       org/springframework/scripting/config/spring-lang-3.1.xsd
    http\://www.springframework.org/schema/cache/spring-cache.xsd=     org/springframework/cache/config/spring-cache-3.1.xsd
    
  2. from https://stackoverflow.com/questions/10768873/spring-di-applicationcontext-xml-how-exactly-is-xsischemalocation-used by cc-by-sa and MIT license