1

我正在尝试将我的 spring 项目添加到 jasper 依赖项,但在下面出现此错误
我已经尝试过使用不同版本的 jasper 和 log4j,但我无法让它工作:
我使用最新版本的 spring 和 oracle weblogic 11g。
这只发生在我添加 jasper 依赖项时。
有人有同样的问题吗?

 <1/Mai/2012 16H10m BST> <Warning> <HTTP> <BEA-101162> <User defined listener org.springframework.web.context.ContextLoaderListener failed: java.lang.ExceptionInInitializerError.
java.lang.ExceptionInInitializerError
    at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:73)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)
    at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
    at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:272)
    Truncated. see log file for complete stacktrace
Caused By: java.lang.ClassCastException: weblogic.xml.jaxp.RegistryDocumentBuilderFactory cannot be cast to javax.xml.parsers.DocumentBuilderFactory
    at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
    at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:849)
    at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:773)
    at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:483)
    at org.apache.log4j.LogManager.<clinit>(LogManager.java:127)
    Truncated. see log file for complete stacktrace
> 


<1/Mai/2012 16H10m BST> <Warning> <HTTP> <BEA-101162> <User defined listener org.springframework.web.context.ContextLoaderListener failed: java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.LogManager.
java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.LogManager
    at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:73)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)
    at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
    at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:272)
    Truncated. see log file for complete stacktrace
> 

这是我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>com.company</groupId>
  <artifactId>myproject</artifactId>
  <name>myProject</name>
  <packaging>war</packaging>
  <version>1.0.0-BUILD-SNAPSHOT</version>
  <properties>
    <java-version>1.6</java-version>
    <org.springframework-version>3.1.0.RELEASE</org.springframework-version>
    <org.aspectj-version>1.6.9</org.aspectj-version>
    <org.slf4j-version>1.6.1</org.slf4j-version>
    <jackson.version>1.9.3</jackson.version>
    <validation-api-version>1.0.0.GA</validation-api-version>
    <hibernate-validator-version>4.2.0.Final</hibernate-validator-version>
    <jasper.version>4.5.0</jasper.version>
    <commons.digester.version>2.1</commons.digester.version>
    <commons.collections.version>3.2.1</commons.collections.version>
  </properties>
  <dependencies>

    <!-- Spring -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>${org.springframework-version}</version>
      <exclusions>
        <!-- Exclude Commons Logging in favor of SLF4j -->
        <exclusion>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${org.springframework-version}</version>
    </dependency>

    <!-- mysql -->
    <dependency>
      <groupId>com.mysql</groupId>
      <artifactId>mysqljdbc6</artifactId>
      <version>3.1.10</version>
    </dependency>

    <!-- Spring Data JPA -->
    <dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-jpa</artifactId>
      <version>1.0.3.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${org.springframework-version}</version>
      <type>jar</type>
      <scope>compile</scope>
    </dependency>

    <!-- validation -->
    <dependency>
      <groupId>javax.validation</groupId>
      <artifactId>validation-api</artifactId>
      <version>${validation-api-version}</version>
      <type>jar</type>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-validator</artifactId>
      <version>${hibernate-validator-version}</version>
      <type>jar</type>
      <scope>compile</scope>
    </dependency>

    <!-- Data Mapper package is a high-performance data binding package built on Jackson JSON processor -->
    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-mapper-asl</artifactId>
      <version>${jackson.version}</version>
      <type>jar</type>
      <scope>compile</scope>
    </dependency>

    <!-- Jackson is a high-performance JSON processor (parser, generator) -->
    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-core-asl</artifactId>
      <version>${jackson.version}</version>
      <type>jar</type>
      <scope>compile</scope>
    </dependency>
    <!-- AspectJ -->
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjrt</artifactId>
      <version>${org.aspectj-version}</version>
    </dependency>
    <!-- Logging -->
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>${org.slf4j-version}</version>
    </dependency>
    <dependency>
      <groupId>net.sf.jasperreports</groupId>
      <artifactId>jasperreports</artifactId>
      <version>4.1.2</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>jcl-over-slf4j</artifactId>
      <version>${org.slf4j-version}</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>${org.slf4j-version}</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.16</version>
      <exclusions>
        <exclusion>
          <groupId>javax.mail</groupId>
          <artifactId>mail</artifactId>
        </exclusion>
        <exclusion>
          <groupId>javax.jms</groupId>
          <artifactId>jms</artifactId>
        </exclusion>
        <exclusion>
          <groupId>com.sun.jdmk</groupId>
          <artifactId>jmxtools</artifactId>
        </exclusion>
        <exclusion>
          <groupId>com.sun.jmx</groupId>
          <artifactId>jmxri</artifactId>
        </exclusion>
      </exclusions>
      <scope>runtime</scope>
    </dependency>

    <!-- @Inject -->
    <dependency>
      <groupId>javax.inject</groupId>
      <artifactId>javax.inject</artifactId>
      <version>1</version>
    </dependency>
    <!-- Servlet -->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>
    <!-- Test -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.7</version>
      <scope>test</scope>
    </dependency>
    <!-- Tiles -->
    <dependency>
      <groupId>org.apache.tiles</groupId>
      <artifactId>tiles-extras</artifactId>
      <version>2.2.2</version>
      <exclusions>
        <exclusion>
          <artifactId>tiles-freemarker</artifactId>
          <groupId>org.apache.tiles</groupId>
        </exclusion>
        <exclusion>
          <artifactId>tiles-velocity</artifactId>
          <groupId>org.apache.tiles</groupId>
        </exclusion>
        <exclusion>
          <artifactId>tiles-ognl</artifactId>
          <groupId>org.apache.tiles</groupId>
        </exclusion>
        <exclusion>
          <artifactId>tiles-mvel</artifactId>
          <groupId>org.apache.tiles</groupId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-eclipse-plugin</artifactId>
        <version>2.9</version>
        <configuration>
          <additionalProjectnatures>
            <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
          </additionalProjectnatures>
          <additionalBuildcommands>
            <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
          </additionalBuildcommands>
          <downloadSources>true</downloadSources>
          <downloadJavadocs>true</downloadJavadocs>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
          <compilerArgument>-Xlint:all</compilerArgument>
          <showWarnings>true</showWarnings>
          <showDeprecation>true</showDeprecation>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <configuration>
          <mainClass>org.test.int1.Main</mainClass>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

