没有合适的资源?快使用搜索试试~ 我知道了~
首页精通Java EE 6:Oracle官方教程解析
精通Java EE 6:Oracle官方教程解析
需积分: 9 1 下载量 88 浏览量
更新于2024-07-26
收藏 12.94MB PDF 举报
"Java Tutorial 6 是一份关于Java EE 6开发的全面指南,由Oracle公司官方提供。这份教程旨在帮助初学者至熟练者掌握Java平台企业版的开发技术,并包含文档和示例代码。教程内容涵盖版权和许可信息,其中示例代码遵循Berkeley许可证。用户仅可将教程用于学习和了解Java EE平台,未经许可不得进行复制、修改或分发。"
在Java EE 6教程中,开发者可以学习到一系列关键知识点:
1. **基础概念**:首先,你会了解到Java EE平台的核心概念,包括它为何被设计出来以及如何作为一个服务导向架构支持企业级应用程序的开发。
2. **组件模型**:Java EE 6引入了更轻量级的组件模型,如JavaServer Faces (JSF) 2.0,它简化了Web用户界面的构建。此外,还包括Enterprise JavaBeans (EJB) 3.1,其降低了EJB的使用门槛,使得无状态和有状态会话bean的使用更加简单。
3. **依赖注入(DI)**:Java EE 6支持注解驱动的依赖注入,通过@EJB、@Inject和@ManagedBean等注解,开发者可以更容易地管理和组装应用程序的组件。
4. **持久化**:Java Persistence API (JPA) 2.0提供了对数据库对象关系映射(ORM)的支持,使得数据库操作更加便捷。
5. **Web服务**:教程会讲解如何使用Java API for RESTful Web Services (JAX-RS)创建RESTful服务,以及使用Java API for XML Web Services (JAX-WS)构建SOAP Web服务。
6. **事务管理**:Java EE 6提供了一种声明式事务管理方式,开发者可以通过注解来定义事务边界,例如@Transactional。
7. **调度和并发**:EJB 3.1中的定时器服务允许开发者安排任务执行,而并发API则帮助处理多线程环境下的复杂性。
8. **模块化和部署**:Java EE 6支持模块化的应用部署,例如war和ear文件格式,以及Web应用程序和企业应用程序的打包和部署。
9. **测试和调试**:教程还将介绍如何使用集成测试框架如Arquillian,以及如何利用Java EE的内置诊断工具进行问题排查。
10. **安全**:Java EE 6提供了多种安全机制,包括角色基的访问控制(RBAC)、容器管理的身份验证和授权,以及SSL/TLS支持。
通过这份教程,开发者不仅能够深入理解Java EE 6的各个组件和它们的工作原理,还能学会如何实际运用这些技术来构建高效、可扩展的企业级应用。同时,示例代码的提供使学习过程更具实践性,帮助开发者快速上手。
The Contents of an Enterprise Bean ............................................................................................... 447
Packaging Enterprise Beans in EJB JAR Modules .................................................................. 447
Packaging Enterprise Beans in WAR Modules ...................................................................... 448
Naming Conventions for Enterprise Beans ................................................................................... 449
The Lifecycles of Enterprise Beans .................................................................................................. 450
The Lifecycle of a Stateful Session Bean .................................................................................. 450
The Lifecycle of a Stateless Session Bean ................................................................................. 451
The Lifecycle of a Singleton Session Bean ............................................................................... 451
The Lifecycle of a Message-Driven Bean ................................................................................. 452
Further Information about Enterprise Beans ................................................................................ 453
23 Getting Started with Enterprise Beans .......................................................................................... 455
Creating the Enterprise Bean ........................................................................................................... 455
Coding the Enterprise Bean Class ............................................................................................ 456
Creating the converter Web Client ........................................................................................ 456
Running the converter Example ............................................................................................ 457
Modifying the Java EE Application ................................................................................................. 458
▼ To Modify a Class File ................................................................................................................ 458
24 Running the Enterprise Bean Examples ........................................................................................ 461
The cart Example ............................................................................................................................. 461
The Business Interface ............................................................................................................... 462
Session Bean Class ..................................................................................................................... 463
The @Remove Method ................................................................................................................. 466
Helper Classes ............................................................................................................................. 466
Running the cart Example ....................................................................................................... 466
A Singleton Session Bean Example: counter ................................................................................. 468
Creating a Singleton Session Bean ........................................................................................... 468
The Architecture of the counter Example .............................................................................. 472
Running the counter Example ................................................................................................ 475
A Web Service Example: helloservice ......................................................................................... 476
The Web Service Endpoint Implementation Class ................................................................ 476
Stateless Session Bean Implementation Class ........................................................................ 477
Running the helloservice Example ...................................................................................... 477
Using the Timer Service .................................................................................................................... 479
Contents
The Java EE 6 Tutorial • January 201316
Creating Calendar-Based Timer Expressions ........................................................................ 479
Programmatic Timers ............................................................................................................... 482
Automatic Timers ...................................................................................................................... 483
Canceling and Saving Timers ................................................................................................... 484
Getting Timer Information ...................................................................................................... 485
Transactions and Timers .......................................................................................................... 485
The timersession Example ..................................................................................................... 485
Running the timersession Example ...................................................................................... 488
Handling Exceptions ......................................................................................................................... 489
25 A Message-Driven Bean Example ...................................................................................................491
Overview of the simplemessage Example ..................................................................................... 491
The simplemessage Application Client ......................................................................................... 492
The Message-Driven Bean Class ..................................................................................................... 493
The onMessage Method ............................................................................................................. 494
Running the simplemessage Example ........................................................................................... 495
Administered Objects for the simplemessage Example ....................................................... 495
▼ To Run the simplemessage Application Using NetBeans IDE ............................................ 496
▼ To Run the simplemessage Application Using Ant .............................................................. 496
Removing the Administered Objects for the simplemessage Example .............................. 497
26 Using the Embedded Enterprise Bean Container ........................................................................ 499
Overview of the Embedded Enterprise Bean Container ............................................................... 499
Developing Embeddable Enterprise Bean Applications ............................................................... 499
Running Embedded Applications ............................................................................................ 500
Creating the Enterprise Bean Container ................................................................................. 500
Looking Up Session Bean References ...................................................................................... 502
Shutting Down the Enterprise Bean Container ..................................................................... 502
The standalone Example Application ........................................................................................... 502
▼ To Run the standalone Example Application ....................................................................... 503
27 Using Asynchronous Method Invocation in Session Beans ....................................................... 505
Asynchronous Method Invocation ................................................................................................. 505
Creating an Asynchronous Business Method ......................................................................... 506
Contents
17
Calling Asynchronous Methods from Enterprise Bean Clients ........................................... 507
The async Example Application ...................................................................................................... 508
Architecture of the async Example Application .................................................................... 508
Running the async Example ..................................................................................................... 509
Part V Contexts and Dependency Injection for the Java EE Platform ...................................................513
28 Introduction to Contexts and Dependency Injection for the Java EE Platform .......................515
Overview of CDI ................................................................................................................................ 516
About Beans ....................................................................................................................................... 517
About CDI Managed Beans .............................................................................................................. 517
Beans as Injectable Objects ............................................................................................................... 518
Using Qualiers ................................................................................................................................. 519
Injecting Beans ................................................................................................................................... 520
Using Scopes ...................................................................................................................................... 520
Overriding the Scope of a Bean at the Point of Injection .............................................................. 522
Giving Beans EL Names .................................................................................................................... 522
Adding Setter and Getter Methods .................................................................................................. 523
Using a Managed Bean in a Facelets Page ....................................................................................... 524
Injecting Objects by Using Producer Methods .............................................................................. 524
Conguring a CDI Application ....................................................................................................... 525
Using the @PostConstruct and @PreDestroy Annotations With CDI Managed Bean
Classes ................................................................................................................................................. 525
▼ To Initialize a Managed Bean Using the @PostConstruct Annotation .............................. 525
▼ To Prepare for the Destruction of a Managed Bean Using the @PreDestroy Annotation 526
Further Information about CDI ...................................................................................................... 526
29 Running the Basic Contexts and Dependency Injection Examples .......................................... 527
The simplegreeting CDI Example ................................................................................................ 527
The simplegreeting Source Files ........................................................................................... 528
The Facelets Template and Page ............................................................................................... 528
Conguration Files .................................................................................................................... 529
Running the simplegreeting Example .................................................................................. 530
The guessnumber CDI Example ...................................................................................................... 531
The guessnumber Source Files ................................................................................................. 532
Contents
The Java EE 6 Tutorial • January 201318
The Facelets Page ....................................................................................................................... 536
Running the guessnumber Example ........................................................................................ 537
30 Contexts and Dependency Injection for the Java EE Platform: AdvancedTopics ...................539
Using Alternatives in CDI Applications ......................................................................................... 539
Using Specialization .................................................................................................................. 540
Using Producer Methods, Producer Fields, and Disposer Methods in CDI Applications ....... 541
Using Producer Methods .......................................................................................................... 542
Using Producer Fields to Generate Resources ........................................................................ 543
Using a Disposer Method .......................................................................................................... 543
Using Predened Beans in CDI Applications ................................................................................ 544
Using Events in CDI Applications ................................................................................................... 545
Dening Events .......................................................................................................................... 545
Using Observer Methods to Handle Events ............................................................................ 545
Firing Events ............................................................................................................................... 546
Using Interceptors in CDI Applications ......................................................................................... 547
Using Decorators in CDI Applications ........................................................................................... 549
Using Stereotypes in CDI Applications .......................................................................................... 550
31 Running the Advanced Contexts and Dependency Injection Examples ................................. 553
The encoder Example: Using Alternatives .................................................................................... 553
The Coder Interface and Implementations ............................................................................. 554
The encoder Facelets Page and Managed Bean ...................................................................... 554
Running the encoder Example ................................................................................................ 556
The producermethods Example: Using a Producer Method To Choose a Bean
Implementation ................................................................................................................................. 558
Components of the producermethods Example .................................................................... 559
Running the producermethods Example ................................................................................ 560
The producerfields Example: Using Producer Fields to Generate Resources ........................ 561
The Producer Field for the producerfields Example .......................................................... 561
The producerfields Entity and Session Bean ...................................................................... 563
The producerfields Facelets Pages and Managed Bean ..................................................... 564
Running the producerfields Example .................................................................................. 566
The billpayment Example: Using Events and Interceptors ........................................................ 568
The PaymentEvent Event Class ................................................................................................ 568
Contents
19
The PaymentHandler Event Listener ....................................................................................... 568
The billpayment Facelets Pages and Managed Bean ............................................................ 569
The LoggedInterceptor Interceptor Class ............................................................................ 572
Running the billpayment Example ........................................................................................ 573
The decorators Example: Decorating a Bean ............................................................................... 574
Components of the decorators Example .............................................................................. 574
Running the decorators Example .......................................................................................... 575
Part VI Persistence ..........................................................................................................................................577
32 Introduction to the Java Persistence API ...................................................................................... 579
Entities ................................................................................................................................................ 579
Requirements for Entity Classes .............................................................................................. 580
Persistent Fields and Properties in Entity Classes .................................................................. 580
Primary Keys in Entities ............................................................................................................ 585
Multiplicity in Entity Relationships ......................................................................................... 587
Direction in Entity Relationships ............................................................................................. 587
Embeddable Classes in Entities ................................................................................................ 590
Entity Inheritance .............................................................................................................................. 591
Abstract Entities ......................................................................................................................... 591
Mapped Superclasses ................................................................................................................. 591
Non-Entity Superclasses ........................................................................................................... 592
Entity Inheritance Mapping Strategies .................................................................................... 592
Managing Entities .............................................................................................................................. 595
The EntityManager Interface .................................................................................................. 595
Persistence Units ........................................................................................................................ 599
Querying Entities ............................................................................................................................... 600
Further Information about Persistence .......................................................................................... 601
33 Running the Persistence Examples ................................................................................................603
The order Application ...................................................................................................................... 603
Entity Relationships in the order Application ....................................................................... 604
Primary Keys in the order Application ................................................................................... 606
Entity Mapped to More Than One Database Table ............................................................... 610
Contents
The Java EE 6 Tutorial • January 201320
剩余1009页未读,继续阅读
2018-11-13 上传
2022-09-21 上传
2007-05-19 上传
2021-03-16 上传
2009-12-07 上传
2021-07-05 上传
393 浏览量
x_aaron
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功