tomcat logging using log4j

In normal install tomcat use JULI for logging and this logging framework has issues on some advance rotation log file  configuration. I got issue with my hard disk always full after tomcat run for a couple of week cause log files. So i wonder if i can limit number of log files generate and tomcat reuse the old one when limit is reach.
After some research i find a solution. Tomcat allow us integration with log4j logging framework so we can handle above issue so easy.
If you have same problem i can guide you through.
Steps to make Tomcat work with log4j

We download two files from extras on tomcat download section

  • tomcat-juli.jar
  • tomcat-juli-adapters.jar

Copy tomcat-juli.jar to $CATALINA_HOME\bin to replace old one

Copy tomcat-juli-adapters.jar to $CATALINA_HOME\lib

Delete in $CATALINA_HOME\conf

Create in $CATALINA_HOME\libs. This is sample of mine:

log4j.rootLogger=INFO, CATALINA

log4j.appender.CATALINA.layout.ConversionPattern=%d [%t] %-5p %c- %m%n

Download log4j version greater than 1.2 and copy to $CATALINA_HOME\lib

After that restart tomcat.


Import mysql:ERROR 2006 (HY000) at line 1197: MySQL server has gone away

1. Symptom

when import large file database into mysql you get follow error:

ERROR 2006 (HY000) at line 1197: MySQL server has gone away

2. Cause

You get above error cause mysql terminal connection between mysql client and mysql server cause reach to limit handle data transmission

3. Solution

Find mysql configuration file add and increase below parameter in [mysqld] section and restart mysql server:

For example: my.cnf



Cannot change version of project facet Dynamic Web Module to x.x

1. Problem

When you create maven web project it default using version servlet 2.3. Now you want change servlet 2.5 or 3.0. You come and manual change on web.xml as below

<web-app xmlns="" xmlns:xsi=""

And now your project on eclipse alway has red mark and with problem show error:

Cannot change version of project facet Dynamic Web Module to 3.0.

2. Solution

Right click on project in eclipse project explorer, choose properties-> Project facets-> uncheck on Dynamic Web Module and click  Apply. Right click on project and choose maven-> update project the project will automatic update and resolve above issue.

jsp EL not working

1. Problem

EL expression on JSP page not working

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri=""%>
<% pageContext.setAttribute("name", "thinh"); %>
<h2>Hello ${name}!</h2>

Output become

Hello ${name}!

the content of web.xml

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "" >


2. Cause

This is cause EL feature not enable on this application. Web servlet 2.3 not enable EL by default.

3. Solution

We have two solutions to solve this issue:

  • Using web servlet 2.5
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns=""
  • Enable EL by directive on JSP
<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8" <code>isELIgnored="false"</code>%>

Maven+spring MVC: org.springframework.web.servlet.DispatcherServlet that does not implement interface javax.servlet.Servlet

1. Problem

When build maven web application, and after that added spring mvc dispatcherServlet for spring 4 i got this issue

"org.springframework.web.servlet.DispatcherServlet" that does not implement 
 interface javax.servlet.Servlet

This is web.xml file

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "" >


2. Cause

You are missing servlet-api in maven dependency

3. Solution
Add following lines to your pom.xml


the element <scope>provided</scope> that mean: this lib will provide at runtime by container check this link for more detail

HibernateException: null index column for collection

1. Symtom
When access one-to-many relation with collection mapping by list. You may be get this error

Caused by: org.hibernate.HibernateException: null index column for collection: org.ow2.bonita.runtime.model.Execution.executions

at org.hibernate.persister.collection.AbstractCollectionPersister.readIndex(

at org.hibernate.collection.PersistentList.readFrom(

at org.hibernate.loader.Loader.readCollectionElement(

at org.hibernate.loader.Loader.readCollectionElements(

at org.hibernate.loader.Loader.getRowFromResultSet(

at org.hibernate.loader.Loader.doQuery(

at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(

at org.hibernate.loader.Loader.loadCollection(

at org.hibernate.loader.collection.CollectionLoader.initialize(

Continue reading HibernateException: null index column for collection

spring: java.lang.ClassNotFoundException: org.hibernate.engine.SessionFactoryImplementor

1- Problem

Using spring 4 and hibernate 3.6.10 and got this

Caused by: java.lang.NoClassDefFoundError: org/hibernate/engine/spi/SessionFactoryImplementor
  at org.springframework.orm.hibernate4.SessionFactoryUtils.( ~[spring-orm-4.0.2.RELEASE.jar:4.0.2.RELEASE]
  at org.springframework.orm.hibernate4.HibernateTransactionManager.afterPropertiesSet( ~[spring-orm-4.0.2.RELEASE.jar:4.0.2.RELEASE]
  at ~[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE]
  at ~[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE]
  ... 28 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.hibernate.engine.spi.SessionFactoryImplementor
  at org.apache.catalina.loader.WebappClassLoader.loadClass( ~[catalina.jar:7.0.50]
  at org.apache.catalina.loader.WebappClassLoader.loadClass( ~[catalina.jar:7.0.50]
  ... 32 common frames omitted


Using right version Hibernate for transaction manager and Local session factory bean

  • org.springframework.orm.hibernate3.HibernateTransactionManager
  • org.springframework.orm.hibernate3.LocalSessionFactoryBean


<beans:bean id="sessionFactory" name="sessionFactory"
        <beans:property name="configLocation">
        <beans:property name="hibernateProperties">
                <beans:prop key="hibernate.show_sql">true</beans:prop>
<beans:bean id="transactionManager"
        <beans:property name="sessionFactory" ref="sessionFactory" />