SlideShare ist ein Scribd-Unternehmen logo
1 von 58
JAVA EE 6
最佳实践:
从 Spring 迁移到
WTF ?!?WTF ?!?
Bert Ertman
荷兰 Luminis 公司研究员
荷兰 Java 用户组的负责人,同时还是一位 Java
Champion
2
Practical Modularity with Java in the Cloud Age
Paul Bakker &Bert Ertman
Modular
Cloud Apps
with OSGi
Building
这是说给谁听的?
您正在使用老版本的 Spring ,却不知怎样向
前发展
Java EE 好像又火起来了,您应当赶上这样的
趋势吗?
您喜欢《 J2EE Design and Development 》
这本书,但它仍没有过时吗?
3
为什么要倾听我们的意见
?
我们不为任何一家应用服务器供应商 工作
我们也不是 Rod Johnson 的追随者
我们广泛使用 J2EE 、 Spring 和新的 Java
EE 技术
针对 Java EE 和 Spring 展开过无数次讨论…
…
4
为什么要迁移?
Spring 是一项专有技术
无论如何,从旧版的 Spring 升级需要大量的
工作
那,为什么不直接迁移到标准上来呢?
5
Scenario A
但现在我们需要这样的
首先让我们澄清几
个误解……
8
Java EE 是否过于庞大了?
部署了应用后的平台启动时间
JBoss AS 7 约 2 秒
Glassfish V3 约 4 秒
Tomcat 6 + Spring 约 4 秒
Java EE 6 WAR 文件 < 100kb
9
但是我需要依赖注入
• Java EE 6 引入 CDI
• 更强大的上下文 DI 模型
• 让平台能够以标准方式扩展
10
但是我需要 AOP !
是吗?
难道您想让你的代码变
得杂乱并难以理解吗?
或者,您仅仅是使用了
轻量级的 AOP , 即
Spring AOP 或 Java
EE 规范中的拦截器?
11
我是否需要重型工具?
12
功能比较
功能 Spring JavaEE
依赖注入 Spring 容器 CDI
事务 AOP/ 批注 EJB
Web 框架 Spring Web MVC JSF
AOP AspectJ (限于 Spring bean ) 拦截器
消息处理 JMS JMS / CDI
数据访问 JPA / JDBC 模板 / 其他 ORM JPA
RESTful Web 服务 Spring Web MVC (3.0) JAX-RS
集成测试 Spring 测试框架 Arquillian *
* 不是 Java EE 规范的一部分
13
这一切均可使用普通轻
量级 Java EE 完成
14
rm -Rf spring*
? 15
当然,这将十
分有趣!
实际情况呢?
16
典型的老版本 Spring 应用
大量复杂的 XML 配置文件,无法使用注解
旧式 / 过时的 ORM 解决方案
( JDBC 模板、 Kodo 、 Toplink 等)
过时的基于 Web MVC 的扩展
( SimpleFormController 等)
17
迁移路径
1. 升级 Spring 版本
2. 替换 Spring 内的旧框架( ORM 、 Web 框
架)
3. Spring 和 Java EE 容器并存
4. 完全替换 Spring
5. 移除 Spring 容器
18
迁移路径
1. 升级 Spring 版本
2. 替换 Spring 内的旧框架( ORM 、 Web 框
架)
3. Spring 和 Java EE 容器并存
4. 完全替换 Spring
5. 移除 Spring 容器
19
升级 Spring 版本
升级 Spring 运行时(替换 JAR 文件)
无代码 / 配置变更
20
迁移路径
1. 升级 Spring 版本
2. 替换 Spring 内的旧框架( ORM 、 Web 框
架)
3. Spring 和 Java EE 容器并存
4. 完全替换 Spring
5. 移除 Spring 容器
21
替换 Spring 内的旧框架
表示层
数据 / 集
成层
Web MVC
任务
Spring JDBC 模
板
Kodo
@AutoWired
业务层
JMS bean
@AutoWired
@AutoWired
JPA
JSF
尚未触碰特定于 Spring
的 API
Spring bean
22
迁移路径
1. 升级 Spring 版本
2. 替换 Spring 内的旧框架( ORM 、 Web 框
架)
3. Spring 和 Java EE 容器并存
4. 完全替换 Spring
5. 移除 Spring 容器
23
myapp.war
Spring 容器
Servlet 容器
Spring 应用程序
Spring bean
Spring bean
TXTX
管
理
器
管
理
器
AOPAOP
ORMORM
24
Java EE 6 应用服务器
CDI / EJB 容器
myapp.war
CDI bean
会话 bean
TXTX
管
理
器
管
理
器
安
全
性
安
全
性
拦
截
器
拦
截
器
JPAJPA
Java EE 应用程序
25
Java EE 6 应用服务器
CDI / EJB 容器
myapp.war
CDI bean
会话 bean
TXTX
管
理
器
管
理
器
安
全
性
安
全
性
拦
截
器
拦
截
器
JPAJPA
Spring 容器
Spring
bean
Spring
bean
TXTX
管
理
器
管
理
器
AOPAOP
ORMORM
混合在一起
26
在 Java EE 容器内运行 Spring
表示层
数据 /
集成层
Spring bean 任务
Spring JDBC
模板
业务层
JMS bean
@AutoWired
@AutoWired
JPA
JSF
27
Spring 和 Java EE 容器并存
表示层
数据 /
集成层
Spring bean 任务
Spring JDBC 模
板
业务层
JMS bean
@AutoWired
@AutoWired
JPA
JSF
EJB CDI
@Inject
@Inject
28
Spring DAO
29
Spring 配置
30
JSF / CDI bean
在此,我们不想了解 Spring
31
用 CDI 封装 Spring
编写 CDI 扩展
引导 Spring 容器
在 Spring 容器中查找 Spring Bean 并在
CDI 上下文中发布
32
CDI 扩展示例
33
迁移路径
1. 升级 Spring 版本
2. 替换 Spring 内的旧框架( ORM 、 Web 框架)
3. Spring 和 Java EE 容器并存
4. 完全替换 Spring
5. 移除 Spring 容器
34
完全替换 Spring
表示层
数据 /
集成层
Spring bean 任务
Spring JDBC 模
板
业务层
JMS bean
@AutoWired
@AutoWired
JPA
JSF
EJB CDI
@Inject
@Inject
35
完全替换 Spring
表示层
数据 /
集成层
EJB 计时器业务层
MDB
@AutoWired
@AutoWired
JPA
JSF
EJB CDI
@Inject
@Inject
Spring JDBC 模
板
36
TX 层
将 Spring TX 和 DAO 迁移到 EJB
TX 管理器在应用服务器内
默认情况下, EJB 是事务性的
EJB 集成了 JPA
37
您是说 EJB 很好吗?
一点没错!
EJB 只是容器管理的 POJO
与 Spring bean 一样,而且不需要容器配置……
38
DAO
Spring
39
DAO 配置
40
Java EE 替代方案
EJB
41
处理惰性加载
许多 Spring 应用程序使用 Open-
EntityManager-In-View 模式
EJB 具有扩展的持久性上下文
更明确、更强大
42
LazyInitializationException 异常
43
修复惰性加载问题
只要 bean 存在就保持 EntityManager 可用
44
沉迷于模板?
如果使用了 JDBC 模板将会怎样?
让我们开始是否使用 ORM 的老生常谈
第 1 阶段:拒绝
第 2 阶段:最终将会完成迁移 ;-)
45
使用 Java EE 内的
JDBC 模板
可用简单的生成器方法注入
可能是因为它没有依赖 Spring 容器
尽管有一些额外的依赖项
46
模板生成器示例
47
迁移路径
1. 升级 Spring 版本
2. 替换 Spring 内的旧框架( ORM 、 Web 框架)
3. Spring 和 Java EE 容器并存
4. 完全替换 Spring
5. 移除 Spring 容器
48
移除依赖项
类路径只需要包含 API 所需的类,并不需要
包含框架类
使得从大约 40 个依赖性减少到 1 个
49
测试方面如何?
Spring 在测试方面一直很出色
DI 让单元测试可行
Spring 测试框架让 Spring 容器内测试可行
灵活配置能满足多环境下测试的需要
50
如何进行测试?
51
Arquillian
使用 API 创建微部署
部署到真正应用服务器
在服务器中运行测试
52
Arquillian 示例
53
这一切都值得吗?
55
Spring 之后还有后
来者吗?
我们相信,创新空间总是存在的
最好是通过开源实现
并且,如果有更为杰出的技术发展出来了,我
们会将其整合到标准规范中
56
还有更多!
• JBoss 网站上的 4 部分文章系列
• Pet Clinic 示例应用程序的逐步迁移
• http://www.howtojboss.com
57
谢谢!

