9. log4j日志记录搭建
conf/log4j.properties(日志记录的配置文件)
01 | ### set log levels ### |
02 | #log4j.rootLogger = debug , stdout , D , E |
03 | log4j.rootLogger = debug , stdout , D |
05 | ### output to the console ### |
06 | log4j.appender.stdout = org.apache.log4j.ConsoleAppender |
07 | log4j.appender.stdout.Target = System.out |
08 | log4j.appender.stdout.layout = org.apache.log4j.PatternLayout |
09 | #log4j.appender.stdout.layout.ConversionPattern = %d{ABSOLUTE} %5p %c{ 1 }:%L - %m%n |
10 | log4j.appender.stdout.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [%c]-[%p] %m%n |
12 | ### Output to the log file ### |
13 | log4j.appender.D = org.apache.log4j.DailyRollingFileAppender |
14 | log4j.appender.D.File = ${springmvc.root}/WEB-INF/logs/log.log |
15 | log4j.appender.D.Append = true |
16 | log4j.appender.D.Threshold = DEBUG |
17 | log4j.appender.D.layout = org.apache.log4j.PatternLayout |
18 | log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n |
20 | ### Save exception information to separate file ### |
21 | log4j.appender.D = org.apache.log4j.DailyRollingFileAppender |
22 | log4j.appender.D.File = ${springmvc.root}/WEB-INF/logs/error.log |
23 | log4j.appender.D.Append = true |
24 | log4j.appender.D.Threshold = ERROR |
25 | log4j.appender.D.layout = org.apache.log4j.PatternLayout |
26 | log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n |
10. 测试运行
WEB-INF/jsp/index.jsp(测试文件)
01 | <%@ page language= "java" contentType= "text/html; charset=UTF-8" |
02 | pageEncoding= "UTF-8" %> |
03 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > |
06 | <meta http-equiv= "Content-Type" content= "text/html; charset=UTF-8" > |
07 | <title>Insert title here</title> |
cn.springmvc.controller/UserComtroller.java(controller层控制)
01 | package cn.springmvc.controller; |
03 | import org.springframework.stereotype.Controller; |
04 | import org.springframework.web.bind.annotation.RequestMapping; |
08 | public class UserController { |
10 | @RequestMapping ( "index" ) |
11 | public String index(){ |
将该项目部署到本地tomcat6中
右击该项目选择Run as,选择Run on Server
选择自己建立的tomcat6运行如图:
![maven+springMVC+mybatis+junit详细搭建过程](https://i-blog.csdnimg.cn/blog_migrate/c934d13f874ddeda8b938850ef04d4a4.png)
控制台打印出日志如图(启动成功):
![maven+springMVC+mybatis+junit详细搭建过程](https://i-blog.csdnimg.cn/blog_migrate/3bb5ff263fca84d3e9c0f14b729a2a14.png)
在浏览器中输入:http://localhost:8080/springmvc/index.do 进行测试
效果如图(返回成功):
![maven+springMVC+mybatis+junit详细搭建过程](https://i-blog.csdnimg.cn/blog_migrate/680833482176d20bafaf0d6f4a3c93d7.png)
整体包下载地址:
http://download.csdn.net/detail/fengerfhf/6916831
来自:http://my.oschina.net/u/1011897/blog/199172