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.