1.@PostConstruct VS  init-method

1.1 both BeanPostProcessor

1.2 @PostConstruct is a JSR-250 annotation while init-method is Spring's way of having an initializing method.

1.3 If you have a @PostConstruct method, this will be called first before the initializing methods are called.

1.4 If your bean implements InitializingBean and overrides afterPropertiesSet , first @PostConstruct is called,

then the afterPropertiesSet and then init-method.

2.

EntityManagerFactory emf =  ...
EntityManagerHolder holder = (EntityManagerHolder)TransactionSynchronizationManager.getResource(emf);
EntityManager em = holder.getEntityManager();

3.MethodValidationPostProcessor

A convenient BeanPostProcessor implementation that delegates to a JSR-303 provider for performing

method-level validation on annotated methods.

4.LocalSessionFactoryBean

FactoryBean that creates a Hibernate SessionFactory. This is the usual way to set up a shared Hibernate

SessionFactory in a Spring application context; the SessionFactory can then be passed to Hibernate-based

data access objects via dependency injection.

5.LocalContainerEntityManagerFactoryBean

FactoryBean that creates a JPA EntityManagerFactory according to JPA's standard container bootstrap contract.

This is the most powerful way to set up a shared JPA EntityManagerFactory in a Spring application context;

the EntityManagerFactory can then be passed to JPA-based DAOs via dependency injection. Note that

switching to a JNDI lookup or to a LocalEntityManagerFactoryBean definition is just a matter of configuration!

6.SharedEntityManagerCreator

Delegate for creating a shareable JPA EntityManager reference for a given EntityManagerFactory.

A shared EntityManager will behave just like an EntityManager fetched from an application server's JNDI

environment, as defined by the JPA specification. It will delegate all calls to the current transactional

EntityManager, if any; otherwise it will fall back to a newly created EntityManager per operation.

For a behavioral definition of such a shared transactional EntityManager, see PersistenceContextType.TRANSACTION

and its discussion in the JPA spec document. This is also the default being used for the annotation-based PersistenceContext.type().

14.3.5 Transaction management strategies

Both TransactionTemplate and TransactionInterceptor delegate the actual transaction handling to a PlatformTransactionManager

instance, which can be a HibernateTransactionManager (for a single Hibernate SessionFactory, using a ThreadLocal Session under

the hood) or a JtaTransactionManager (delegating to the JTA subsystem of the container) for Hibernate applications. You can

even use a customPlatformTransactionManager implementation. Switching from native Hibernate transaction management to

JTA, such as when facing distributed transaction requirements for certain deployments of your application, is just a matter

of configuration. Simply replace the Hibernate transaction manager with Spring’s JTA transaction implementation. Both

transaction demarcation and data access code will work without changes, because they just use the generic transaction

management APIs.

For distributed transactions across multiple Hibernate session factories, simply combine JtaTransactionManager as a transaction

strategy with multiple LocalSessionFactoryBean definitions. Each DAO then gets one specific SessionFactory reference passed into

its corresponding bean property. If all underlying JDBC data sources are transactional container ones, a business service can

demarcate transactions across any number of DAOs and any number of session factories without special regard, as long as it

is using JtaTransactionManager as the strategy.

7.

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ys.scs.performance.PerformanceService

com.ys.scs.vip.MemberCardService.performanceService; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException:

Error creating bean with name 'performanceService': Bean with name 'performanceService' has been injected into other beans [resetTaskPerformanceService,billAdaptorService]

in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean.

This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.

该问题出现的原因是:在正常加载完依赖后,因为 @Async 注解的出现,又需将该 Bean 代理一次,然后 Spring 发现该 Bean 已经被其他对象注入,

且注入的是没被代理过的版本,于是报错。@Lazy注解可以解决

