gwt + jetty + spring + log4j ERROR: "DOMConfigurator object is not assignable to a Configurator" -
this problem mentioned in several sources around web unable solve solutions provided there.
problem: following error thrown log4j when issuing mvn gwt:run:
[error] log4j:error "org.apache.log4j.xml.domconfigurator" object not assignable "org.apache.log4j.spi.configurator" variable. [error] log4j:error class "org.apache.log4j.spi.configurator" loaded [error] log4j:error [sun.misc.launcher$appclassloader@23137792] whereas object of type [error] log4j:error "org.apache.log4j.xml.domconfigurator" loaded [webappclassloader=demo@3d1665ac]. [error] log4j:error not instantiate configurator [org.apache.log4j.xml.domconfigurator].
description of project: use default jetty server provided gwt , run on exploded war.
<gwt.version>2.6.1</gwt.version> <spring.version>3.2.6.release</spring.version> <log4j.version>1.2.17</log4j.version> <slf4j.version>1.7.5</slf4j.version> <dependency> <groupid>log4j</groupid> <artifactid>log4j</artifactid> <version>${log4j.version}</version> </dependency> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-api</artifactid> <scope>runtime</scope> </dependency> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-log4j12</artifactid> <scope>runtime</scope> </dependency> <!-- jar listed in dependencies in case causes log4j error. --> <dependency> <groupid>org.slf4j</groupid> <artifactid>jcl-over-slf4j</artifactid> <version>${slf4j.version}</version> <scope>runtime</scope> </dependency>
what's more, exclude commons-logging spring , other projects depend on it.
(not satisfying) solution: logging works fine when log4j, slf4j-api, slf4j-log4j12 , jcl-over-slf4j jars put in web-inf/lib directory when jcl-over-slf4 not in project's classpath (i.e. comment out last mentioned dependency).
when jcl-overl-slf4j included in maven dependencies (see above) not added target's lib directory included in project's classpath. causes error. jar necessary put in lib error disappears when not included in classpath. maven-dependency-plugin used work problem around copying lib directory , skipping maven dependency.
this solution workaround 4 jars - log4j, slf4j-api, slf4j-log4j12, jcl-over-slf4j - mentioned in many standard examples of gwt , spring projects.
could explain why behaving way , how solve normal inclusion of jcl-over-slf4j in maven dependencies?
jetty treats org.apache.commons.logging
system class, i.e. loads system class loader (i.e. classpath) in priority on webapp's web-inf/lib
. in case, org.apache.commons.logging
provided jcl-over-slf4j
. so, code in webapp calls commons logging loaded system class loader, , initializes slf4j using class's class loader (as opposed current thread class loader), uses code slf4j-log4j12
, log4j
system class loader. later on, code in webapp calls log4j (possibly through slf4j) initialize logging configuration, , uses jars webapp's web-inf/lib
(as expected). when comes put together, comes issue, classes loaded different class loaders.
now solve issue: it's not straightforward.
simply put, classloading in devmode mess (see https://docs.google.com/document/d/1bwfafapa0m0z1swodnx7m3qtv31odqfke7aeadn_2bu/edit?usp=sharing tried document it).
to solve issue, you'd have either use own servletcontainerlauncher
in devmode own classloading rules, or more run webapp in servlet container (e.g. mvn jetty:run
or mvn tomcat7:run
, or whatever). you'd run devmode in -noserver
mode.
it's more complex setup, has big advantage of being 1 you'll need superdevmode; , superdevmode replace devmode year (devmode dead in firefox, , in chrome on linux –basically, it's dead on linux–, , support removed chrome on other platforms later year, leaving 1 working platform: internet explorer on windows).
Comments
Post a Comment