The configuration of spring and log4j in the Web environment spring3.2.5 Log4j1.2.17__web

Source: Internet
Author: User
Tags log4j

The spring framework plays an increasingly important role in the development of Java EE, and learning the Spring framework configuration in the Web is the first step in the practice, and its importance is self-evident.

First download the release package to the spring official website, and the unpacked jar package is shown in the following illustration:

Then go to the Apache website download the 1.2.x version of the log4j, downloading the address click Download, all jar packages ready to start after the formal.

First step:

Create a new Web project with Eclipse or MyEclipse, and copy all the spring framework and log4j jar packages to the Web-in/lib directory.

The second step: Configure the Web.xml file, the specific configuration is as follows:

<context-param>
  	<param-name>log4jConfigLocation</param-name>
  	<param-value>/ web-inf/classes/log4j.properties</param-value>
  </context-param>
  
  <context-param>
  	<param-name>log4jRefreshInterval</param-name>
  	<param-value>6000</param-value>
  </context-param>
  
  <listener>
  	<listener-class> org.springframework.web.util.log4jconfiglistener</listener-class>
  </listener>
  
  < context-param>
  	<param-name>contextConfigLocation</param-name>
  	<param-value> web-inf/*-content.xml</param-value>
  </context-param>
  
  <listener>
  	< Listener-class>org.springframework.web.context.contextloaderlistener</listener-class>
  </ Listener>

Step three: The Log4j.properties configuration is as follows:

Log4j.appender.stdout=org.apache.log4j.consoleappender
log4j.appender.stdout.layout= Org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.conversionpattern=%d%p [%c]-%m%n
Log4j.rootlogger=info, Stdout,r

log4j.appender.r=org.apache.log4j.dailyrollingfileappender
Log4j.appender.r.file=${webapp.root}/log/system.log
Log4j.appender.r.datepattern = "." yyyy-mm
log4j.appender.r.layout=org.apache.log4j.patternlayout
log4j.appender.r.layout.conversionpattern=%d%p [%c]-%m%n
The final folder is distributed in the following figure:

Launch the project to the server.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.