`

让Spring架构减化事务配置(4)

阅读更多

 

<!---->完整的实现类如下: BeanClassTypeAutoProxyCreator.java /**//** * 根据类型自动代理Creator * * @author yuanguangdong date: Jul 13, 2004 */ public class BeanClassTypeAutoProxyCreator extends AbstractAutoProxyCreator implements ApplicationContextAware, InitializingBean ...{ /**//** Logger that is available to subclasses */ protected final Log logger = LogFactory.getLog(getClass()); /**//** ApplicationContext this object runs in */ private ApplicationContext applicationContext; /**//** MessageSourceAccessor for easy message access */ private MessageSourceAccessor messageSourceAccessor; /**//**被代理的bean别名列表**/ private List beanNames; /**//**被代理的classType列表**/ private List classTypes; //--------------------------------------------------------- //实现AbstractAutoProxyCreator的抽像方法 //--------------------------------------------------------- /**//** * @see org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator
#getAdvicesAndAdvisorsForBean(java.lang.Class, * java.lang.String, org.springframework.aop.TargetSource) */ protected Object[] getAdvicesAndAdvisorsForBean(Class beanClass, String beanName, TargetSource targetSource) throws BeansException ...{ if (this.beanNames != null) ...{ if (this.beanNames.contains(beanName)) ...{ return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS; } } return DO_NOT_PROXY; } //------------------------------------------------------- //实现ApplicationContextAware接口方法 //------------------------------------------------------- /**//** * @see org.springframework.context.ApplicationContextAware
#setApplicationContext(org.springframework.context.ApplicationContext) */ public void setApplicationContext(ApplicationContext context) throws BeansException ...{
if (context == null && !isContextRequired()) ...{ // Reset internal context state. this.applicationContext = null; this.messageSourceAccessor = null; }
else if (this.applicationContext == null) ...{ // Initialize with passed-in context. if (!requiredContextClass().isInstance(context)) ...{ throw new ApplicationContextException(
"Invalid application context: needs to be of type ["
+ requiredContextClass().getName() + "]"); } this.applicationContext = context; this.messageSourceAccessor = new MessageSourceAccessor(context); initApplicationContext(); }
else ...{ // Ignore reinitialization if same context passed in.
if (this.applicationContext != context) ...{ throw new ApplicationContextException( "Cannot reinitialize with different application context: current one is [" + this.applicationContext + "], passed-in one is [" + context + "]"); } } } /**//** * Determine whether this application object needs to run in an * ApplicationContext. * <p> * Default is "false". Can be overridden to enforce running in a context * (i.e. to throw IllegalStateException on accessors if outside a context). * * @see #getApplicationContext * @see #getMessageSourceAccessor */ protected boolean isContextRequired() ...{ return true; } /**//** * Determine the context class that any context passed to * <code>setApplicationContext</code> must be an instance of. Can be * overridden in subclasses. * * @see #setApplicationContext */ protected Class requiredContextClass() ...{ return ApplicationContext.class; } /**//** * Return the ApplicationContext instance used by this object. */ public final ApplicationContext getApplicationContext() throws IllegalStateException ...{ if (this.applicationContext == null && isContextRequired()) ...{
throw new IllegalStateException( "ApplicationObjectSupport instance [" + this + "] does not run in an ApplicationContext"); } return applicationContext; } /**//** * Return a MessageSourceAccessor for the application context used by this * object, for easy message access. * * @throws IllegalStateException * if not running in an ApplicationContext */ protected final MessageSourceAccessor getMessageSourceAccessor() throws IllegalStateException ...{ if (this.messageSourceAccessor == null && isContextRequired()) ...{ throw new IllegalStateException(
"ApplicationObjectSupport instance [" + this + "] does not run in an ApplicationContext"); } return this.messageSourceAccessor; } public void setClassTypes(String[] classTypes) ...{ this.classTypes = Arrays.asList(classTypes); } /**//** * Subclasses can override this for custom initialization behavior. Gets * called by <code>setApplicationContext</code> after setting the context * instance. * <p> * Note: Does </i>not</i> get called on reinitialization of the context but * rather just on first initialization of this object's context reference. * * @throws ApplicationContextException * in case of initialization errors * @throws BeansException * if thrown by ApplicationContext methods * @see #setApplicationContext */ protected void initApplicationContext() throws BeansException ...{ } //----------------------------------- //实现InitializingBean接口方法 //----------------------------------- /**//** * 查找指定classType的beanName列表 */ private List getBeanNames(String classType) ...{ List beanNameList = null; try ...{ String[] beanName = this.getApplicationContext() .getBeanNamesForType(Class.forName(classType), true, false); if (beanName != null) ...{ beanNameList = Arrays.asList(beanName); } } catch (ClassNotFoundException ex) ...{ throw new IllegalArgumentException("Class not found: " + ex.getMessage()); } return beanNameList; } /**//** * * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */ public void afterPropertiesSet() throws Exception ...{ if (classTypes != null && !classTypes.isEmpty()) ...{ beanNames = new ArrayList(); for (int i = 0; i < classTypes.size(); i++) ...{ String classType = (String) classTypes.get(i); List aList = getBeanNames(classType); beanNames.addAll(aList); } } if (logger.isDebugEnabled()) ...{ for (int i = 0; i < beanNames.size(); i++) ...{ logger.debug("printBean:" + (String) beanNames.get(i)); } } } }
分享到:
评论

相关推荐

    Spring声明式事务配置管理方法

    发布于2013-5-6项目使用SSH架构,现在要添加Spring事务管理功能,针对当前环境,只需要添加Spring2.0AOP类库即可。添加方法:点击项目右键-&gt;BuildPath-&gt;Addlibrarys:打开AddLibraries对话框,然后选定...

    基于Spring Authorization Server全新适配OAuth 2.1协议的企业级微服务架构和服务能力开发平台

    2022.0.4、Spring Cloud Alibaba 2023.0.0.0、Nacos 2.3.1 等主流技术栈开发的多租户系统,遵循SpringBoot 编程思想,高度模块化和可配置化。具备服务发现、配置、熔断、限流、降级、监控、多级缓存、分布式事务、...

    精通Spring(书签)

     Spring 2.5是迄今为止完美的Java EE架构级框架,全面深入、多维度演绎Spring 2.5的各个方面,本书蕴含作者多年Java EE研发实践及经验。  凝聚Java魅力,成就开发专家  看清Java万花的本质,从复杂的表象中寻找...

    spring声明式事务管理

    3. 掌握整合spring和hibernate的持久化操作编程 4.掌握基于AOP的声明式事务编程 按照三层架构构建web项目,在业务层添加事务控制。 1.创建web project项目命名为aopweb 2.添加spring支持、hibernate支持 3.配置WEB...

    精通spring--源代码

    精通spring 源代码 对JavaEE5及Spring2.5进行了综述。包括Java EE5,步入Spring2.5,获得Spring2.5发布版和源码。启动Spring2.5使能项目  详细介绍Spring2.5核心技术。包括控制反转容器,面向切面编程  对DA0层...

    spring boot 全面的样例代码

    - chapter9-1-4:[Spring Cloud构建微服务架构(四)分布式配置中心](http://blog.didispace.com/springcloud4/) - chapter9-1-5:[Spring Cloud构建微服务架构(五)服务网关]...

    SpringColud1简易分布式

    SpringColud1简易分布式 ● cloud-config-server:配置服务器-(通过git获取配置) ● cloud-eureka-server:eureka注册服务器 ● cloud-simple-service:一个使用mybatis的数据库应用,服务端 ● cloud-simple-...

    spring.net中文手册在线版

    14.5.1.理解Spring.NET声明式事务管理的实现 14.5.2.第一个例子 14.5.3.Transaction特性的设置 14.5.4.通过AutoProxyCreator使用声明式事务 14.5.5.通过TransactionProxyFactoryObject使用声明式事务 14.5.6. 通过...

    基于Spring Cloud的进销存管理系统源码

    采用前后端分离的模式,微服务版本前端vue 后端采用Spring Boot、Spring Cloud & Alibaba。注册中心、配置中心选型Nacos,权限认证使用Redis。流量控制框架选型Sentinel,分布式事务选型Seata。 商品管理:商品类型...

    基于Spring Boot、Spring Cloud Alibaba的分布式微服务架构权限管理系统,同时提供了 Vue3 的版本

    基于 Vue/Element UI 和 Spring Boot/Spring Cloud & Alibaba 前后端分离的分布式微服务架构权限管理系统,同时提供了 Vue3 的版本。若依是一套全部开源的快速开发平台,毫无保留给个人及企业免费使用。采用前后端...

    基于Spring BootSpring Cloud & Alibaba的分布式微服务架构权限管理系统同时提供了 Vue

    基于Spring Boot、Spring Cloud & Alibaba的分布式微服务架构权限管理系统,同时提供了 Vue3 的版本。若依是一套全部开源的快速开发平台,毫无保留给个人及企业免费使用。采用前后端分离的模式,微服务版本前端(基于...

    基于Spring Boot、Spring Cloud & Alibaba的分布式微服务架构权限管理系统

    基于Spring Boot、Spring Cloud & Alibaba的分布式微服务架构权限管理系统。 采用前后端分离的模式,微服务版本前端(基于 RuoYi-Vue)。 后端采用Spring Boot、Spring Cloud & Alibaba。 注册中心、配置中心选型Nacos...

    SpringCloud思维导图

    4.微服务架构编码构建 5.Eureka服务注册与发现 6.Zookeeper服务注册与发现 7.Consul服务注册与发现 8.Ribbon负载均衡服务调用 9.OpenFeign服务接口调用 10.Hystrix断路器 11.Zuul路由网关 12.Gateway新一代网关 13....

    springmvc+ibatis框架包,使用spring注入,事务等,包都齐全

    自己配置的springmvc+ibatis框架,自己找齐了包,不容易啊,所以上来跟大家分享一下,spring自动注入包,事务包,ibatis包,数据库连接包,都齐全的,仅局限于springmvc+ibatis,这些包不多,不少,刚够

    基于Spring Cloud+Vue的班级事务管理系统源码(毕设源码)+项目使用说明.zip

    基于Spring Cloud+Vue的班级事务管理系统源码(毕设源码)+项目使用说明.zip 【系统架构】 项目采用B/S架构,前后端通讯采用RESTful API,数据格式使用Json,认证Token格式采用JWT。 身份认证使用Spring Security ...

    SpringCloud H版+SpringCloud alibaba

    SpringCloud H版+SpringCloud alibaba构成,内容涵盖了分布式...分享了服务降级、服务熔断、服务限流、hotkey控制、分布式统一配置管理、分布式全局事务控制、RabbitMQ与Stream整合、Nacos和Nginx配置高可用集群等技术

    Spring攻略(第二版 中文高清版).part1

    1.2 配置Spring IoC容器中的Bean 4 1.2.1 问题 4 1.2.2 解决方案 4 1.2.3 工作原理 4 1.3 调用构造程序创建Bean 14 1.3.1 问题 14 1.3.2 解决方案 14 1.3.3 工作原理 14 1.4 解决构造程序歧义 17 ...

    yudao-cloud是以 ruoyi-vue-pro为基础实现的 Spring Cloud Alibaba 微服务架构.rar

    后端采用 Spring Cloud Alibaba 微服务架构,注册中心 + 配置中心 Nacos,消息队列 RocketMQ,定时任务 XXL-Job,服务保障 Sentinel,服务网关 Gateway,分布式事务 Seata 数据库可使用 MySQL、Oracle、PostgreSQL...

    用于将所有Spring xml配置转换为基于Spring java的配置的工具(高分毕设).zip

    Java SSM项目是一种使用Java语言和SSM框架(Spring + Spring MVC + MyBatis)开发的Web应用程序。SSM是一种常用的Java开发框架组合,它结合了Spring框架、Spring MVC框架和MyBatis框架的优点,能够快速构建可靠、...

Global site tag (gtag.js) - Google Analytics