• log4J

    • 导入log4J.jar
    • 创建log4J.properties
      # Create a file called log4j.properties as shown below and place it in your classpath:
      # 创建一个名为log4j.properties的文件,如下所示,并将其放在类路径中:
      # Global logging configuration
      # 在开发环境下日志级别要设置成DEBUG,生产环境设置成info或error
      log4j.rootLogger=DEBUG, stdout
      # MyBatis logging configuration...
      log4j.logger.org.mybatis.example.BlogMapper=TRACE
      # Console output...
      log4j.appender.stdout=org.apache.log4j.ConsoleAppender
      log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
      log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
  • Spring整合web项目原理
    • 加载spring核心配置文件

      • 加载spring配置文件时,new对象可以实现功能,但效率低
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("service/service.xml");
      • 解决办法
        • 实现思想

          • 把加载配置文件和创建对象过程,在服务器启动时候完成
        • 实现原理(ServletContext对象、监听器)
          • 在ServletContext对象创建时候,使用监听器可以具体到ServletContext对象在什么时候创建
          • 使用监听器(ServletContextListener)监听到ServletContext对象创建时候

            • 加载spring配置文件,把配置文件配置对象创建
            • 把创建出来的对象放到ServletContext域对象里面(setAttribute)
            • 获取对象时候,到ServletContext域得到(getAttribute)
              /**
              * 实现监听器
              */
              public class BaseListener implements ServletContextListener {
              @Override
              public void contextInitialized(ServletContextEvent servletContextEvent) {
              ServletContext servletContext = servletContextEvent.getServletContext();
              ApplicationContext applicationContext = new ClassPathXmlApplicationContext("service/service.xml"); servletContext.setAttribute("applicationContext",applicationContext);
              } @Override
              public void contextDestroyed(ServletContextEvent servletContextEvent) { }
              } <!-- 在web.xml配置listener --> <!-- 配置listener -->
              <listener>
              <listener-class>cn.muriel.auto.web.listener.BaseListener</listener-class>
              </listener> <!-- 测试代码 -->
              <%@ page import="cn.muriel.auto.service.UserService" %>
              <%@ page import="cn.muriel.auto.dao.UserDao" %>
              <%@ page import="org.springframework.context.ApplicationContext" %>
              <%@ page contentType="text/html;charset=UTF-8" language="java" %>
              <html>
              <head>
              <title>$Title$</title>
              </head>
              <body>
              <%
              ApplicationContext applicationContext = (ApplicationContext) application.getAttribute("applicationContext");
              UserService userService = (UserService) applicationContext.getBean("userService");
              UserDao userDao = (UserDao) applicationContext.getBean("userDao");
              userService.setUserDao(userDao);
              userService.addUser();
              %>
              </body>
              </html>

