spring源码学习之springMVC(一)
个人感觉《Spring技术内幕:深入解析Spring架构与设计原理(第2版)》这本书对spring的解读要优于《Spring源码深度解析(第2版)》这本书的,后者感觉就是再陈述一些代码,没有自己的理解,有点呆板!下面是《Spring技术内幕》中的springMVC的描述:
在部署描述中,为这个DispatcherServlet定义了对应的URL映射,这些URL映射为这个servlet指定了需要处理的HTTP请求。context-param 参数的配置用来指定spring IoC容器读取Bean定义的XML文件的路径,作为springMVC启动类,ContextLoaderListener被定义一个监听器,这个监听器是与web服务器的生命周期相关联的,由ContextLoaderListener监听器负责完成IoC容器
在web环境中的启动工作,DispatcherServlet和ContextLoaderListener提供了在web容器中对spring的接口,也就是说,这些接口与web容器耦合是通过ServletContext来实现的,这个ServletContext为spring的IoC容器体系提供了一个宿主环境,在宿主环境中,springMVC建立起一个IoC容器的体系。这个IoC容器体系是通过ContextLoaderListener初始化来建立起来的,在建立IoC容器的体系后,把DispatcherServlet作为spring MVC处理web请求的转发器建立起来,从而完成响应HTTP请求的准备,有了这些基本的配置,建立在IOC容器基础上的spring MVC就可以正常的发挥作用了。
《Spring源码深度解析(第2版)》中的内容:
spring框架提供了构建完整的Web应用程序的全功能MVC模块,通过策略接口,spring框架是高度可配置的,而且支持多种视图技术,springMVC框架并不知道使用的视图,
所以不会强迫您只使用JSP技术,springMVC分离了控制器、模型对象、分派器以及处理程序对象的角色,这种分离让他们更容易进行定制
spring的NVC是基于Servlet功能实现的,通过实现servlet接口DispatcherServlet来封装其核心功能实现,通过将请求分配给程序处理,同时带有可配置的处理程序映射,
视图解析、本地语言、主体解析以及下载文件支持。默认的处理程序是非常简单的Controller接口,只有一个方法ModelAndView handleRequest(request, response);
spring提供了一个控制器层次结构,可以派生子类。
springMVC解决的问题主要就是以下几点:
将web页面的请求传给服务器
根据不同的请求处理不同的逻辑单元
返回处理结果数据并跳转至结果页面
一、ContextLoaderListener
对于springMVC功能实现的分析,我们首先从web.xml开始,在web.xml 文件中我们首先配置的就是ContextLoaderListener,那么它所提供的功能有哪些,又是
如何实现的呢?
当使用编程方式的时候我们可以直接将spring配置信息作为参数注入spring容器中,如ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
但是在web下,我们需要更多的是与web环境相互结合,通常的办法是将路径以context-param的方式注册并使用ContextLoaderListener进行监听读取
ContextLoaderListener的作用就是启动web容器时,自动装配ApplicationContext的配置信息。因为它实现了ServletContextListener这个接口,在web.xml配置这个监听器,
启动容器时,就会默认执行它实现的方法,使用ServletContextListener接口,开发者能够在为客户端请求提供服务之前向ServletContext中添加任意的对象,这个对象在
ServletContext启动的时候被初始化,然后在ServletContext整个运行期间都是可用的
每一个web应用都有一个ServletContext与之相关联。ServletContext对象在应用启动时被创建,在应用关闭的时候被销毁。ServletContext在全局范围内有效,
类似于应用中的一个全局变量
在ServletContextListener中核心逻辑便是初始化WebApplicationContext实例并存放至ServletContext中
1、ServletContextListener的使用
(1)创建自定义的ServletContextListener
首先我们创建ServletContextListener,目标是在系统启动时添加自定义属性,以便于在全局范围内可以随时调用。系统启动的时候会调用ServletContextListener实现类的
contextInitialized方法,所以需要实现在这个方法中实现我们的初始化逻辑。
public class MyDataContextListener implements ServletContextListener{
private ServletContext context = null;
public MyDataContextListener(){ }
// 该方法在ServletContext启动之后调用,并准备好处理客户端请求
public void contextInitialized (SevrvletContextEvent event){
this.context = event.getServletContext();
// 实现自己的逻辑并将结果记录在属性中
context = setAttribute("myData","this is myData");
}
// 这个方法在ServletContext关闭时调用
public void contextDestroyed(SevrvletContextEvent event){
this.context = null;
}
}
(2)注册监听器
<listener>
<listener-class>com.test.MyDataContextListener</listener-class>
</listener>
(3)测试
一旦web应用启动的时候,我们就鞥在任意的servlet或者jsp中通过下面方式获取我们初始化的参数:
String myData = (String) getServletContext().getAttribute("myData");
2、spring中的contextLoaderListener
ServletContext启动之后会调用ServletContextListener的contextInitialized方法,可以从这个方法开始:
org.springframework.web.context.ContextLoaderListener类中的contextInitialized
@Override
public void contextInitialized(ServletContextEvent event) {
// 初始化WebApplicationContext
initWebApplicationContext(event.getServletContext());
}
这里有一个WebApplicationContext,WebApplicationContext继承自ApplicationContext,在ApplicationContext的基础上又追加了一些特定于web的操作与特性,看一下这个类的初始化源码:
public WebApplicationContext initWebApplicationContext(ServletContext servletContext) {
if (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null) {
// web.xml 中存在多次ContextLoader定义
throw new IllegalStateException(
"Cannot initialize context because there is already a root application context present - " +
"check whether you have multiple ContextLoader* definitions in your web.xml!");
} Log logger = LogFactory.getLog(ContextLoader.class);
servletContext.log("Initializing Spring root WebApplicationContext");
if (logger.isInfoEnabled()) {
logger.info("Root WebApplicationContext: initialization started");
}
long startTime = System.currentTimeMillis(); try {
// Store context in local instance variable, to guarantee that
// it is available on ServletContext shutdown.
if (this.context == null) {
// 初始化WebApplicationContext
this.context = createWebApplicationContext(servletContext);
}
if (this.context instanceof ConfigurableWebApplicationContext) {
ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) this.context;
if (!cwac.isActive()) {
// The context has not yet been refreshed -> provide services such as
// setting the parent context, setting the application context id, etc
if (cwac.getParent() == null) {
// The context instance was injected without an explicit parent ->
// determine parent for root web application context, if any.
ApplicationContext parent = loadParentContext(servletContext);
cwac.setParent(parent);
}
configureAndRefreshWebApplicationContext(cwac, servletContext);
}
}
// 记录在servletContext中
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context); ClassLoader ccl = Thread.currentThread().getContextClassLoader();
if (ccl == ContextLoader.class.getClassLoader()) {
currentContext = this.context;
}
else if (ccl != null) {
currentContextPerThread.put(ccl, this.context);
} if (logger.isDebugEnabled()) {
logger.debug("Published root WebApplicationContext as ServletContext attribute with name [" +
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE + "]");
}
if (logger.isInfoEnabled()) {
long elapsedTime = System.currentTimeMillis() - startTime;
logger.info("Root WebApplicationContext: initialization completed in " + elapsedTime + " ms");
} return this.context;
}
catch (RuntimeException ex) {
logger.error("Context initialization failed", ex);
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
throw ex;
}
catch (Error err) {
logger.error("Context initialization failed", err);
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, err);
throw err;
}
}
步骤如下:
(1)WebApplicationContext存在性的验证
(2)创建WebApplicationContext
主要就是创建WebApplicationContext类,看一下创建过程的源码,在createWebApplicationContext方法中:
org.springframework.web.context.ContextLoader类中的createWebApplicationContext
protected WebApplicationContext createWebApplicationContext(ServletContext sc) {
Class<?> contextClass = determineContextClass(sc);
// 这里判断使用什么样的类在web容器中作为IoC容器
if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {
throw new ApplicationContextException("Custom context class [" + contextClass.getName() +
"] is not of type [" + ConfigurableWebApplicationContext.class.getName() + "]");
}
// 直接实例化需要产生的IoC容器,并设置IoC容器的各个参数,然后通过refresh启动容器的初始化
return (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);
} protected Class<?> determineContextClass(ServletContext servletContext) {
String contextClassName = servletContext.getInitParameter(CONTEXT_CLASS_PARAM);
if (contextClassName != null) {
try {
return ClassUtils.forName(contextClassName, ClassUtils.getDefaultClassLoader());
}
catch (ClassNotFoundException ex) {
throw new ApplicationContextException(
"Failed to load custom context class [" + contextClassName + "]", ex);
}
}
else {
contextClassName = defaultStrategies.getProperty(WebApplicationContext.class.getName());
try {
return ClassUtils.forName(contextClassName, ContextLoader.class.getClassLoader());
}
catch (ClassNotFoundException ex) {
throw new ApplicationContextException(
"Failed to load default context class [" + contextClassName + "]", ex);
}
}
}
// 其中ContextLoader类中有这样的静态代码块:
static {
// Load default strategy implementations from properties file.
// This is currently strictly internal and not meant to be customized
// by application developers.
try {
ClassPathResource resource = new ClassPathResource(DEFAULT_STRATEGIES_PATH, ContextLoader.class);
defaultStrategies = PropertiesLoaderUtils.loadProperties(resource);
}
catch (IOException ex) {
throw new IllegalStateException("Could not load 'ContextLoader.properties': " + ex.getMessage());
}
}
根据以上代码,肯定会存在当前目录下的属性文件ContextLoader.properties,你当然可以在源码中看到这个配置:
spring-web下的resources文件夹下的org.springframework.web.context.ContextLoader.properties
org.springframework.web.context.WebApplicationContext=org.springframework.web.context.support.XmlWebApplicationContext
综合代码来看,在初始化过程中,程序首先会读取ContextLoader类的同目录下的属性文件ContextLoader.properties,并根据其中的配置提取将要实现的WebApplicationContext类的
实现类,并且根据反射方式进行实例的创建
(3)将实例记录在servletContext中
(4)映射当前的类加载器与创建的实例到全局变量currentContextPerThread中
二、DispatcherServlet
1、DispatcherServlet的初始化
在servlet初始化阶段,我们知道会首先调用其init方法,在DispatcherServlet中查找init方法的实现,查找方法直接查看该类的调用关系,在其父类中:
org.springframework.web.servlet.HttpServletBean中的init方法:
@Override
public final void init() throws ServletException {
if (logger.isDebugEnabled()) {
logger.debug("Initializing servlet '" + getServletName() + "'");
} // Set bean properties from init parameters.
// 解析init-param 并封装到pvs中
PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this.requiredProperties);
if (!pvs.isEmpty()) {
try {
// 将当前的这个servlet类转换成BeanWrapper,从而能够以spring的方式对init-param的值进行注入
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
ResourceLoader resourceLoader = new ServletContextResourceLoader(getServletContext());
// 注册自定义的属性编辑器,一旦使用Resource类型的属性将会使用ResourceEditor进行解析
bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment()));
// 空实现,留给子类覆盖
initBeanWrapper(bw);
// 属性注入
bw.setPropertyValues(pvs, true);
}
catch (BeansException ex) {
if (logger.isErrorEnabled()) {
logger.error("Failed to set bean properties on servlet '" + getServletName() + "'", ex);
}
throw ex;
}
} // Let subclasses do whatever initialization they like.
// 留给子类扩展
initServletBean(); if (logger.isDebugEnabled()) {
logger.debug("Servlet '" + getServletName() + "' configured successfully");
}
}
DispatcherServlet的初始化过程是通过将当前servlet类型实例转换为BeanWrapper类型实例,以便使用spring中提供的注入功能进行对应属性的注入,这些属性如contextAttribute、
contextClass、nameSpace等,都可以在web.xml文件中以初始化参数的方式。DispatcherServlet继承自FrameworkServlet,FrameworkServlet类上包含同名属性,spring会保证这些
这些参数被注入到对应的值中。属性注入主要包含以下几个步骤:
(1)封装以及验证初始化参数
ServletConfigPropertyValues除了封装属性还有对属性的验证功能
org.springframework.web.servlet.HttpServletBean.ServletConfigPropertyValues类中
public ServletConfigPropertyValues(ServletConfig config, Set<String> requiredProperties)
throws ServletException { Set<String> missingProps = (!CollectionUtils.isEmpty(requiredProperties) ?
new HashSet<>(requiredProperties) : null); Enumeration<String> paramNames = config.getInitParameterNames();
while (paramNames.hasMoreElements()) {
String property = paramNames.nextElement();
Object value = config.getInitParameter(property);
addPropertyValue(new PropertyValue(property, value));
if (missingProps != null) {
missingProps.remove(property);
}
} // Fail if we are still missing properties.
if (!CollectionUtils.isEmpty(missingProps)) {
throw new ServletException(
"Initialization from ServletConfig for servlet '" + config.getServletName() +
"' failed; the following required properties were missing: " +
StringUtils.collectionToDelimitedString(missingProps, ", "));
}
} // 从代码中得知,封装属性主要是对初始化的参数进行封装,也就是servlet中配置的<init-param>中配置的封装。
(2)将当前的servlet实例转化成BeanWrapper实例
PropertyAccessorFactory.forBeanPropertyAccess(this);是spring中提供的方法,主要作用就是将制定实例转化为spring中可以处理的BeanWrapper实例
(3)注册相对于Resource的属性编辑器
在当前实例的属性注入过程中一旦遇到Resource类型的属性就会使用ResourceEditor去解析
(4)属性注入
BeanWrapper为spring中的方法,支持spring的自动注入。其实我们最常用的属性注入无非是contextAttribute、contextClass、nameSpace等
(5)servletBean实例化
在ContextLoaderListener加载的时候已经创建了WebApplicationContext实例,而在这个函数中最重要的就是对这个类的进一步补充实例化
看一下initServletBean源码:
org.springframework.web.servlet.FrameworkServlet中
@Override
protected final void initServletBean() throws ServletException {
getServletContext().log("Initializing Spring FrameworkServlet '" + getServletName() + "'");
if (logger.isInfoEnabled()) {
logger.info("FrameworkServlet '" + getServletName() + "': initialization started");
}
long startTime = System.currentTimeMillis(); try {
this.webApplicationContext = initWebApplicationContext();
// 设计为子类覆盖
initFrameworkServlet();
}
catch (ServletException | RuntimeException ex) {
logger.error("Context initialization failed", ex);
throw ex;
} if (logger.isInfoEnabled()) {
long elapsedTime = System.currentTimeMillis() - startTime;
logger.info("FrameworkServlet '" + getServletName() + "': initialization completed in " +
elapsedTime + " ms");
}
}
最为关键的初始化逻辑其实由initWebApplicationContext方法实现:
2、WebApplicationContext的初始化
initWebApplicationContext方法的主要工作就是创建或刷新WebApplicationContext实例并对servlet功能所使用的变量进行初始化
org.springframework.web.servlet.FrameworkServlet类中
protected WebApplicationContext initWebApplicationContext() {
WebApplicationContext rootContext =
WebApplicationContextUtils.getWebApplicationContext(getServletContext());
WebApplicationContext wac = null; if (this.webApplicationContext != null) {
// A context instance was injected at construction time -> use it
// context实例在构造函数中被注入
wac = this.webApplicationContext;
if (wac instanceof ConfigurableWebApplicationContext) {
ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) wac;
if (!cwac.isActive()) {
// The context has not yet been refreshed -> provide services such as
// setting the parent context, setting the application context id, etc
if (cwac.getParent() == null) {
// The context instance was injected without an explicit parent -> set
// the root application context (if any; may be null) as the parent
cwac.setParent(rootContext);
}
// 刷新上下文环境
configureAndRefreshWebApplicationContext(cwac);
}
}
}
if (wac == null) {
// No context instance was injected at construction time -> see if one
// has been registered in the servlet context. If one exists, it is assumed
// that the parent context (if any) has already been set and that the
// user has performed any initialization such as setting the context id
// 根据contextAttribute属性加载WebApplicationContext
wac = findWebApplicationContext();
}
if (wac == null) {
// No context instance is defined for this servlet -> create a local one
wac = createWebApplicationContext(rootContext);
} if (!this.refreshEventReceived) {
// Either the context is not a ConfigurableApplicationContext with refresh
// support or the context injected at construction time had already been
// refreshed -> trigger initial onRefresh manually here.
synchronized (this.onRefreshMonitor) {
onRefresh(wac);
}
} if (this.publishContext) {
// Publish the context as a servlet context attribute.
String attrName = getServletContextAttributeName();
getServletContext().setAttribute(attrName, wac);
if (this.logger.isDebugEnabled()) {
this.logger.debug("Published WebApplicationContext of servlet '" + getServletName() +
"' as ServletContext attribute with name [" + attrName + "]");
}
} return wac;
}
对于本函数的初始化主要分为这几个部分:
(1)寻找和创建对应的WebApplicationContext实例
寻找和创建对应的WebApplicationContext实例主要分为以下几个步骤:
1.1 通过构造函数的注入进行初始化
1.2 通过contextAttribute进行初始化
org.springframework.web.servlet.FrameworkServlet中的findWebApplicationContext方法
@Nullable
protected WebApplicationContext findWebApplicationContext() {
String attrName = getContextAttribute();
if (attrName == null) {
return null;
}
WebApplicationContext wac =
WebApplicationContextUtils.getWebApplicationContext(getServletContext(), attrName);
if (wac == null) {
throw new IllegalStateException("No WebApplicationContext found: initializer not registered?");
}
return wac;
}
1.3 重新创建WebApplicationContext实例
org.springframework.web.servlet.FrameworkServlet类中createWebApplicationContext
protected WebApplicationContext createWebApplicationContext(@Nullable ApplicationContext parent) {
// 获取servlet的初始化参数contextClass,如果没有默认匹配XmlWebApplicationContext.class
Class<?> contextClass = getContextClass();
if (this.logger.isDebugEnabled()) {
this.logger.debug("Servlet with name '" + getServletName() +
"' will try to create custom WebApplicationContext context of class '" +
contextClass.getName() + "'" + ", using parent context [" + parent + "]");
}
if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {
throw new ApplicationContextException(
"Fatal initialization error in servlet with name '" + getServletName() +
"': custom WebApplicationContext class [" + contextClass.getName() +
"] is not of type ConfigurableWebApplicationContext");
}
// 通过反射方式实例化contextClass
ConfigurableWebApplicationContext wac =
(ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass); wac.setEnvironment(getEnvironment());
// parent为在ContextLoaderListener中创建的实例,在ContextLoaderListener加载的时候初始化的WebApplicationContext类型实例
wac.setParent(parent);
// 获取ContextConfigLocation属性,配置在servlet初始化参数中
String configLocation = getContextConfigLocation();
if (configLocation != null) {
wac.setConfigLocation(configLocation);
}
// 初始化spring环境包括加载配置文件等
configureAndRefreshWebApplicationContext(wac); return wac;
}
(2)configureAndRefreshWebApplicationContext刷新上下文环境
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext方法中
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac) {
if (ObjectUtils.identityToString(wac).equals(wac.getId())) {
// The application context id is still set to its original default value
// -> assign a more useful id based on available information
if (this.contextId != null) {
wac.setId(this.contextId);
}
else {
// Generate default id...
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
ObjectUtils.getDisplayString(getServletContext().getContextPath()) + '/' + getServletName());
}
} wac.setServletContext(getServletContext());
wac.setServletConfig(getServletConfig());
wac.setNamespace(getNamespace());
wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener())); // The wac environment's #initPropertySources will be called in any case when the context
// is refreshed; do it eagerly here to ensure servlet property sources are in place for
// use in any post-processing or initialization that occurs below prior to #refresh
ConfigurableEnvironment env = wac.getEnvironment();
if (env instanceof ConfigurableWebEnvironment) {
((ConfigurableWebEnvironment) env).initPropertySources(getServletContext(), getServletConfig());
} postProcessWebApplicationContext(wac);
applyInitializers(wac);
// 加载配置文件及整合parent到wac
wac.refresh();
}
// 无论调用方式如何变化,只要使用ApplicationContext所提供的的功能最后都免不了使用公共父类AbstractApplicationContext提供的refresh()方法
(3)刷新
onRefresh是在FrameworkServlet类中提供的模板方法,在其子类DispatcherServlet中进行重写,主要用于刷新在web功能实现中所必须使用的全局变量。
@Override
protected void onRefresh(ApplicationContext context) {
initStrategies(context);
} protected void initStrategies(ApplicationContext context) {
// 初始化MultipartResolver
initMultipartResolver(context);
// 初始化LocaleResolver
initLocaleResolver(context);
// 初始化ThemeResolver
initThemeResolver(context);
// 初始化HandlerMappings
initHandlerMappings(context);
// 初始化HandlerAdapters
initHandlerAdapters(context);
// 初始化HandlerExceptionResolvers
initHandlerExceptionResolvers(context);
// 初始化RequestToViewNameTranslator
initRequestToViewNameTranslator(context);
// 初始化ViewResolvers
initViewResolvers(context);
// 初始化FlashMapManager
initFlashMapManager(context);
}
3.1 初始化MultipartResolver
在spring中,MultipartResolver主要用来处理文件上传。常用的配置如下:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxmunFileSize">
<value>1000</value>
</property>
</bean> org.springframework.web.servlet.DispatcherServlet类中:
private void initMultipartResolver(ApplicationContext context) {
try {
this.multipartResolver = context.getBean(MULTIPART_RESOLVER_BEAN_NAME, MultipartResolver.class);
if (logger.isDebugEnabled()) {
logger.debug("Using MultipartResolver [" + this.multipartResolver + "]");
}
}
catch (NoSuchBeanDefinitionException ex) {
// Default is no multipart resolver.
this.multipartResolver = null;
if (logger.isDebugEnabled()) {
logger.debug("Unable to locate MultipartResolver with name '" + MULTIPART_RESOLVER_BEAN_NAME +
"': no multipart request handling provided");
}
}
}
就写一个吧,其他的基本类似!
spring源码学习之springMVC(一)的更多相关文章
- 【spring源码学习】springMVC之映射,拦截器解析,请求数据注入解析,DispatcherServlet执行过程
[一]springMVC之url和bean映射原理和源码解析 映射基本过程 (1)springMVC配置映射,需要在xml配置文件中配置<mvc:annotation-driven > ...
- spring源码学习之springMVC(二)
接着上一篇.继续来看springMVC中最和我们开发中接近的一部分内容: DispatcherServlet的逻辑处理 作者写到在DispatcherServlet类中存在doGet.doPost之类 ...
- spring源码学习之路---深入AOP(终)
作者:zuoxiaolong8810(左潇龙),转载请注明出处,特别说明:本博文来自博主原博客,为保证新博客中博文的完整性,特复制到此留存,如需转载请注明新博客地址即可. 上一章和各位一起看了一下sp ...
- spring源码学习之路---IOC初探(二)
作者:zuoxiaolong8810(左潇龙),转载请注明出处,特别说明:本博文来自博主原博客,为保证新博客中博文的完整性,特复制到此留存,如需转载请注明新博客地址即可. 上一章当中我没有提及具体的搭 ...
- Spring源码学习
Spring源码学习--ClassPathXmlApplicationContext(一) spring源码学习--FileSystemXmlApplicationContext(二) spring源 ...
- Spring源码学习-容器BeanFactory(四) BeanDefinition的创建-自定义标签的解析.md
写在前面 上文Spring源码学习-容器BeanFactory(三) BeanDefinition的创建-解析Spring的默认标签对Spring默认标签的解析做了详解,在xml元素的解析中,Spri ...
- Spring源码学习-容器BeanFactory(三) BeanDefinition的创建-解析Spring的默认标签
写在前面 上文Spring源码学习-容器BeanFactory(二) BeanDefinition的创建-解析前BeanDefinition的前置操作中Spring对XML解析后创建了对应的Docum ...
- Spring源码学习-容器BeanFactory(二) BeanDefinition的创建-解析前BeanDefinition的前置操作
写在前面 上文 Spring源码学习-容器BeanFactory(一) BeanDefinition的创建-解析资源文件主要讲Spring容器创建时通过XmlBeanDefinitionReader读 ...
- Spring源码学习-容器BeanFactory(一) BeanDefinition的创建-解析资源文件
写在前面 从大四实习至今已一年有余,作为一个程序员,一直没有用心去记录自己工作中遇到的问题,甚是惭愧,打算从今日起开始养成写博客的习惯.作为一名java开发人员,Spring是永远绕不过的话题,它的设 ...
随机推荐
- Arrays.asList()使用的问题
在java语言中,把数组转换成List集合,有个很方便的方法就是 List<String> list = Arrays.asList("a","b" ...
- 学习 debug
要在代码编辑器中设置源代码断点,有以下 4 种操作方式. (1) 把光标移到要设为断点的行上,按下 F5 键. (2) 用鼠标左键单击要设为断点的行的最左端. (3) 用鼠标右键单击要设为断点的行,在 ...
- [JZOJ4673] 【NOIP2016提高A组模拟7.20】LCS again
题目 描述 题目大意 给你一个字符串和字符的取值范围,问和这个字符串的最长公共子串的长度为N−1N-1N−1的串的个数. 思考历程 一看就知道这是一个神仙题. 思考了一会儿,觉得AC是没有希望的了. ...
- SpringCloud之Fegin学习笔记
以下部分内容来源于网络摘抄~ 1.作用 Feign 是一种声明式.模板化的 HTTP 客户端.在 Spring Cloud 中使用 Feign,可以做到使用 HTTP 请求访问远程服务,就像调用本地方 ...
- thinkphp 自动完成
自动完成是ThinkPHP提供用来完成数据自动处理和过滤的方法,使用create方法创建数据对象的时候会自动完成数据处理. 因此,在ThinkPHP使用create方法来创建数据对象是更加安全的方式, ...
- limit方法也是模型类的连贯操作方法之一
limit方法也是模型类的连贯操作方法之一,主要用于指定查询和操作的数量,特别在分页查询的时候使用较多.ThinkPHP的limit方法可以兼容所有的数据库驱动类的. 限制结果数量 例如获取满足要求的 ...
- Python更新后ros用不了的bug
一.原因 我同时安装了python2.7 和3.5,而且将python默认配置为python3.5,所以ros并不支持,所以提示找不到. 2.解决方式 通过修改不同版本的python的优先级,将pyt ...
- python随机数(转载)
随机生成 0 到 1 之间的浮点数 random.random() 方法会返回 [0.0, 1.0) 之间的浮点数,注意,这是一个左闭右开的区间,随机数可能会是 0 但不可能为 1 . 随机生成 a ...
- SpringCloud学习笔记(四):Eureka服务注册与发现、构建步骤、集群配置、Eureka与Zookeeper的比较
简介 Netflix在设计Eureka时遵守的就是AP原则 拓展: 在分布式数据库中的CAP原理 CAP原则又称CAP定理,指的是在一个分布式系统中,Consistency(一致性). Availab ...
- django中的request对象
Request 我们知道当URLconf文件匹配到用户输入的路径后,会调用对应的view函数,并将 HttpRequest对象 作为第一个参数传入该函数. 我们来看一看这个HttpRequest对 ...