Archive for August, 2008

Spring Tip: Log4j configuration

Place log4j.properties in WEB-INF directory of the web application,

log4j.rootLogger=INFO, stdout, fileAppender

# Used only for development.
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} [%t] %-5p (%F:%L) – %m%n
log4j.logger.net.sf.ehcache=TRACE

# File appender used in production.
log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.fileAppender.File=${app.logdir}/app.log

log4j.appender.fileAppender.MaxFileSize=1MB
log4j.appender.fileAppender.MaxBackupIndex=5

log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.fileAppender.layout.ConversionPattern=%d{ISO8601} %t %p %c – %m%n

In web.xml add


<context-param>
	<param-name>log4jConfigLocation</param-name>
	<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>

<context-param>
	<param-name>log4jRefreshInterval</param-name>
	<param-value>1000</param-value>
</context-param>

<listener>
	<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

Comments (3)

Spring Tip : how to reference local xsd file.

Got this exception when I changed the spring configuration file from using dtd to xsd,

SRVE0100E: Did not realizeĀ  init() exception thrown by servlet dispatcher: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 4 in XML document from ServletContext resource [/WEB-INF/dispatcher-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element ‘beans’.
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element ‘beans’.
Had to google around for some time to find a solution. The original solution is written here.

This works!. Just elaborating what i did on Websphere 6.1 server to solve this…

Extract the spring.jar file to a temp directory and take the META-INF directory from it.

Delete the existing MANIFEST.MF file and created a new jar “spring-schemas.jar” with just the META-INF directory as content.

Now, On Websphere admin console.. goto..

Environments > Shared Libraries

and create a new one named SPRING_SCHEMA pointing to spring-schemas.jar.

Now add this library to the server at

Application servers > server1 > Class loader > Classloader_1203675889577 > Library Reference

That’s it. Restart the server and the error should be gone.

Comments (2)