Weitere ähnliche Inhalte

Andere mochten auch

Microservices for Mortals
Microservices for MortalsMicroservices for Mortals
Microservices for MortalsBert Ertman
 
JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6Bert Ertman
 
Building Modular Cloud Applications in Java - Lessons Learned
Building Modular Cloud Applications in Java - Lessons LearnedBuilding Modular Cloud Applications in Java - Lessons Learned
Building Modular Cloud Applications in Java - Lessons LearnedBert Ertman
 
VJUG - Building Modular Java Applications in the Cloud Age
VJUG - Building Modular Java Applications in the Cloud AgeVJUG - Building Modular Java Applications in the Cloud Age
VJUG - Building Modular Java Applications in the Cloud AgeBert Ertman
 
The Eff monad, one monad to rule them all
The Eff monad, one monad to rule them allThe Eff monad, one monad to rule them all
The Eff monad, one monad to rule them allEric Torreborre
 
How Hootsuite Manages its Growing Microservice Landscape - Adam Arsenault
How Hootsuite Manages its Growing Microservice Landscape - Adam ArsenaultHow Hootsuite Manages its Growing Microservice Landscape - Adam Arsenault
How Hootsuite Manages its Growing Microservice Landscape - Adam ArsenaultAmbassador Labs
 
Microservices Tutorial Session at JavaOne 2016
Microservices Tutorial Session at JavaOne 2016Microservices Tutorial Session at JavaOne 2016
Microservices Tutorial Session at JavaOne 2016Jason Swartz
 
