python源码剖析第二版、spring源码搭建
spring-framework-5.1.x 源码编译 环境搭建 [ idea:2020.1 ]
在spring源码中创建一个新的module
dockerfile里封装ruby。build.gradle
plugins {id 'java'id 'war'
}group 'com.dabing.springmvc'
version '5.1.13.BUILD-SNAPSHOT'sourceCompatibility = 11repositories {mavenCentral()
}dependencies {compile(project(":spring-webmvc"))compile(project(":spring-tx"))compile(project(":spring-jdbc"))testCompile group: 'junit', name: 'junit', version: '4.12'
}
web.xml (DispatcherServlet配置的请求时进行加载创建)
<!DOCTYPE web-app PUBLIC"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN""http://java.sun.com/dtd/web-app_2_3.dtd" ><web-app><display-name>Archetype Created Web Application</display-name><!--spring容器配置--><!--1. 配置全局初始化参数,让服务器启动加载spring的配置文件--><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><!--2. Spring监听器,监听服务器的启动(在服务器启动的时候,创建spring容器)--><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!--springmvc配置--><servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc.xml</param-value></init-param></servlet><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>/</url-pattern></servlet-mapping></web-app>
springmvc.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beanshttps://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttps://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttps://www.springframework.org/schema/mvc/spring-mvc.xsd
"><!--开启controller扫描--><context:component-scan base-package="com.dabing.controller"/><!--配置springmvc的视图解析器--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/jsp/"/><property name="suffix" value=".jsp"/></bean><!--自动注册最合适的处理器映射器,处理器适配器(调用handler方法)--><!-- <mvc:annotation-driven/>--></beans>
ControllerDemo
@Controller
@RequestMapping("/demo")
public class ControllerDemo{@RequestMapping("/handle01")public String handle01(String name, Map<String,Object> model) {System.out.println("++++++++handler业务逻辑处理中....");Date date = new Date();model.put("date",date);return "success";}
}
关联本地tomcat
启动tomcat,测试module
启动tomcat,加载web.xml,加载web.xml中的监听器,执行ContextLoaderListener,执行监听器中的initWebApplicationContext方法进行父容器初始化操作
因为IOC容器已经是顶级容器了,所以其parent属性是null
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态