Spring项目中怎么配置log4j
在spring项目中配置log4j
http://blogger.org.cn/blog/more.asp?name=lhwork&id=17174
其实我们只要查看spring的sample示例就知道怎么做。
首先创建好集成了spring的web项目。
下面配置:
一、在web.xml中加入下面内容
package com.lwf.spring.web.action;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.log4j.Logger;import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import com.lwf.spring.web.dao.UserDao;import com.lwf.spring.web.form.LoginForm;public class LoginAction extends Action { static Logger logger = Logger.getLogger(LoginAction.class); private UserDao userDao;public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {LoginForm loginForm = (LoginForm)form;String name = loginForm.getName();String pwd = loginForm.getPassword();userDao.add(name, pwd);logger.info("just test logger");logger.debug("debug log message");return mapping.findForward("success");}public void setUserDao(UserDao userDao) {this.userDao = userDao;}}?