복붙노트

[SPRING] Spring jandlers / spring.schemas가 하나의 항아리에 여러 개의 스프링 종속성을 병합 할 때 덮어 쓰지 않도록하는 아이디어

SPRING

Spring jandlers / spring.schemas가 하나의 항아리에 여러 개의 스프링 종속성을 병합 할 때 덮어 쓰지 않도록하는 아이디어

컨텍스트를 사용할 때 NamespaceHandler를 찾을 수 없습니다. annotation-config를 실행하면 (java -jar) maven-assembly-plugin으로 어셈블 된 Jar 파일과 프로젝트 및 모든 종속성을 포함합니다.

다른 사람들이 forum.springsource.org 스레드 (메시지 # 7/8)에서 올바르게 발견 했으므로 다른 jar에있는 META-INF / spring.handlers 및 META-INF / spring.schemas 파일이 덮어 쓰기 때문에 문제가 발생합니다 maven-assembly-plugin이 jar 파일을 하나의 파일로 재 패키징 할 때.

두 개의 spring - *. jar 파일의 내용을 보면 파일이 클래스 경로와 상대적으로 같은 위치에 있음을 알 수 있습니다

$ jar tf spring-oxm-3.0.3.RELEASE.jar
META-INF/spring.handlers
META-INF/spring.schemas
org/springframework/oxm/GenericMarshaller.class
...

$ jar tf spring-context-3.0.3.RELEASE.jar
META-INF/spring.handlers
META-INF/spring.schemas
org/springframework/context/ApplicationContext.class

특정 패키지에 META-INF 폴더를 넣을 수 있습니까? 그래서 내가 제안 할 생각이라면, META-INF / spring.shemas와 META-INF / spring.handlers 파일을 참조하는 패키지 밑에 넣는 것이 좋다.

$ jar tf spring-oxm-3.0.3.RELEASE.jar
org/springframework/oxm/META-INF/spring.schemas
org/springframework/oxm/META-INF/spring.handlers
org/springframework/oxm/GenericMarshaller.class
...

$ jar tf spring-context-3.0.3.RELEASE.jar
org/springframework/context/META-INF/spring.handlers
org/springframework/context/META-INF/spring.schemas
org/springframework/context/ApplicationContext.class

이 방법은 단일 항아리에 병합 할 때 충돌하지 않습니다. 당신이 그것에 대해 어떻게 생각하십니까?

해결법

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

    1.나는 (버기) 어셈블러 플러그인 대신 쉐이더 플러그인을 사용하여 버그를 없앴습니다.

    나는 (버기) 어셈블러 플러그인 대신 쉐이더 플러그인을 사용하여 버그를 없앴습니다.

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>at.seresunit.lecturemanager_connector.App</mainClass>
                                </transformer>
                                <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>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    

    나는 스프링 소스 포럼에서 해결책을 찾았다 고 생각한다. 내가 그것을 보았던 이래로 꽤 오랜 시간이 걸렸다. 저자를 정말로 기억할 수 없다. 어쨌든 그에게 명성 : p

    건배

  2. ==============================

    2.개미와.

    개미와.

    <!--define couple of properties to identify spring jar files-->
    <property name="spring-beans-jar" value="spring-beans-4.0.5.RELEASE.jar"/>
    <property name="spring-context-jar" value="spring-context-4.0.5.RELEASE.jar"/>
    
    <!--other properties-->
    
    
    <target name="dist" depends="compile" description="Prepare distribution">
        <!--dump spring-context into build classes (or some place else)-->
        <unjar src="${lib.dir}/${spring-context-jar}" dest="${build.classes.dir}"/>
    
        <!--dump spring-beans on top of it overwriting META-INF/spring.* files-->
        <unjar src="${lib.dir}/${spring-beans-jar}" dest="${build.classes.dir}"/>
    
        <!--get overwritten META-INF/spring.* files of spring-context to some other place-->
        <unjar src="${lib.dir}/${spring-context-jar}" dest="${build.tmp.dir}">
            <patternset>
                <include name="META-INF/spring.handlers"/>
                <include name="META-INF/spring.schemas"/>
                <include name="META-INF/spring.tooling"/>
            </patternset>
        </unjar>
    
        <!--skipped spring-beans/META-INF/spring.factories as its not present in spring-context-->
        <!--handled only spring-context and spring-beans as that's what I needed at this point-->
    
        <!--append content from spring-context/META-INF/spring.* files-->
        <concat destfile="${build.classes.dir}/META-INF/spring.handlers" append="true">
            <filelist dir="${build.tmp.dir}" files="META-INF/spring.handlers"/>
        </concat>
        <concat destfile="${build.classes.dir}/META-INF/spring.schemas" append="true">
            <filelist dir="${build.tmp.dir}" files="META-INF/spring.schemas"/>
        </concat>
        <concat destfile="${build.classes.dir}/META-INF/spring.tooling" append="true">
            <filelist dir="${build.tmp.dir}" files="META-INF/spring.tooling"/>
        </concat>
    
        <jar destfile="${build.dist.dir}/application.jar">
            <fileset dir="${build.classes.dir}"/>
    
            <!--include all .jar files except already extracted ones-->
            <zipgroupfileset dir="${lib.dir}" includes="*.jar"
                             excludes="${spring-beans-jar}, ${spring-context-jar}"/>
            <manifest>
                <attribute name="Main-Class" value="${main-class}"/>
            </manifest>
        </jar>
    </target>
    
  3. from https://stackoverflow.com/questions/5586515/idea-to-avoid-that-spring-handlers-spring-schemas-get-overwritten-when-merging-m by cc-by-sa and MIT license