HTTP/2 and Java: Current Status
HTTP/2 and Java: Current StatusHTTP/2 and Java: Current Status
HTTP/2 and Java: Current StatusSimone Bordet
 
Engineering and Autonomy in the Age of Microservices - Nic Benders, New Relic
Engineering and Autonomy in the Age of Microservices - Nic Benders, New RelicEngineering and Autonomy in the Age of Microservices - Nic Benders, New Relic
Engineering and Autonomy in the Age of Microservices - Nic Benders, New RelicAmbassador Labs
 
Designing and building a micro-services architecture. Stairway to heaven or a...
Designing and building a micro-services architecture. Stairway to heaven or a...Designing and building a micro-services architecture. Stairway to heaven or a...
Designing and building a micro-services architecture. Stairway to heaven or a...Sander Hoogendoorn
 
Servlet 3.1 Async I/O
Servlet 3.1 Async I/OServlet 3.1 Async I/O
Servlet 3.1 Async I/OSimone Bordet
 
Rethinking it for digital transformation
Rethinking it for digital transformationRethinking it for digital transformation
Rethinking it for digital transformationMuleSoft
 
Microservices are the Future! (...and always will be) - Josh Holtzman, PayPal...
Microservices are the Future! (...and always will be) - Josh Holtzman, PayPal...Microservices are the Future! (...and always will be) - Josh Holtzman, PayPal...
Microservices are the Future! (...and always will be) - Josh Holtzman, PayPal...Ambassador Labs
 
Microservices OSGi-running-with-apache-karaf
Microservices OSGi-running-with-apache-karafMicroservices OSGi-running-with-apache-karaf
Microservices OSGi-running-with-apache-karafAchim Nierbeck
 
Developing applications with a microservice architecture (svcc)
Developing applications with a microservice architecture (svcc)Developing applications with a microservice architecture (svcc)
Developing applications with a microservice architecture (svcc)Chris Richardson
 
Microservices at Spotify
Microservices at SpotifyMicroservices at Spotify
Microservices at SpotifyKevin Goldsmith
 
