GlassFish 4,在pom.xml中没有日志框架的依赖性。[英] GlassFish 4, no logging framework dependencies is working in pom.xml

本文是小编为大家收集整理的关于GlassFish 4,在pom.xml中没有日志框架的依赖性。的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

每个春季MVC项目库都使用自己的记录框架,即. log4j,slf4j,logback,jboss-logging,commons-logging等.如以下Maven Integration.

pom.xml

<log4j.version>1.6.5</log4j.version>
<slf4j.version>1.7.16</slf4j.version>
<slf4j.log4j13.version>1.0.1</slf4j.log4j13.version>
<logback.version>1.1.2</logback.version>
<jboss.logging.version>3.3.0.Final</jboss.logging.version>
<commons.logging.version>1.2</commons.logging.version>

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-bom</artifactId>
      <version>2.5</version>
      <scope>import</scope>
      <type>pom</type>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
<dependency>
    <groupId>ant</groupId>
    <artifactId>ant-jakarta-log4j</artifactId>
    <version>1.6.1</version>
</dependency>

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>${slf4j.version}</version>
</dependency>

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jcl-over-slf4j</artifactId>
    <version>${slf4j.version}</version>
</dependency>

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>${logback.version}</version>
</dependency>

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j13</artifactId>
    <version>${slf4j.log4j13.version}</version>
</dependency>

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-web</artifactId>  
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-jcl</artifactId>
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
</dependency>
</dependencies>

这是运行项目时显示的严重错误

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

slf4j:在[jar:file:/web-inf/lib/log4j-slf4j-impl-2.5.5.jar!/org/slf4j/impl/staticloggerbinder.class.class.class.jar!

slf4j:在[jar:file:/web-inf/lib/logback-classic-1.1.2.2.2.jar!/org/slf4j/impl/StaticLoggerbinder.class.class.class.class.class.class.class.class.class.class.class.class.class.class.class.class.class.class.class.class.class.class.class.class.class.class.class.class.class.class.class]

slf4j.

SLF4J: Found binding in [jar:file:/WEB-INF/lib/slf4j-log4j12-1.7.12.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/WEB-INF/lib/slf4j-log4j13-1.0.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]

slf4j:实际绑定是类型[org.apache.logging.slf4j.log4jloggerfactory] ​​

错误状态记录器未找到log4j2配置文件.使用默认配置:仅将错误记录到控制台.

包括每个记录框架才能包括该项目.但是,是否有任何技巧可以保留外部库所需的日志记录框架,而没有错误.

推荐答案

通常,您将拥有多个使用不同日志记录API的组件.您通常想做的就是绑定具有特定日志记录实现的每个人.例如,春季使用Commons-Loging,因此将其路由到Log4J 2,您将包括Log4J-JCl Jar.同样,要将SLF4J路由到log4j 2您将包括log4j-slf4j-impl jar.您不会包含任何记录罐,因为它是另一个日志记录实现.在上面的情况下,您得到的错误表明您具有log4j 2 slf4j绑定,logback,log4j1.2绑定和log4j 1.3 slf4j的绑定.您应该只有1个,因此请卸下您不想使用的罐子的罐子.

请注意,SLF4J告诉您它选择了log4j 2绑定,但随后您会从log4j 2中获得错误,告诉您它找不到配置文件 - 通常是log4j2.xml.

.

本文地址:https://www.itbaoku.cn/post/1575159.html

问题描述

Each spring mvc project library uses its own logging framework viz. log4j, slf4j, logback, jboss-logging, commons-logging etc. as given below with maven integration.

pom.xml

<log4j.version>1.6.5</log4j.version>
<slf4j.version>1.7.16</slf4j.version>
<slf4j.log4j13.version>1.0.1</slf4j.log4j13.version>
<logback.version>1.1.2</logback.version>
<jboss.logging.version>3.3.0.Final</jboss.logging.version>
<commons.logging.version>1.2</commons.logging.version>

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-bom</artifactId>
      <version>2.5</version>
      <scope>import</scope>
      <type>pom</type>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
<dependency>
    <groupId>ant</groupId>
    <artifactId>ant-jakarta-log4j</artifactId>
    <version>1.6.1</version>
</dependency>

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>${slf4j.version}</version>
</dependency>

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jcl-over-slf4j</artifactId>
    <version>${slf4j.version}</version>
</dependency>

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>${logback.version}</version>
</dependency>

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j13</artifactId>
    <version>${slf4j.log4j13.version}</version>
</dependency>

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-web</artifactId>  
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-jcl</artifactId>
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
</dependency>
</dependencies>

Here is the Severe Error displayed while running the project

SLF4J: Class path contains multiple SLF4J bindings.

SLF4J: Found binding in [jar:file:/WEB-INF/lib/log4j-slf4j-impl-2.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/WEB-INF/lib/logback-classic-1.1.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/WEB-INF/lib/slf4j-log4j12-1.7.12.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/WEB-INF/lib/slf4j-log4j13-1.0.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

Each logging framework is needed for the project to be included. But is there any trick to retain the logging framewokrs needed by the external libraries while running the project without errors.

推荐答案

Typically you will have multiple components that each use different logging APIs. What you normally want to do is bind each of those with a specific logging implementation. For example, Spring uses commons-logging so to route it to Log4j 2 you would include the log4j-jcl jar. Likewise, to route SLF4J to Log4j 2 you would include the log4j-slf4j-impl jar. You would not include any Logback jars since it is another logging implementation. In the case above the errors you are getting show that you have the Log4j 2 SLF4J binding, logback, log4j1.2 binding and log4j 1.3 bindings for SLF4J. You should only have 1 of them, so remove the jars for the ones you don't want to use.

Note that SLF4J is telling you that it chose the Log4j 2 binding but then you are getting an error from Log4j 2 informing you that it can't find a configuration file - typically this would be log4j2.xml.