无法在Spring'mvc-basic'教程上实例化SLF4J LoggerFactory [英] Failed to instantiate SLF4J LoggerFactory on Spring 'mvc-basic' tutorial

查看:60
本文介绍了无法在Spring'mvc-basic'教程上实例化SLF4J LoggerFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Eclipse上尝试 Spring 3.x教程安装了m2e和Maven Integration for WTP插件的3.7.

I'm trying a Spring 3.x tutorial on Eclipse 3.7 with m2e and Maven Integration for WTP plugins installed.

我将上面的教程转换为Maven Project,但是当部署Web应用程序时,出现以下异常:

I converted the above tutorial to Maven Project, but when i deploy the web application i get the following exception:

Failed to instantiate SLF4J LoggerFactory
Reported exception:
  java.lang.NoClassDefFoundError: org/apache/log4j/Level

我的pom.xml看起来像这样:

My pom.xml look like this:

<?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>org.springframework.samples</groupId>
    <artifactId>mvc-basic</artifactId>
    <name>mvc-basic</name>
    <packaging>war</packaging>
    <version>1.0.0-SNAPSHOT</version>
    <properties>
        <org.springframework.version>3.0.5.RELEASE</org.springframework.version>
        <org.slf4j.version>1.6.1</org.slf4j.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>

        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${org.slf4j.version}</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>
            <scope>runtime</scope>
        </dependency>

        <!--  JSR 303 with Hibernate Validator -->
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.1.0.Final</version>
        </dependency>

        <!--  Joda Time -->
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>1.6.2</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time-jsptags</artifactId>
            <version>1.0.2</version>
            <scope>runtime</scope>
        </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>
    </dependencies>
    <repositories>
        <!-- For Hibernate Validator -->
        <repository>
            <id>org.jboss.repository.release</id>
            <name>JBoss Maven Release Repository</name>         
            <url>https://repository.jboss.org/nexus/content/repositories/releases</url>
            <snapshots><enabled>false</enabled></snapshots>         
        </repository>
    </repositories>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                    <showWarnings>true</showWarnings>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warName>mvc-basic</warName>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>install</id>
                        <phase>install</phase>
                        <goals>
                            <goal>sources</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

我还检查了'Project Properties'->'Java Build Path'->'Libraries',但是我发现的唯一的log4j jar是'Maven Dependencies'下的那个

I also checked in 'Project Properties' -> 'Java Build Path' -> 'Libraries' but the only log4j jar that i found is the one under 'Maven Dependencies'

好像我在乱扔罐子,但我自己找不到解决方案.

Seems like i'm messing with jars but i can't find a solution by myself.

推荐答案

好像其他一些库也依赖SLF4J.创建一个WAR文件,并检查SLF4J.jar是否打包在战争中.如果没有,请检查您的Appservers公共lib目录.以防它加载. 检查pom.xml的Dependency图.

Looks like some other library has dependency on SLF4J. Create a WAR file and check if SLF4J.jar is packaged in the war. If not, check your Appservers common lib directory. In case its loading it. Check the Dependency graph of your pom.xml.

如果要添加以下SLF4J log4j API,则为依赖项.

In case if you want to add SLF4J log4j API below is the dependency.

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.6.4</version>
</dependency>

这篇关于无法在Spring'mvc-basic'教程上实例化SLF4J LoggerFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