Spring RESTful服务的问题

时间:2012-03-06 18:52:31

标签: web-services spring spring-mvc

当我在我的库中添加log4j.jar时,Spring RESTful Web服务未加载。控制台日志:

Mar 5, 2012 1:36:35 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'policy'
Mar 5, 2012 1:36:36 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080 
它正在初始化servlet,但之后没有加载服务。

但如果我删除log4j.jar,一切正常。控制台日志:

Mar 5, 2012 1:32:36 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'policy': initialization started
Mar 5, 2012 1:32:37 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'policy-servlet': startup date [Mon Mar 05 13:32:37 EST 2012]; root of context hierarchy

我的库中有commons-logging.jar来运行Spring。

2 个答案:

答案 0 :(得分:1)

是的,commons-logging可以和Spring一起使用。我建议改用slf4j。这是基于令人讨厌的个人经验,包括commons-logging和log4j。

我建议使用构建工具来清理依赖项:

maven:http://maven.apache.org/ 要么 gradle:http://gradle.org/

我还建议不要使用commons日志记录。这是个人选择但我使用slf4j是因为我使用log4j和commons-logging的类加载问题。

使用maven,您可以排除公共日志记录

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

然后包括slf4j logging

答案 1 :(得分:0)

我已经通过在我的classes文件夹中添加long4j.xml并向其添加DTD规范来解决了这个问题。 之前我使用的是log4j.properties,log4j.jar没有认出来。