• 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. ndk编译libx264生成库

    编译脚本如下: TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64 function build_x26 ...

  2. [Swift]LeetCode261.图验证树 $ Graph Valid Tree

    Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...

  3. [Swift]LeetCode347. 前K个高频元素 | Top K Frequent Elements

    Given a non-empty array of integers, return the k most frequent elements. Example 1: Input: nums = [ ...

  4. [Swift]LeetCode560. 和为K的子数组 | Subarray Sum Equals K

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  5. Truncated incorrect DOUBLE value: 'd'的解决方法(jdbc)

    今天写jdbc中dao的增删改查时遇到了一个问题,花费了好长时间,不过还好,有我峰哥出头,问题解决了,在这做个分享,对峰哥表达一下感激之情 网上搜索到的对“Truncated incorrect DO ...

  6. 微信小程序中样式问题

    1.去除button按钮的默认样式 这是button按钮自带的默认样式 button { position:relative; display:block; margin-left:auto; mar ...

  7. mac连接windows远程桌面及文件复制

    最近更换mac办公,但由于之前是用windows,所以很多文件项目之类的东西都还在windows电脑中,一次都传到mac上又会比较占内存,并且使用率也不高,感觉不划算.但每次想用的时候,在从windo ...

  8. 二叉树的相关在线编程(python)

    问题一: 输入一个整数数组, 判断该数组是不是某二叉搜索树的后序遍历的结果.如果是则输出Yes,否则输出No. 假设输入的数组的任意两个数字都互不相同. 正确的后序遍历结果: sequence = [ ...

  9. IDEA激活码(2019)

    如您激活出现问题,请点击这里加入:软件激活问题解决群 前言 IDEA已然成为我最热爱的一款编辑器,作为一个从Eclipse阵营转过来的coder,确实能感受到IDEA的强大,而我电脑桌面的Eclips ...

  10. CentOS开发ASP.NET Core入门教程

    作者:依乐祝 原文地址:https://www.cnblogs.com/yilezhu/p/9891346.html 因为之前一直没怎么玩过CentOS,大多数时间都是使用Win10进行开发,然后程序 ...