我检查了 pom.xml 的依赖层次结构,发现了一些奇怪的东西,我会放在下面这可能是问题吗?但这很奇怪,因为它只会在我每次添加 jasper 的依赖项时发生。我开发了其他东西,从来没有冲突过。

http://imageshack.us/photo/my-images/151/capturar1b.jpg/
http://imageshack.us/photo/my-images/696/capturar2f.jpg/

4

1 回答 1

0

第二个答案


第一个错误表明正在使用不兼容的 XML 解析器实现。Weblogic 很可能提供它自己的实现,这与您的依赖项之一引入的 XML 解析器实现相冲突。您需要弄清楚是什么引入了 XML 解析器,然后排除该解析器。许多 IDE(如使用 m2eclipse 时的 Eclipse)可以提供 POM 的可视化图表,以帮助找出依赖关系。或者,我认为您可以使用' mvn dependency:tree '。

第二个错误似乎表明它org.apache.log4j.LogManager不在类路径上。假设您正在正确构建战争(或爆炸战争)并且所有 maven 生成的依赖 jar 都在 /WEB-INF/lib 文件夹中,那么我最好的猜测是有两个 log4j 实现在起作用,它们是冲突的. (也许 weblogic 包含一个 log4j 实现,并且默认情况下它可用于 webapps。)为了测试它,您可以尝试将 log4j 依赖范围设置为“提供”。如果您仍然遇到 log4j 问题,您可能会考虑使用 slf4j 自己的日志记录实现 ( logback )。IE

  <dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <scope>runtime</scope>
    <version>1.0.0</version>
  </dependency>

第一个答案(也许有用,但没有解决主要问题。)


尝试从 jasper 中排除 commons-logging。

另外,我注意到您直接使用杰克逊。Jasper 也依赖于 Jackson。就我而言,我还需要将 Jackson 从 Jasper 中排除,以便我可以参考更新的版本。

  <dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>4.5.0</version>
    <exclusions>
      <exclusion>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
      </exclusion>
      <exclusion>
        <artifactId>jackson-mapper-lgpl</artifactId>
        <groupId>org.codehaus.jackson</groupId>
      </exclusion>
      <exclusion>
        <artifactId>jackson-core-lgpl</artifactId>
        <groupId>org.codehaus.jackson</groupId>
      </exclusion>        
    </exclusions>
  </dependency>

我看到您确实从许多其他依赖项中正确删除了 commons-logging。如果检查最终传递依赖项,则不应看到 commons-logging.jar。

(另外,我尝试稍微改进一下您的 XML 格式。以前很难阅读。仍然不是那么容易阅读,但更好。)

于 2012-05-01T15:49:37.273 回答