Thursday, May 3, 2012

Configure log4j for Spring MVC

1. Add following to web.xml


    log4jConfigLocation
    
    classpath:log4j.properties


    log4jExposeWebAppRoot
    false




    org.springframework.web.util.Log4jConfigListener

2. Create log4j factory bean in applicationContext.xml


3. Use it


@Component
public class SomeComponent{
    private Log logger;
  
    @Resource
    public void setLogger(Log logger){
       this.logger=logger;
    }


}

Sample log4j.properties
Spring MVC Sample Project