log4j介绍
1 通过log4j可以看到程序运行过程中更详细的信息
(1)经常使用log4j查看日志
2 使用
(1)导入log4j的jar包
(2)复制log4j的配置文件,复制到src下面
log4j.properties
3 设置日志级别
log4j.rootLogger=info, stdout
(1)info:看到基本信息
(2)debug:看到更详细信息
Spring整合web项目演示
1 演示问题
每次访问action时候,都会加载spring配置文件
2 解决方案:
(1)在服务器启动时候,创建对象加载配置文件
(2)底层使用监听器、ServletContext对象
3 在spring里面不需要我们自己写代码实现,帮封装
(1)封装了一个监听器,只需要 配置监听器 就可以了
(2)配置监听器之前做事情:导入spring整合web项目jar包
(3)web.xml指定加载spring配置文件位置
<!-- 指定spring配置文件位置 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:bean1.xml</param-value> </context-param> <!-- 配置监听器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>