POM版本不兼容整合spring-batch-admin

时间:2014-01-20 07:41:32

标签: spring maven spring-batch spring-batch-admin

我已按照Integrating Spring Batch Admin into an existing application中的答案将spring-batch-admin整合到我的应用程序中。

问题1

首先,我收到了与slf4j相关的以下错误:

java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.info(SLF4JLocationAwareLog.java:159)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:273)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
...
...

我通过排除slf4j依赖关系来解决这个错误(阅读:错误已停止,但我不知道这是否是解决问题的正确方法):

<dependency>
  <groupId>org.springframework.batch</groupId>
  <artifactId>spring-batch-admin-manager</artifactId>
  <version>1.2.2.RELEASE</version>
  <exclusions>
    <exclusion>
      <groupId>org.slf4j</groupId>
      <artifactId>jcl-over-slf4j</artifactId>
    </exclusion>
    <exclusion>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </exclusion>
    <exclusion>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
    </exclusion>
  </exclusions>
</dependency>

问题2

在问题1的上述解决方法之后,出现以下错误:

java.lang.IncompatibleClassChangeError: class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:788)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
...
...

根据Class Conflict when starting up Java project: ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class,这是由使用多个弹簧库版本引起的。

问题

  1. 问题1的解决方案是否正确?我可以在依赖项的POM中排除依赖项并期望事情正常工作(通过使用我的项目正在使用的slf4j版本)吗?
  2. 问题2可以用同样的方法解决吗?我的应用程序没有使用spring-batch-admin所需的所有依赖项,所以我应该排除错误的版本并包含正确的版本吗?
  3. 这似乎是为了让事情发挥作用的大量黑客行为。有没有“更好的方式”?
  4. 更新

    主要的pom文件。为简洁起见,已删除了一些信息。我还删除了私人信息:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>hidden.from.you</groupId>
      <artifactId>my-project</artifactId>
      <version>0.1.4-SNAPSHOT</version>
      <packaging>pom</packaging>
      <name>My Project</name>
      <modules>
        <!-- Modules listed here. About 20 in total. -->
      </modules>
      <properties>
        <slf4j.version>1.7.5</slf4j.version>
        <spring.version>3.2.4.RELEASE</spring.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
      <profiles>
        <!-- Profiles here. -->
      </profiles>
      <dependencies>
        <!-- Logging -->
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-log4j12</artifactId>
        </dependency>
        <!-- Spring -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-core</artifactId>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-beans</artifactId>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context-support</artifactId>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
          <groupId>cglib</groupId>
          <artifactId>cglib</artifactId>
        </dependency>
        <dependency>
          <groupId>org.springframework.batch</groupId>
          <artifactId>spring-batch-core</artifactId>
        </dependency>
        <!-- Testing -->
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-test</artifactId>
          <scope>test</scope>
        </dependency>
        <!-- Lombok -->
        <dependency>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
        </dependency>
        <!-- Caching -->
        <dependency>
          <groupId>net.sf.ehcache</groupId>
          <artifactId>ehcache</artifactId>
          <version>2.7.4</version>
        </dependency>
      </dependencies>
      <dependencyManagement>
        <dependencies>
          <!-- Logging -->
          <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
          </dependency>
          <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
          </dependency>
          <!-- Spring -->
          <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
          </dependency>
          <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
          </dependency>
          <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
          </dependency>
          <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
          </dependency>
          <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
          </dependency>
          <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
          </dependency>
          <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
          </dependency>
          <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
            <scope>test</scope>
          </dependency>
          <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2.2</version>
          </dependency>
          <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-core</artifactId>
            <version>2.2.4.RELEASE</version>
          </dependency>
          <!-- Testing -->
          <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
          </dependency>
          <!-- Lombok -->
          <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>0.12.0</version>
          </dependency>
          <!-- HTTP Client -->
          <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.1.2</version>
          </dependency>
        </dependencies>
      </dependencyManagement>
      <build>
        <resources>
          <resource>
            <filtering>true</filtering>
            <directory>src/main/resources</directory>
          </resource>
        </resources>
        <testResources>
          <testResource>
            <filtering>true</filtering>
            <directory>src/test/resources</directory>
          </testResource>
        </testResources>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.4.2</version>
          </plugin>
          <plugin>
            <inherited>true</inherited>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
              <source>1.7</source>
              <target>1.7</target>
              <optimize>true</optimize>
              <debug>true</debug>
              <showDeprecation>true</showDeprecation>
              <showWarnings>true</showWarnings>
            </configuration>
          </plugin>
          <plugin>
            <inherited>true</inherited>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.9</version>
            <configuration>
              <downloadSources>true</downloadSources>
            </configuration>
          </plugin>
          <plugin>
            <inherited>true</inherited>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
            <configuration>
              <encoding>UTF-8</encoding>
            </configuration>
          </plugin>
          <plugin>
            <inherited>false</inherited>
            <groupId>com.mycila.maven-license-plugin</groupId>
            <artifactId>maven-license-plugin</artifactId>
            <version>1.10.b1</version>
            <configuration>
              <header>license-header.txt</header>
              <aggregate>true</aggregate>
              <properties>
                <year>2014</year>
                <holder>Secret</holder>
                <email>private@notimportantnow.com</email>
              </properties>
              <strictCheck>true</strictCheck>
              <useDefaultExcludes>true</useDefaultExcludes>
              <excludes>
                <exclude>**/*.cgi</exclude>
                <exclude>**/*.css</exclude>
                <exclude>**/*.doc</exclude>
                <exclude>**/*.dot</exclude>
                <exclude>**/*.html</exclude>
                <exclude>**/*.js</exclude>
                <exclude>**/*.log</exclude>
                <exclude>**/*.mcr</exclude>
                <exclude>**/*.odt</exclude>
                <exclude>**/*.pdb</exclude>
                <exclude>**/*.pdf</exclude>
                <exclude>**/*.pom</exclude>
                <exclude>**/*.properties</exclude>
                <exclude>**/*.txt</exclude>
                <exclude>**/*.xml</exclude>
              </excludes>
            </configuration>
            <executions>
              <execution>
                <goals>
                  <goal>check</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.16</version>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.16</version>
            <executions>
              <execution>
                <id>failsafe-integration-tests</id>
                <phase>integration-test</phase>
                <goals>
                  <goal>integration-test</goal>
                </goals>
              </execution>
              <execution>
                <id>failsafe-verify</id>
                <phase>verify</phase>
                <goals>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
            <version>3.3</version>
            <executions>
              <execution>
                <id>attach-descriptor</id>
                <goals>
                  <goal>attach-descriptor</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <reportPlugins>
                <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-project-info-reports-plugin</artifactId>
                  <version>2.7</version>
                  <configuration>
                    <dependencyDetailsEnabled>false</dependencyDetailsEnabled>
                    <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
                  </configuration>
                </plugin>
                <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-pmd-plugin</artifactId>
                  <version>3.0.1</version>
                  <configuration>
                    <targetJdk>1.7</targetJdk>
                    <ignoreAnnotations>false</ignoreAnnotations>
                    <excludeRoots>
                      <excludeRoot>
                        target/generated-sources/groovy-stubs/main
                      </excludeRoot>
                    </excludeRoots>
                  </configuration>
                </plugin>
                <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-checkstyle-plugin</artifactId>
                  <version>2.10</version>
                  <configuration>
                    <configLocation>checkstyle.xml</configLocation>
                  </configuration>
                </plugin>
                <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-javadoc-plugin</artifactId>
                  <version>2.9.1</version>
                </plugin>
                <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-jxr-plugin</artifactId>
                  <version>2.3</version>
                  <configuration>
                    <includes>
                      <include>**/*.java</include>
                      <include>**/*.groovy</include>
                    </includes>
                  </configuration>
                </plugin>
                <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-surefire-report-plugin</artifactId>
                  <version>2.16</version>
                  <configuration>
                    <aggregate>true</aggregate>
                    <linkXRef>true</linkXRef>
                  </configuration>
                </plugin>
                <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>cobertura-maven-plugin</artifactId>
                  <version>2.6</version>
                  <configuration>
                    <aggregate>true</aggregate>
                  </configuration>
                </plugin>
                <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>taglist-maven-plugin</artifactId>
                  <version>2.4</version>
                  <configuration>
                    <aggregate>true</aggregate>
                    <tagListOptions>
                      <tagClasses>
                        <tagClass>
                          <displayName>Tasks</displayName>
                          <tags>
                            <tag>
                              <matchString>TODO</matchString>
                              <matchType>exact</matchType>
                            </tag>
                            <tag>
                              <matchString>FIXME</matchString>
                              <matchType>exact</matchType>
                            </tag>
                          </tags>
                        </tagClass>
                      </tagClasses>
                    </tagListOptions>
                  </configuration>
                </plugin>
              </reportPlugins>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </project>
    

1 个答案:

答案 0 :(得分:0)

如果您看一下依赖性hirarchie,您会看到slf4j来自spring-batch-integration,ehcache-core和spring-batch-admin-resources。换句话说,这意味着你所做的排除不起作用。

enter image description here