2013년 8월 5일 월요일

Unable to locate Spring NamespaceHandler for XML schema namespace

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
Offending resource: class path resource [launch-context.xml]

이런 에러가 뜨면서 내가 만든 배치 잡이 실행되지 않는다.
maven을 통해서 라이브러리를 함께 넣어서 jar 파일을 만들었다.
내가 찾은 해결책은 맨 아래를 참조 바람.


http://rgordon.co.uk/blog/2012/01/20/getting-started-with-spring-batch/
위의 블로그에서는 이클립스 플러그인 m2e에서 dependency copy가 되지 않아서 명령어로 직접 lib를 넣은 것이다.

http://stackoverflow.com/questions/17099438/unable-to-locate-namespacehandler-for-namespace-http-www-springframework-org
여기에서는 spring-context라이브러리와 xsd 경로를 통일시키라고 하는데... 통일시켜도 동작하지 않는다.
=> 주요 해결책은 이것인것 같다. 거의 모든 구글 결과가 이 내용이다. 클래스패스에 라이브러리가 있는지 확인하고 해당 버전과 호환되는 버전을 써야 한다는 내용들이었다.

http://mojo.codehaus.org/exec-maven-plugin/exec-mojo.html
스프링 배치 샘플 프로젝트를 만들면 pom파일에 exec-maven-plugin이 있다. 이 플러그인을 통해서 mvn 명령어로 jar 파일을 실행 시킬 수 있다. 샘플 프로젝트의 폼 파일을 보면 아래와 같이 되어 있다.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<mainClass>org.springframework.batch.core.launch.support.CommandLineJobRunner</mainClass>
<arguments>
<!-- job configuration file -->
<argument>classpath:/launch-context.xml</argument>
<!-- job name -->
<argument>job1</argument>
</arguments>
</configuration>
</plugin>
launch-context.xml 파일에서 job1을 실행시키는 설정이 되어 있다.
이클립스에서 gaol에 exec:exec를 입력하고 실행시키면 된다.

참조:http://www.dashaun.com/2010/03/10/springframework-applicationcontext-woes-unable-to-locate-spring-namespacehandler/
http://stackoverflow.com/questions/15013651/using-maven-execexec-with-arguments
http://www.lucasward.net/2010/07/spring-batch-deployment-example.html

나에게 맞았던 해결책
출처: http://stackoverflow.com/questions/3335203/yet-another-unable-to-locate-spring-namespacehandler-error
Shade 플러그인을 쓰니까 해결이 되었다. - 아직 transformers 항목은 이해하지 못했다.
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.0</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
              <resource>META-INF/spring.handlers</resource>
            </transformer>
            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
              <resource>META-INF/spring.schemas</resource>
            </transformer>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
              <mainClass>org.XYZ</mainClass>
            </transformer>
          </transformers>
        </configuration>
      </execution>
    </executions>
  </plugin>

댓글 없음:

댓글 쓰기