刚开始学习Struts2的时候,用的是maven方式,但是却不如官方文中所指的出log信息
就是文末提到的:
com.opensymphony.xwork2.DefaultActionProxy.debug:57 - Creating an DefaultActionProxy for
namespace / and action name index
...
org.apache.struts2.dispatcher.ServletDispatcherResult.debug:57 - Forwarding to location /index.jsp
很是疑惑,按理配置啥的官方都是全部提供的,配置位置也不可能搞错,因为如果删除了log4j.xml,启动tomcat后会有提示缺少log4j配置文件,那到底是哪里出了问题呢?
后来发现是少了commons-logging-1.0.4.jar,为什么maven自动编译会漏了这个jar包呢?pom.xml如下:
<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>manning</groupId> <artifactId>Basic_Struts2_Mvn</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>Basic Struts 2</name> <build> <finalName>Basic_Struts2_Mvn</finalName> </build> <dependencies> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>2.2.1</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.14</version> </dependency> <dependency> <groupId>javassist</groupId> <artifactId>javassist</artifactId> <version>3.8.0.GA</version> </dependency> </dependencies> </project>
貌似是没提到commons-logging系列,还有一个问题log4j的输出怎么会需要common-logging呢,莫非这输出不如官方所说不是log4j的?
2010-12-30 11:00:02,700 DEBUG com.opensymphony.xwork2.config.ConfigurationManager.debug:68 - Checking ConfigurationProviders for reload.
2010-12-30 11:00:02,805 DEBUG com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler.debug:68 - Entering nullPropertyValue [target=[com.opensymphony.xwork2.DefaultTextProvider@3278f], property=struts]
2010-12-30 11:00:02,822 DEBUG com.opensymphony.xwork2.config.ConfigurationManager.debug:68 - Checking ConfigurationProviders for reload.
2010-12-30 11:00:02,879 DEBUG com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler.debug:68 - Entering nullPropertyValue [target=[com.opensymphony.xwork2.DefaultTextProvider@3278f], property=struts]
2010-12-30 11:00:02,889 DEBUG com.opensymphony.xwork2.config.ConfigurationManager.debug:68 - Checking ConfigurationProviders for reload.
2010-12-30 11:00:02,928 DEBUG com.opensymphony.xwork2.DefaultActionProxy.debug:68 - Creating an DefaultActionProxy for namespace / and action name index
2010-12-30 11:00:03,012 DEBUG com.opensymphony.xwork2.interceptor.I18nInterceptor.debug:68 - intercept '//index' {
2010-12-30 11:00:03,012 DEBUG com.opensymphony.xwork2.interceptor.I18nInterceptor.debug:68 - applied invocation context locale=zh_CN
2010-12-30 11:00:03,013 DEBUG com.opensymphony.xwork2.interceptor.I18nInterceptor.debug:68 - before Locale=zh_CN
2010-12-30 11:00:03,211 DEBUG com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler.debug:68 - Entering nullPropertyValue [target=[com.opensymphony.xwork2.ActionSupport@15aef45, com.opensymphony.xwork2.DefaultTextProvider@3278f], property=struts]
2010-12-30 11:00:03,268 DEBUG org.apache.struts2.interceptor.FileUploadInterceptor.debug:68 - Bypassing //index
2010-12-30 11:00:03,269 DEBUG com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.debug:68 - Setting static parameters {}
2010-12-30 11:00:03,283 DEBUG com.opensymphony.xwork2.interceptor.ParametersInterceptor.debug:68 - Setting params NONE
2010-12-30 11:00:03,284 DEBUG com.opensymphony.xwork2.interceptor.ParametersInterceptor.debug:68 - Setting params
2010-12-30 11:00:03,314 DEBUG org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.debug:68 - Validating //index with method execute.
2010-12-30 11:00:03,527 DEBUG com.opensymphony.xwork2.validator.ValidationInterceptor.debug:68 - Invoking validate() on action com.opensymphony.xwork2.ActionSupport@15aef45
2010-12-30 11:00:03,536 DEBUG com.opensymphony.xwork2.interceptor.PrefixMethodInvocationUtil.debug:68 - cannot find method [validateExecute] in action [com.opensymphony.xwork2.ActionSupport@15aef45]
2010-12-30 11:00:03,537 DEBUG com.opensymphony.xwork2.interceptor.PrefixMethodInvocationUtil.debug:68 - cannot find method [validateDoExecute] in action [com.opensymphony.xwork2.ActionSupport@15aef45]
2010-12-30 11:00:03,538 DEBUG com.opensymphony.xwork2.DefaultActionInvocation.debug:68 - Executing action method = null
2010-12-30 11:00:03,547 DEBUG org.apache.struts2.dispatcher.ServletDispatcherResult.debug:68 - Forwarding to location /index.jsp
2010-12-30 11:00:03,574 DEBUG com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler.debug:68 - Entering nullPropertyValue [target=[com.opensymphony.xwork2.ActionSupport@15aef45, com.opensymphony.xwork2.DefaultTextProvider@3278f], property=struts]
2010-12-30 11:00:03,595 DEBUG com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler.debug:68 - Entering nullPropertyValue [target=[com.opensymphony.xwork2.ActionSupport@15aef45, com.opensymphony.xwork2.DefaultTextProvider@3278f], property=org]
2010-12-30 11:00:03,799 DEBUG com.opensymphony.xwork2.interceptor.I18nInterceptor.debug:68 - after Locale=zh_CN
2010-12-30 11:00:03,799 DEBUG com.opensymphony.xwork2.interceptor.I18nInterceptor.debug:68 - intercept }
如上控制台日志信息com.opensymphony和org.apache.struts2都是在log4j.xml中配置的:
<!-- specify the logging level for loggers from other libraries --> <logger name="com.opensymphony"> <level value="DEBUG" /> </logger> <logger name="org.apache.struts2"> <level value="DEBUG" /> </logger>
可见,日志输出应与log4j是有直接关系的,尝试删除过log4j-1.2.14.jar,会导致日志不出,由此得出结论两个日志关联jar包缺一不可,但两者为什么要必须同时呢?用到了什么呢?