日期:2014-05-19 浏览次数:20824 次
<!-- Spring2.5配置,下面的"*"代表都个配置文件 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext-*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>访问方法
//只有在j2ee中(容器),下面的路径获取方法才可以使用 String url = this.getClass().getClassLoader().getResource("/").toString(); url = url.substring(0, url.length() - 8);// 截取字符串,去掉classes/ ApplicationContext factory = new ClassPathXmlApplicationContext(url + " applicationContext-*.xml");// 加载多个配置文件查找beans2)log4j
<!-- log4j配置 --> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/log4j.properties</param-value> </context-param> <context-param> <param-name>log4jRefreshInterval</param-name> <param-value>60000</param-value> </context-param> <context-param> <param-name>webAppRootKey</param-name> <param-value>webApp.root</param-value> </context-param> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener>Log4j的配置文件 log4j.properties
#1) org.springframework包下面所有的日志输出的级别设为DEBUG log4j.logger.org.springframework=INFO log4j.rootLogger=INFO,appender1 #2) 控制台输出 log4j.appender.appender1=org.apache.log4j.ConsoleAppender log4j.appender.appender1.layout=org.apache.log4j.PatternLayout log4j.appender.appender1.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}[%p]: %m%n # 立即输出 log4j.appender.appender1.immediateFlush=true
Logger logger = Logger.getLogger(this.getClass());