spring 拾遗的更多相关文章

  1. spring拾遗(一)——@Value注入static属性

    一般情况的下的@Value是用在非静态方法上的,如下: import org.springframework.beans.factory.annotation.Value; import org.sp ...

  2. Spring 实践 -拾遗

    Spring 实践 标签: Java与设计模式 Junit集成 前面多次用到@RunWith与@ContextConfiguration,在测试类添加这两个注解,程序就会自动加载Spring配置并初始 ...

  3. Java注解拾遗

    注解简介: 注解Annotation是jdk1.5的新增功能,在现在的日常开发中,几乎离不开注解,写篇短文,来做个拾遗. 注解作用: Annotation(注解)的作用是修饰包.类.构造方法.方法.成 ...

  4. Spring IOC 概述

    Spring IOC 概述 IOC(Inversion of Control) 控制反转,也叫 DI(D_ependency injection_) 依赖注入.是一种设计思想.不过我并不同意所谓反转的 ...

  5. 精尽Spring MVC源码分析 - 寻找遗失的 web.xml

    该系列文档是本人在学习 Spring MVC 的源码过程中总结下来的,可能对读者不太友好,请结合我的源码注释 Spring MVC 源码分析 GitHub 地址 进行阅读 Spring 版本:5.2. ...

  6. 基于spring注解AOP的异常处理

    一.前言 项目刚刚开发的时候,并没有做好充足的准备.开发到一定程度的时候才会想到还有一些问题没有解决.就比如今天我要说的一个问题:异常的处理.写程序的时候一般都会通过try...catch...fin ...

  7. 玩转spring boot——快速开始

    开发环境: IED环境:Eclipse JDK版本:1.8 maven版本:3.3.9 一.创建一个spring boot的mcv web应用程序 打开Eclipse,新建Maven项目 选择quic ...

  8. Spring基于AOP的事务管理

                                  Spring基于AOP的事务管理 事务 事务是一系列动作,这一系列动作综合在一起组成一个完整的工作单元,如果有任何一个动作执行失败,那么事务 ...

  9. [Spring]IoC容器之进击的注解

    先啰嗦两句: 第一次在博客园使用markdown编辑,感觉渲染样式差强人意,还是github的样式比较顺眼. 概述 Spring2.5 引入了注解. 于是,一个问题产生了:使用注解方式注入 JavaB ...

随机推荐

  1. PgSQl临时表的创建

    创建前可先删除 drop table tmp0 创建临时表 select * into temp table tmp0 from xxx create index idx_tmp0_inner_cd ...

  2. senfile函数实例的运行过程截图

    //要传输的文件内容如下所示: 启动服务器,等待客户端连接(在同一台主机上模拟的) 客户端远程登录,这里是在本地登录 这个要注意一点就是远程登陆的时候一定要带上端口号不然连接失败!!

  3. div随页面滚动遇顶固定的两种方法(js&jQuery)

    一.遇顶固定的例子 我一直以为是某个div或层随屏幕滚动,遇顶则固定,离开浏览器顶部又还原这样的例子其实不少,其实它的名字叫“层的智能浮动效果”.目前我们在国内的商业网站上就常常看到这样的效果了.例如 ...

  4. sql 追踪 神器

    http://www.thinkphp.cn/download/690.html 一个中国人开发的php工具箱此工具能几秒钟追踪出sql 数据库操作, 能分析出 Thinkphp3.2 的任意sql ...

  5. Android性能测试框架Emmagee

    目前移动设备,尤其是Android设备,相对于过去的J2me时代,硬件有大幅度的提高,并且更新地非常快,可以安装和运行更多的应用. 但是目前安卓市场对于应用的要求并不如苹果商店那么严格,Android ...

  6. 错题0913-java

    子类A继承父类B, A a = new A(); 则父类B构造函数.父类B静态代码块.父类B非静态代码块.子类A构造函数.子类A静态代码块.子类A非静态代码块 执行的先后顺序是? A:父类B静态代码块 ...

  7. MyBatis是支持普通 SQL查询

    MyBatis是支持普通 SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis 消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索.MyBatis 使用简单的 XML或注解用于配置 ...

  8. Nucleus PLUS的启动、执行线程和中断处理

    nucleus系统是实时嵌入式操作系统,具有实时.任务抢先.多任务内核,当中95%的代码由C语言写成,极易移植.开放的源代码使得配置和裁剪方便,再加上体积小(所有二进制映像可仅20K).响应高速等特性 ...

  9. 《Java并发编程实战》第八章 线程池的使用 读书笔记

    一.在任务与运行策略之间的隐性解耦 有些类型的任务须要明白地指定运行策略,包含: . 依赖性任务.依赖关系对运行策略造成约束.须要注意活跃性问题. 要求线程池足够大,确保任务都能放入. . 使用线程封 ...

  10. android 清除缓存功能

    本应用数据清除管理器 DataCleanManager.java   是从网上摘的 忘了 名字了 对不住了 载入一个webview   产生缓存  众所周知的webview是产生缓存的主要原因之中的一 ...