Microservices: Decomposing Applications for Deployability and Scalability (ja...
Microservices: Decomposing Applications for Deployability and Scalability (ja...Microservices: Decomposing Applications for Deployability and Scalability (ja...
Microservices: Decomposing Applications for Deployability and Scalability (ja...Chris Richardson
 
MicroService Architecture
MicroService ArchitectureMicroService Architecture
MicroService ArchitectureFred George
 

Andere mochten auch (20)

Microservices for Mortals
Microservices for MortalsMicroservices for Mortals
Microservices for Mortals
 
JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6
 
Building Modular Cloud Applications in Java - Lessons Learned
Building Modular Cloud Applications in Java - Lessons LearnedBuilding Modular Cloud Applications in Java - Lessons Learned
Building Modular Cloud Applications in Java - Lessons Learned
 
VJUG - Building Modular Java Applications in the Cloud Age
VJUG - Building Modular Java Applications in the Cloud AgeVJUG - Building Modular Java Applications in the Cloud Age
VJUG - Building Modular Java Applications in the Cloud Age
 
The Eff monad, one monad to rule them all
The Eff monad, one monad to rule them allThe Eff monad, one monad to rule them all
The Eff monad, one monad to rule them all
 
How Hootsuite Manages its Growing Microservice Landscape - Adam Arsenault
How Hootsuite Manages its Growing Microservice Landscape - Adam ArsenaultHow Hootsuite Manages its Growing Microservice Landscape - Adam Arsenault
How Hootsuite Manages its Growing Microservice Landscape - Adam Arsenault
 
Digital Transformation and Microservices
Digital Transformation and MicroservicesDigital Transformation and Microservices
Digital Transformation and Microservices
 
Microservices Tutorial Session at JavaOne 2016
Microservices Tutorial Session at JavaOne 2016Microservices Tutorial Session at JavaOne 2016
Microservices Tutorial Session at JavaOne 2016
 
HTTP/2 and Java: Current Status
HTTP/2 and Java: Current StatusHTTP/2 and Java: Current Status
HTTP/2 and Java: Current Status
 
Engineering and Autonomy in the Age of Microservices - Nic Benders, New Relic
Engineering and Autonomy in the Age of Microservices - Nic Benders, New RelicEngineering and Autonomy in the Age of Microservices - Nic Benders, New Relic
Engineering and Autonomy in the Age of Microservices - Nic Benders, New Relic
 
Designing and building a micro-services architecture. Stairway to heaven or a...
Designing and building a micro-services architecture. Stairway to heaven or a...Designing and building a micro-services architecture. Stairway to heaven or a...
Designing and building a micro-services architecture. Stairway to heaven or a...
 
Servlet 3.1 Async I/O
Servlet 3.1 Async I/OServlet 3.1 Async I/O
Servlet 3.1 Async I/O
 
Rethinking it for digital transformation
Rethinking it for digital transformationRethinking it for digital transformation
Rethinking it for digital transformation
 
Microservices are the Future! (...and always will be) - Josh Holtzman, PayPal...
Microservices are the Future! (...and always will be) - Josh Holtzman, PayPal...Microservices are the Future! (...and always will be) - Josh Holtzman, PayPal...
Microservices are the Future! (...and always will be) - Josh Holtzman, PayPal...
 
Microservices OSGi-running-with-apache-karaf
Microservices OSGi-running-with-apache-karafMicroservices OSGi-running-with-apache-karaf
Microservices OSGi-running-with-apache-karaf
 
Developing applications with a microservice architecture (svcc)
Developing applications with a microservice architecture (svcc)Developing applications with a microservice architecture (svcc)
Developing applications with a microservice architecture (svcc)
 
Microservices at Spotify
Microservices at SpotifyMicroservices at Spotify
Microservices at Spotify
 
Microservices: Decomposing Applications for Deployability and Scalability (ja...
Microservices: Decomposing Applications for Deployability and Scalability (ja...Microservices: Decomposing Applications for Deployability and Scalability (ja...
Microservices: Decomposing Applications for Deployability and Scalability (ja...
 
MicroService Architecture
MicroService ArchitectureMicroService Architecture
MicroService Architecture
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 

Ähnlich wie Migrating from Spring Applications to Java EE 6 [CHINESE VERSION]

GlassFish特性介绍
GlassFish特性介绍GlassFish特性介绍
GlassFish特性介绍Jim Jiang
 
Java2新觀念教本投影片ch1
Java2新觀念教本投影片ch1Java2新觀念教本投影片ch1
Java2新觀念教本投影片ch15045033
 
给学习J2 Ee的朋友一些值得研究的开源项目
给学习J2 Ee的朋友一些值得研究的开源项目给学习J2 Ee的朋友一些值得研究的开源项目
给学习J2 Ee的朋友一些值得研究的开源项目yiditushe
 
Spring boot 简介
Spring boot 简介Spring boot 简介
Spring boot 简介宇帆 盛
 
Java 推荐读物
Java 推荐读物Java 推荐读物
Java 推荐读物yiditushe
 
Big Java, Big Data
Big Java, Big DataBig Java, Big Data
Big Java, Big DataKuo-Chun Su
 
中远公司 Java培训资料
中远公司  Java培训资料中远公司  Java培训资料
中远公司 Java培训资料yiditushe
 
Java Tutorial:Learn Java in 06:00:00
Java Tutorial:Learn Java in 06:00:00Java Tutorial:Learn Java in 06:00:00
Java Tutorial:Learn Java in 06:00:00Justin Lin
 
中远公司 Java培训资料
中远公司  Java培训资料中远公司  Java培训资料
中远公司 Java培训资料yiditushe
 
漫谈php和java
漫谈php和java漫谈php和java
漫谈php和javasulong
 
IKVM.NET 深入敵營的 Java
IKVM.NET 深入敵營的 JavaIKVM.NET 深入敵營的 Java
IKVM.NET 深入敵營的 Java建興 王
 
Spring 2.0 技術手冊第十章 - 專案:線上書籤
Spring 2.0 技術手冊第十章 - 專案:線上書籤Spring 2.0 技術手冊第十章 - 專案:線上書籤
Spring 2.0 技術手冊第十章 - 專案:線上書籤Justin Lin
 
D2_Node在淘宝的应用实践
D2_Node在淘宝的应用实践D2_Node在淘宝的应用实践
D2_Node在淘宝的应用实践Jackson Tian
 
基于Ivy ant的java构建初探
基于Ivy ant的java构建初探基于Ivy ant的java构建初探
基于Ivy ant的java构建初探Anson Yang
 
第一章 概述和Jdk的安装和配置
第一章 概述和Jdk的安装和配置第一章 概述和Jdk的安装和配置
第一章 概述和Jdk的安装和配置yinmei1983
 
2. java introduction
2. java introduction2. java introduction
2. java introductionnetdbncku
 
Asp.net mvc 從無到有 -twMVC#2
Asp.net mvc 從無到有 -twMVC#2Asp.net mvc 從無到有 -twMVC#2
Asp.net mvc 從無到有 -twMVC#2twMVC
 

Ähnlich wie Migrating from Spring Applications to Java EE 6 [CHINESE VERSION] (20)

GlassFish特性介绍
GlassFish特性介绍GlassFish特性介绍
GlassFish特性介绍
 
Java2新觀念教本投影片ch1
Java2新觀念教本投影片ch1Java2新觀念教本投影片ch1
Java2新觀念教本投影片ch1
 
给学习J2 Ee的朋友一些值得研究的开源项目
给学习J2 Ee的朋友一些值得研究的开源项目给学习J2 Ee的朋友一些值得研究的开源项目
给学习J2 Ee的朋友一些值得研究的开源项目
 
Spring boot 简介
Spring boot 简介Spring boot 简介
Spring boot 简介
 
Ejb方面
Ejb方面Ejb方面
Ejb方面
 
Java 推荐读物
Java 推荐读物Java 推荐读物
Java 推荐读物
 
Big Java, Big Data
Big Java, Big DataBig Java, Big Data
Big Java, Big Data
 
中远公司 Java培训资料
中远公司  Java培训资料中远公司  Java培训资料
中远公司 Java培训资料
 
beidakejian
beidakejianbeidakejian
beidakejian
 
Java Tutorial:Learn Java in 06:00:00
Java Tutorial:Learn Java in 06:00:00Java Tutorial:Learn Java in 06:00:00
Java Tutorial:Learn Java in 06:00:00
 
中远公司 Java培训资料
中远公司  Java培训资料中远公司  Java培训资料
中远公司 Java培训资料
 
Jni文档
Jni文档Jni文档
Jni文档
 
漫谈php和java
漫谈php和java漫谈php和java
漫谈php和java
 
IKVM.NET 深入敵營的 Java
IKVM.NET 深入敵營的 JavaIKVM.NET 深入敵營的 Java
IKVM.NET 深入敵營的 Java
 
Spring 2.0 技術手冊第十章 - 專案:線上書籤
Spring 2.0 技術手冊第十章 - 專案:線上書籤Spring 2.0 技術手冊第十章 - 專案:線上書籤
Spring 2.0 技術手冊第十章 - 專案:線上書籤
 
D2_Node在淘宝的应用实践
D2_Node在淘宝的应用实践D2_Node在淘宝的应用实践
D2_Node在淘宝的应用实践
 
基于Ivy ant的java构建初探
基于Ivy ant的java构建初探基于Ivy ant的java构建初探
基于Ivy ant的java构建初探
 
第一章 概述和Jdk的安装和配置
第一章 概述和Jdk的安装和配置第一章 概述和Jdk的安装和配置
第一章 概述和Jdk的安装和配置
 
2. java introduction
2. java introduction2. java introduction
2. java introduction
 
Asp.net mvc 從無到有 -twMVC#2
Asp.net mvc 從無到有 -twMVC#2Asp.net mvc 從無到有 -twMVC#2
Asp.net mvc 從無到有 -twMVC#2
 

Migrating from Spring Applications to Java EE 6 [CHINESE VERSION]

Hinweis der Redaktion

  1. Het maakt eigenlijk niet uit of je van old school of new school Spring migreert, de argumenten zijn hetzelfde. Voor old school is meer werk nodig, maar is er ook meer reden toe. Van new school is het waarschijnlijk een kleine stap, zeker als je al JPA/JSF etc. gebruikt.
  2. 3 opties: niks doen / nieuwe api ’ s gebruiken maar spring leidend houden / all-the-way