Spring框架基础(下)的更多相关文章

  1. Spring框架基础2

    Spring框架基础2 测试Spring的AOP思想和注解的使用 导包(在前面的基础上添加) SpringAOP名词解释 AOP编程思想:横向重复代码,纵向抽取:就是说多个地方重复的代码可以抽取出来公 ...

  2. Spring学习指南-第二章-Spring框架基础(完)

    第二章 Spring框架基础 面向接口编程的设计方法 ​ 在上一章中,我们看到了一个依赖于其他类的POJO类包含了对其依赖项的具体类的引用.例如,FixedDepositController 类包含 ...

  3. 4-1 Spring框架基础知识

    Spring框架基础知识 1.Spring 框架作用 主要解决了创建对象和管理对象的问题. 自动装配机制 2.Spring 框架 (Spring容器,JavaBean容器,Bean容器,Spring容 ...

  4. Spring框架基础

    1         Spring框架 1.1           Spring的基本概念 是一个轻量级的框架,提供基础的开发包,包括消息.web通讯.数据库.大数据.授权.手机应用.session管理 ...

  5. Spring 框架基础(04):AOP切面编程概念,几种实现方式演示

    本文源码:GitHub·点这里 || GitEE·点这里 一.AOP基础简介 1.切面编程简介 AOP全称:Aspect Oriented Programming,面向切面编程.通过预编译方式和运行期 ...

  6. Spring框架基础知识

    本人博客文章网址:https://www.peretang.com/basic-knowledge-of-spring-framework/ Spring框架简介 Spring , 一个开源的框架 , ...

  7. Spring 框架基础(06):Mvc架构模式简介,执行流程详解

    本文源码:GitHub·点这里 || GitEE·点这里 一.SpringMvc框架简介 1.Mvc设计理念 MVC是一种软件设计典范,用一种业务逻辑.数据.界面显示分离的方法组织代码,将业务逻辑聚集 ...

  8. Spring 框架基础(03):核心思想 IOC 说明,案例演示

    本文源码:GitHub·点这里 || GitEE·点这里 一.IOC控制反转 1.IOC容器思想 Java系统中对象耦合关系十分复杂,系统的各模块之间依赖,微服务模块之间的相互调用请求,都是这个道理. ...

  9. (一)Spring框架基础

    一.什么是spring框架 spring是J2EE应用程序框架,是轻量级的IoC和AOP的容器框架,主要是针对javaBean的生命周期进行管理的轻量级容器,可以单独使用,也可以和Struts框架,i ...

  10. Spring框架基础解析

    Spring是一个轻量级的.非侵入式的容器框架:对Bean对象的生命周期进行管理. Spring框架的核心:IOC(控制反转).DI(依赖注入).AOP(面向切面编程). (1) IOC:控制反转. ...

随机推荐

  1. iptables实现--kafka限制ip地址访问

    iptables -I INPUT -p tcp --dport 9092:9094 -j DROPiptables -I INPUT -s 10.144.137.32 -p tcp --dport ...

  2. 别以为真懂Openstack: 虚拟机创建的50个步骤和100个知识点(5)

    八.KVM 这一步,像virsh start命令一样,将虚拟机启动起来了.虚拟机启动之后,还有很多的步骤需要完成. 步骤38:从DHCP Server获取IP 有时候往往数据库里面,VM已经有了IP, ...

  3. 解决 spring-cloud-starter-zipkin 启动错误

    应用场景:Spring Boot 服务添加 Zipkin 依赖,进行服务调用的数据采集,然后进行 Zipkin-Server 服务调用追踪显示. 示例pom.xml配置: <parent> ...

  4. 【RL-TCPnet网络教程】第9章 RL-TCPnet网络协议栈移植(uCOS-III)

    第9章        RL-TCPnet网络协议栈移植(uCOS-III) 本章教程为大家讲解RL-TCPnet网络协议栈的uCOS-III操作系统移植方式,学习了第6章讲解的底层驱动接口函数之后,移 ...

  5. [Swift]LeetCode34. 在排序数组中查找元素的第一个和最后一个位置 | Find First and Last Position of Element in Sorted Array

    Given an array of integers nums sorted in ascending order, find the starting and ending position of ...

  6. [Swift]LeetCode628. 三个数的最大乘积 | Maximum Product of Three Numbers

    Given an integer array, find three numbers whose product is maximum and output the maximum product. ...

  7. MySQL 规范及优化

    一.建库建表优化 1.核心规范(推荐) 表字符集选择UTF8 (“表情”字段单独设置为其他字符集) 存储引擎使用INNODB 不在库中存储图片.文件等 使用可变长字符串(varchar) 每张表数据量 ...

  8. .NET Core 2.0迁移技巧之web.config配置文件

    大家都知道.NET Core现在不再支持原来的web.config配置文件了,取而代之的是json或xml配置文件.官方推荐的项目配置方式是使用appsettings.json配置文件,这对现有一些重 ...

  9. 本地连接虚拟机_环境搭建01_VMWARE/XShell/CentOS

    今天起准备搭建一套环境用来学习redis,dubbo,docker,nginx. 环境准备: 1.VMware12:  https://pan.baidu.com/s/1-LnqfrWw8ZjQdmG ...

  10. jQuery Mobile中表单的使用体会

    jQuery Mobile是手机端(移动端)页面制作用的框架,包括CSS和JavaScript,此处简单总结一下表单的书写,主要涉及CSS部分.框架提供了表单的一些样式,但在实际使用的时候,我们可能会 ...