无法启用spring框架

时间:2015-06-09 12:17:28

标签: spring logging log4j slf4j apache-commons-logging

我想在Spring框架和Spring Security中配置日志记录,并遵循此http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/overview.html#overview-not-using-commons-logging

但是当我加载Tomcat时我遇到了这个问题:

  

GRAVE:子容器在启动时失败   java.util.concurrent.ExecutionException:   org.apache.catalina.LifecycleException:无法启动组件   [StandardEngine [卡塔利娜] .StandardHost [本地主机] .StandardContext [/ RH-探索]     在java.util.concurrent.FutureTask.report(未知来源)at   java.util.concurrent.FutureTask.get(未知来源)at   org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)     在   org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:816)     在   org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     在   org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1575)     在   org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1565)     在java.util.concurrent.FutureTask.run(未知来源)at   java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)at   java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源)at   java.lang.Thread.run(未知来源)引起:   org.apache.catalina.LifecycleException:无法启动组件   [StandardEngine [卡塔利娜] .StandardHost [本地主机] .StandardContext [/ RH-探索]     在   org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)     ......还有6个

     

引起:java.lang.NoClassDefFoundError:   org / springframework / core / io /资源在   java.lang.Class.getDeclaredFields0(Native Method)at   java.lang.Class.privateGetDeclaredFields(未知来源)at   java.lang.Class.getDeclaredFields(未知来源)at   org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106)     在   org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:270)     在   org.apache.catalina.startup.WebAnnotationSet.loadApplicationListenerAnnotations(WebAnnotationSet.java:89)     在   org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:63)     在   org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:415)     在   org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:892)     在   org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:386)     在   org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)     在   org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)     在   org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5412)     在   org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     ......还有6个

的pom.xml

<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
            <scope>runtime</scope>
              <exclusions>
                 <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                 </exclusion>
              </exclusions>
        </dependency>

<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
            <scope>runtime</scope>
              <exclusions>
                 <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                 </exclusion>
              </exclusions>
        </dependency>

<dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>${spring.security.version}</version>
            <scope>runtime</scope>
            <exclusions>
                 <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

<dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>jcl-over-slf4j</artifactId>
          <version>1.5.8</version>
          <scope>runtime</scope>
       </dependency>
       <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
          <version>1.5.8</version>
          <scope>runtime</scope>
       </dependency>
       <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-log4j12</artifactId>
          <version>1.5.8</version>
          <scope>runtime</scope>
       </dependency>
       <dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
          <version>1.2.14</version>
          <scope>runtime</scope>
       </dependency> 

1 个答案:

答案 0 :(得分:1)

我解决了问题!!

首先,这个错误:

  

GRAVE:子容器在启动时失败   java.util.concurrent.ExecutionException:   org.apache.catalina.LifecycleException:无法启动组件   [StandardEngine [卡塔利娜] .StandardHost [本地主机] .StandardContext [/ RH-探索]

是部署问题,所以我为项目做了一个干净,然后我收到了这个错误:

  

严重:例外情况l l l en en en en   (上下文初始化)àl'instancede classe d'écoute(听众)   org.springframework.web.context.ContextLoaderListener   java.lang.AbstractMethodError:   org.slf4j.impl.JDK14LoggerAdapter.log(Lorg / SLF4J /标记; Ljava /郎/字符串; ILjava /郎/字符串; [Ljava /郎/对象; Ljava /郎/ Throwable的;)V

此错误是SLF4J的兼容性问题,因此我将版本从1.5.8更改为1.7.12 而且我发现由于这个错误,应该从SLF4J罐中删除一些重复的pom.xml包:

  

SLF4J:类路径包含多个SLF4J绑定。

我在启动tomcat时也在控制台中出现此错误:

  

INFOS:没有在类路径上检测到Spring WebApplicationInitializer类型

这是servlet-api中的一个问题,我使用的是版本2.5所以为了解决这个问题,我改为版本3.0.1

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
</dependency>

并且所有问题都消失了,春季记录工作正常:D