Spring框架
文章平均质量分 69
自然鸟神
我热爱编程,搜索引擎
展开
-
Spring线程池ThreadPoolTaskExecutor配置及详情
<!-- spring thread pool executor --> <bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"> <!-- 线程池维护线程的最少数量 --> ...原创 2018-09-29 16:51:12 · 4272 阅读 · 0 评论 -
每日一则JavaWeb---Spring的ApplicationEventPublisher的作用
public interface ApplicationEventPublisher { /** * Notify all listeners registered with this application of an application * event. Events may be framework events (such as RequestHandledEvent)原创 2017-08-30 19:10:24 · 1995 阅读 · 0 评论 -
每日一则JavaWeb---Spring的ResourceLoader的作用
先来看看的源码public interface ResourceLoader { /** Pseudo URL prefix for loading from the class path: "classpath:" */ String CLASSPATH_URL_PREFIX = ResourceUtils.CLASSPATH_URL_PREFIX; Resource getRes原创 2017-08-30 18:01:51 · 930 阅读 · 0 评论 -
每日一则JavaWeb---Spring之ContextLoaderListener
先看一下ContextLoaderListener的继承结构public class ContextLoaderListener extends ContextLoader implements ServletContextListener可以看到其中涉及了ContextLoader、ServletContextListener。首先看看ServletContextListener的源原创 2017-08-29 20:14:38 · 305 阅读 · 0 评论 -
Spring源码解读:ContextLoader类
ContextLoader类的结构如图:ContextLoader类的源码:package org.springframework.web.context;import java.io.IOException;import java.util.ArrayList;import java.util.Collections;import java.util.List;原创 2017-05-05 14:34:09 · 10361 阅读 · 0 评论 -
每日一则JavaWeb---spring的<util:> 和<p:>
spring中的配置<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"转载 2017-09-14 14:21:39 · 280 阅读 · 0 评论 -
每日一则JavaWeb---Spring的OncePerRequestFilter的作用
在Spring中,filter默认继承OncePerRequestFilter,OncePerRequestFilter,顾名思义,它能够确保在一次请求中只通过一次filter,而需要重复的执行。大家常识上都认为,一次请求本来就只filter一次,为什么还要由此特别限定呢,往往我们的常识和实际的实现并不真的一样,经过一番资料的查阅,此方法是为了兼容不同的web container,也就是说并不转载 2017-08-15 19:18:22 · 2806 阅读 · 0 评论 -
Spring提高篇(一):Spring 所提供的过滤器和监听器
Spring 为 Web 应用提供了几个过滤器和监听器,在适合的时间使用它们,可以解决一些常见的 Web 应用问题。延迟加载过滤器Hibernate 允许对关联对象、属性进行延迟加载,但是必须保证延迟加载的操作限于同一个 Hibernate Session 范围之内进行。如果 Service 层返回一个启用了延迟加载功能的领域对象给 Web 层,当 Web 层访问到那些需要延迟加载的数据时转载 2017-05-09 17:17:34 · 459 阅读 · 0 评论 -
Spring提高篇(七):Web 相关工具类
您几乎总是使用 Spring 框架开发 Web 的应用,Spring 为 Web 应用提供了很多有用的工具类,这些工具类可以给您的程序开发带来很多便利。在这节里,我们将逐一介绍这些工具类的使用方法。操作 Servlet API 的工具类当您在控制器、JSP 页面中想直接访问 Spring 容器时,您必须事先获取 WebApplicationContext 对象。Spring 容器在启动时将转载 2017-05-09 17:05:24 · 323 阅读 · 0 评论 -
Spring提高篇(六):文件资源操作工具类
查看这个类是因为今天查看AbstractResource默认实现的时候看见了用来返回一个URL的URI部分return ResourceUtils.toURI(url);它支持“classpath:”和“file:”的地址前缀,它能够从指定的地址加载文件资源File f = ResourceUtils.getFile("classpath:sqlscript/eventLog转载 2017-05-09 16:55:36 · 562 阅读 · 0 评论 -
源码深度解析spring中防止乱码的过滤器
今天本来是看shiro框架和spring等框架的整合,顺带看了一下web.xml的配置<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/原创 2017-04-25 18:14:44 · 1012 阅读 · 0 评论 -
Spring源码解读:ServletContextListener接口
ServletContextListener接口的源码package javax.servlet;import java.util.EventListener; /** * Implementations of this interface receive notifications about * changes to the servlet context of the原创 2017-05-05 11:22:06 · 644 阅读 · 0 评论 -
每日一则JavaWeb---Spring的MessageSource的作用
我们都知道MessageSource用于国际化,先来看看源码是个啥,其实啥也不是就是一个方法public interface MessageSource { /** * 解析传入的message,如果没有就返回defaultMessage */ String getMessage(String code, Object[] args, String defaultMessag原创 2017-08-30 19:55:43 · 3398 阅读 · 2 评论 -
每日一则JavaWeb---ClassLoader原理解析
参考文档:参加class对象详解java中的class对象深入解析类加载器深入探讨 Java 类加载器真正理解线程上下文类加载器对于类的加载机制的探讨主要是最近的Spring源码的第一的解读过程中总是会出现一些很有意思的东西如下:ClassLoader ccl = Thread.currentThread().getContext原创 2017-08-31 16:48:20 · 303 阅读 · 0 评论 -
org.springframework.web.filter.DelegatingFilterProxy 的原理及使用
DelegatingFilterProxy就是一个对于servlet filter的代理,用这个类的好处主要是通过Spring容器来管理servlet filter的生命周期,还有就是如果filter中需要一些Spring容器的实例,可以通过spring直接注入,另外读取一些配置文件这些便利的操作都可以通过Spring来配置实现。首先在web.xml中配置:<filter> &...转载 2018-03-29 16:59:08 · 2586 阅读 · 0 评论 -
SpringBoot中使用事务
Spring Boot 使用事务非常简单,首先使用注解 @EnableTransactionManagement 开启事务支持后,然后在访问数据库的Service方法上添加注解 @Transactional 便可。关于事务管理器,不管是JPA还是JDBC等都实现自接口 PlatformTransactionManager 如果你添加的是 spring-boot-starter-jdbc 依转载 2018-02-07 15:56:14 · 6040 阅读 · 0 评论 -
Spring的编程式事务
JDBC的事务管理在Spring2.0下有两种编程式的实现:PlatformTransactionManager、TransactionTemplate一、PlatformTransactionManager的编程式实现例子:JdbcTemplate template = new JdbcTemplate(datasource);DataSourceTransactionManage转载 2018-02-07 15:43:22 · 623 阅读 · 0 评论 -
Spring中基于注解的事务管理
1. 事务说明在Spring中,事务有两种实现方式,分别是编程式事务管理和声明式事务管理两种方式。 编程式事务管理: 编程式事务管理使用TransactionTemplate或者直接使用底层的PlatformTransactionManager。对于编程式事务管理,spring推荐使用TransactionTemplate。 声明式事务管理: 建立在AOP之上的。其本质是对方法前后转载 2018-02-07 14:51:00 · 360 阅读 · 0 评论 -
Spring源码解读:EventListener接口
在spring中EventListener接口的源码package java.util;/** * A tagging interface that all event listener interfaces must extend. * @since JDK1.1 */public interface EventListener {}EventListener 解释说明了原创 2017-05-05 11:05:32 · 4436 阅读 · 3 评论 -
解决spring中不同配置文件中存在name或者id相同的bean可能引起的问题
spring对同一配置文件中相同id或者name的两个或以上的bean时,做直接抛异常的处理,而对不同配置文件中相同id或者名称的bean,只会在打印日志级别为info的信息,信息内容大概为"Overriding bean definition for bean xxx : replacing xxx with beanDefinition ".可能引发的问题:当不同文件中配置了相同id或转载 2017-12-22 19:58:10 · 590 阅读 · 0 评论 -
深入理解Spring系列之一:开篇
自己最近工作也不是很忙,因为主要是做业务相关的程序,所以技术都已经荒废很久了,最近看了一系列的技术文章就顺带自己也学习和记录一下。顺便加深一下对Spring这个最流行的框架的理解。前言:Spring经过大神们的构思、编码,日积月累而来,所以,对其代码的理解也不是一朝一夕就能快速完成的。源码学习是枯燥的,需要坚持!坚持!坚持!当然也需要技巧,第一遍学习的时候,不用关注全部细节,不重要的代码可以先原创 2016-11-18 17:00:34 · 426 阅读 · 0 评论 -
每日一则JavaWeb---spring的ApplicationContext
在Spring中使用的最多的还是ApplicationContext这个Model,直接使用BeanFactory的比较少,话不多说先上代码public interface ApplicationContext extends EnvironmentCapable, ListableBeanFactory, HierarchicalBeanFactory, MessageSource, A原创 2017-09-01 15:30:36 · 480 阅读 · 0 评论 -
每日一则JavaWeb---spring中非Controller层使用HttpServletRequest两种解决方案
第一种方案:第一种特别简单就是直接使用注入的方式private @Autowired HttpServletRequest request;但是会有一个测试的问题Warning for Spring the autowiring will not work running tests.但是现在的Spring的版本中估计已经没有这个问题了第二种方案:原创 2017-09-18 11:49:54 · 840 阅读 · 0 评论 -
spring源码解读:BeanFactory接口
不知道为什么看着Spring的源码,感触最深的是Spring对概念的抽象,所以我就先学接口了,BeanFactory是Spring IOC实现的基础,这边定义了一系列的接口,我们通过这些接口的学习,可以大致了解BeanFactory体系各接口如何分工合作。为学习具体实现打下基础.毕竟这边逻辑复杂,涉及的概念很多.BeanFactory 是Spring bean容器的根接口.提供转载 2017-05-05 17:40:17 · 982 阅读 · 0 评论 -
每日一则JavaWeb---spring 各个包的作用
org.springframework.aop-3.0.6.RELEASESpring的面向切面编程,提供AOP(面向切面编程)实现org.springframework.asm- 3.0.6.RELEASESpring独立的asm程序,Spring2.5.6的时候需要asmJar 包3.0.6开始提供他自己独立的asmJarorg.springframework.aspects-转载 2017-08-31 17:02:12 · 340 阅读 · 0 评论 -
spring源码解读:aware接口
/* * Copyright 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * Y原创 2017-04-26 10:14:44 · 427 阅读 · 0 评论 -
spring源码解读:BeanPostProcessor接口
在aware接口中曾经提到过其实它是不做啥事情的,要实现回调通知的功能还得BeanPostProcessor来,现在来看一下BeanPostProcessor的源码package org.springframework.beans.factory.config;import org.springframework.beans.BeansException;/** * Factory原创 2017-04-26 10:38:50 · 790 阅读 · 0 评论 -
spring实例化javabean的三种方式分享
第一种:直接配置javabean文件bean.xmlpersonDao.javapackage springdao;public class personDao { private String name; private String dep; public String getName() { return name; } public void setName转载 2016-07-08 13:42:50 · 2262 阅读 · 0 评论 -
quartz与spring整合
-->------------------------------------------------------------------------------------------------------------------------ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p原创 2016-06-02 17:24:39 · 250 阅读 · 0 评论 -
spring aop的三个关键概念
1.PointCut (切入点)Join Point 指的是程序运行中的某个阶段点,如某个方法调用,异常抛出等。Pointcut是joincut的集合,他是程序需要注入Advice的位置的集合,指明Advice要什么样的条件才能被触发。在Pointcut接口的定义中,也许你已经想到了,ClassFilter是类过滤器,它定义了哪些类名需要拦截;典型的两个实现类为TypePatternC原创 2016-01-04 16:19:30 · 1468 阅读 · 0 评论 -
不使用spring的aop功能实现日志输出
第一种:public class TimeBook { private Logger logger = Logger.getLogger(this.getClass().getName()); //审核数据的相关程序 public void doAuditing(String name){ logger.log(Level.INFO, name + "开始审核数据..."原创 2016-01-04 15:06:04 · 990 阅读 · 0 评论 -
Spring中ApplicationContext对事件传递
ApplicationContext中的事件处理是通过ApplicationEvent类和ApplicationListener接口来提供的,通过ApplicationContext的publishEvent()方法发布到ApplicationListener; 在这里包含三个角色:被发布的事件,事件的监听者和事件发布者。 事件发布者在发布事件的时候通知事件的监听者。 下面我们围绕转载 2015-12-14 21:23:27 · 8325 阅读 · 0 评论 -
Application中的资源访问的三种方式
1.ApplicationContext actx=new FileSystemApplicationContext("config.xml");Resource resource=actx.getResource("classpath:messages.properties");2.ApplicationContext actx=new FileSystemApplicationCo原创 2015-12-14 21:16:07 · 742 阅读 · 0 评论 -
Spring中bean的三种使用方式
第一种使用beanwrapperHelloWorld helloWorld=new HelloWorld();BeanWrapper bw=new BeanWrapperImpl(helloWorld);bw.setPeopertyValue("msg","HelloWorld");第二种,使用BeanFactoryInputStream is=new FileI原创 2015-12-14 20:00:55 · 540 阅读 · 0 评论 -
Spring中的国际化
一.基于浏览器请求的国际化实现:获取message文档配置的方法ApplicationContext actx=new FileSystemXmlApplicationContext("config.xml");Object[] objects=new Object[]{"HelloWorld","afs"};String msg=actx.getMessage("HelloWor转载 2015-12-14 21:07:01 · 573 阅读 · 0 评论 -
Spring中Bean的4种依赖检查模式
下面我们来看看Spring中的Bean的4中依赖检查模式:simple,object,all,none.1 simple:对基本类型,字符型和集合进行依赖检查。Java代码xml version="1.0" encoding="UTF-8"?> "http://www.springframework.org/dtd/spring-beans.dtd"> beans> be转载 2015-12-14 20:34:46 · 814 阅读 · 0 评论 -
spring中的5中自动装配方案
Spring Auto-Wiring Beans——Spring自动装配Bean所谓自动装配,就是将一个Bean注入到其他Bean的Property中,类似于以下:bean id="customer" class="com.lei.common.Customer" autowire="byName" /> Spring支持5种自动装配模式,如下:no转载 2015-12-14 20:33:28 · 316 阅读 · 0 评论 -
spring中用ref属性指定的三种方法
package javamxj.spring.basic.ref;public class HelloBean { private String hello; public String getHello() { return hello; } public void setHello(String hello) {原创 2015-12-14 20:25:14 · 5064 阅读 · 0 评论 -
Spring源码解读:Envrionment接口
spring提供了普通结构通用的环境机制,可以使用默认或者自定义的环境去配置一些变量或者设置,便于正式运行的环境跟开发,测试的环境分开。PropertyResolver接口中的方法及定义/** * Interface for resolving properties against any underlying source. * * @author Chris Beams *转载 2017-04-26 14:16:07 · 2351 阅读 · 0 评论 -
Spring框架的两个简化XML配置文件的p-namespace和c-namespace
spring框架的模块化设计,出现了大量的命名空间。应用开发过程中用到的模块,才需要引入对应的命名空间。Spring框架的丰富功能,导致了Spring框架的XML配置文件十分复杂。这里要介绍的是两个特殊的命名空间,其出现只是为了简化XML配置文件的编写,并未提供应用所需的逻辑功能。1. p-namespace在XML配置文件中,首先引入如下命名空间:xmlns:p="http://转载 2017-05-02 16:36:38 · 313 阅读 · 0 评论