为什么我们需要 apache 通用日志 jars 在 eclipse 中安装 spring 框架

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14055602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 19:42:13  来源:igfitidea点击:

Why we need apache common logging jars to install spring framework in eclipse

javaspringeclipseapachespring-mvc

提问by anish sharma

I was reading some of the tutorials and some of them are adding apache common logging jars in order to use/install spring framework instead. I have no knowledge about apache common logging.Is it necessary to install apache common logging if I want to work/learn with/from spring/springMVC.What is exactly is apache common logging? What is the most preferable way to install spring in eclipse.

我正在阅读一些教程,其中一些教程正在添加 apache 通用日志记录 jar,以便使用/安装 spring 框架。我对 apache 通用日志记录一无所知。如果我想在 spring/springMVC 中工作/学习/学习,是否需要安装 apache 通用日志记录。apache 通用日志记录到底是什么?在eclipse中安装spring的最可取的方法是什么。

Thanks

谢谢

回答by Isaac

Commons Logging is the logging framework that Spring uses to log its own data:

Commons Logging 是 Spring 用来记录自己数据的日志框架:

http://blog.springsource.org/2009/12/04/logging-dependencies-in-spring/

http://blog.springsource.org/2009/12/04/logging-dependencies-in-spring/

Spring is a product like any other product, and as such, it does logging of its own. It uses Commons Logging as an API to perform logging.

Spring 是一个与任何其他产品一样的产品,因此,它有自己的日志记录。它使用 Commons Logging 作为 API 来执行日志记录。

You don't need to know Commons Logging inside-out in order to learn Spring; but you need to install Commons Logging for the Spring Framework to work.

为了学习 Spring,您不需要从内到外了解 Commons Logging;但是您需要安装 Commons Logging 才能让 Spring Framework 工作。

You don't "install Spring in Eclipse". Eclipse is an IDE. You need to simply download Spring and make it available to your Eclipse projects, by editing your project's build path (right click the project and choose "Properties").

您没有“在 Eclipse 中安装 Spring”。Eclipse 是一个 IDE。您只需下载 Spring 并使其可用于您的 Eclipse 项目,方法是编辑您的项目的构建路径(右键单击该项目并选择“属性”)。

(Making Spring available for a JavaEE application is a bit more involved. Information about it is readily available within a simple Google search)

(使 Spring 可用于 JavaEE 应用程序要复杂一些。有关它的信息可在简单的 Google 搜索中轻松获得)

回答by Shreya Sharma

Yes, It is necessary to include commons-logging dependency in a spring project. Logging is a very important dependency for Spring because

是的,有必要在 spring 项目中包含 commons-logging 依赖项。日志记录是 Spring 的一个非常重要的依赖项,因为

a) it is the only mandatory external dependency
b) everyone likes to see some output from the tools they are using
c) Spring integrates with lots of other tools all of which have also made a choice of logging dependency.

a) 它是唯一的强制性外部依赖
b) 每个人都喜欢看到他们使用的工具的一些输出
c) Spring 与许多其他工具集成,所有这些工具也都选择了日志依赖。

One of the goals of an application developer is often to have unified logging configured in a central place for the whole application, including all external components.
In almost all enterprise or webapp projects there is a need to log all the information related to error, debug, info(other important infomation/event) to be stored somewhere. In practical application developers later use these logs to find out error in the code.Thus logging is important.

应用程序开发人员的目标之一通常是在整个应用程序(包括所有外部组件)的中央位置配置统一的日志记录。
在几乎所有企业或 webapp 项目中,都需要记录与错误、调试、信息(其他重要信息/事件)相关的所有信息以存储在某处。在实际应用程序开发人员后来使用这些日志来找出代码中的错误。因此记录很重要。

We can include this dependency in pom.xml while building the project as shown below(when using maven) or we can download commons-logging jar.

我们可以在构建项目时将此依赖项包含在 pom.xml 中,如下所示(使用 maven 时),或者我们可以下载 commons-logging jar。

<dependencies>
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-webmvc</artifactId>
 <version>${spring.version}</version>
 <exclusions>
 <exclusion>
 <artifactId>commons-logging</artifactId>
 <groupId>commons-logging</groupId>
 </exclusion>
 </exclusions>
 </dependency>
 </dependencies>

After downloading the jar/dependency, We need to create the commons-logging.propertiesin our src folder.

下载JAR /依赖之后,我们需要创建commons- logging.properties在我们的src文件夹中。

org.apache.commons.logging.Log = org.apache.commons.logging.impl.Log4JLogger

The Logger class can be any one from these:
1)org.apache.commons.logging.impl.Log4JLogger
2)org.apache.commons.logging.impl.Jdk14Logger
3)org.apache.commons.logging.impl.SimpleLog

Logger 类可以是以下任一类:
1)org.apache.commons.logging.impl.Log4JLogger
2)org.apache.commons.logging.impl.Jdk14Logger
3)org.apache.commons.logging.impl.SimpleLog

We need to add the log4j.propertiesto the src folder.

我们需要将log4j.properties添加到 src 文件夹。

log4j.rootLogger=DEBUG, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=D:\logger.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

Now, with both the libraries configured we can use them in our Class:

现在,配置了两个库后,我们可以在我们的类中使用它们:

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    public class HowToLog
    {
         private static Log logger = LogFactory.getLog(HowToLog.class);
          public static void main(String[] args){
                logger.info("Log info");
               logger.debug("Debug info");

     }
   }

logger.log:

记录器.log:

2015-01-30 22:12:20 INFO  HowToLog:14 - Log info
2015-01-30 22:12:20 DEBUG HowToLog:15 - Debug info

回答by zwang

Apache Common Logging is used for logging the status of spring system. Without this library, the spring framework could not work properly.

Apache Common Logging 用于记录 spring 系统的状态。没有这个库,spring 框架就无法正常工作。

In my computer, I use myeclipse instead which could help u add spring capability.

在我的电脑中,我使用 myeclipse 代替它可以帮助您添加弹簧功能。

Best

最好的事物

回答by srinivas

The Apache Commons Logging (JCL) provides a Log interface that is intended to be both light-weight and an independent abstraction of other logging toolkits. It provides the middleware/tooling developer with a simple logging abstraction, that allows the user (application developer) to plug in a specific logging implementation.

Apache Commons Logging (JCL) 提供了一个 Log 接口,该接口旨在成为其他日志记录工具包的轻量级和独立抽象。它为中间件/工具开发人员提供了一个简单的日志抽象,允许用户(应用程序开发人员)插入特定的日志实现。

JCL provides thin-wrapper Log implementations for other logging tools, including Log4J, Avalon LogKit (the Avalon Framework's logging infrastructure), JDK 1.4, and an implementation of JDK 1.4 logging APIs (JSR-47) for pre-1.4 systems. The interface maps closely to Log4J and LogKit.

JCL 为其他日志工具提供了瘦包装器日志实现,包括 Log4J、Avalon LogKit(Avalon 框架的日志基础架构)、JDK 1.4 和 JDK 1.4 日志 API (JSR-47) 的实现,用于 1.4 之前的系统。该接口与 Log4J 和 LogKit 紧密映射。