Spring enterprise recipes: a problem-solution approach 1430224975, 9781430224976

The Spring Framework is the de-facto leading open source agile enterprise Java meta-framework and serves as an alternati

336 54 2MB

English Pages 495 Year 2009

Report DMCA / Copyright

DOWNLOAD PDF FILE

Table of contents :
Books for Professionals......Page 2
Contents at a Glance......Page 7
Contents......Page 9
About the Authors......Page 15
About the Technical Reviewer......Page 17
Acknowledgments......Page 19
Who This Book Is For......Page 21
How This Book Is Structured......Page 22
Contacting the Authors......Page 23
Solution......Page 25
Getting Beans from the IoC Container......Page 26
Creating the Bean Class......Page 27
Creating the Bean Configuration File......Page 28
Declaring Beans in the Bean Configuration File......Page 29
Defining Bean Properties by Shortcut......Page 30
Lists, Arrays, and Sets......Page 31
Maps and Properties......Page 33
Solution......Page 36
Auto-Wiring by Type......Page 37
Auto-Wiring by Constructor......Page 38
Auto-Wiring by Auto-Detection......Page 39
Solution......Page 40
Auto-Wiring a Single Bean of Compatible Type......Page 41
Auto-Wiring All Beans of Compatible Type......Page 43
Auto-Wiring by Type with Qualifiers......Page 44
Auto-Wiring by Name......Page 46
How It Works......Page 47
Scanning Components Automatically......Page 49
Filtering Components to Scan......Page 51
1-6. Setting Bean Scopes Problem......Page 52
How It Works......Page 53
Solution......Page 55
How It Works......Page 56
Setting the init-method and destroy-method Attributes......Page 58
Annotating the @PostConstruct and @PreDestroy Annotations......Page 59
How It Works......Page 60
Solution......Page 62
How It Works......Page 63
Injecting Resources......Page 64
How It Works......Page 65
Solution......Page 67
Before Advices......Page 68
After Advices......Page 69
After Returning Advices......Page 70
After Throwing Advices......Page 71
Around Advices......Page 72
How It Works......Page 73
Method Signature Patterns......Page 75
Type Signature Patterns......Page 77
Combining Pointcut Expressions......Page 78
Declaring Pointcut Parameters......Page 79
How It Works......Page 80
How It Works......Page 83
Summary......Page 85
What’s New in Spring 3.0?......Page 87
What Is REST?......Page 88
How It Works......Page 90
2-2. Using Java 5 Syntax in Spring Problem......Page 91
BeanFactory and FactoryBean......Page 92
ApplicationContext Events......Page 93
How It Works......Page 94
Java SE......Page 95
Spring’s Solution......Page 97
Features of the Language Syntax......Page 103
Uses of the Language in Your Configurations......Page 106
Using the Spring Expression Language Parser......Page 107
How It Works......Page 109
How It Works......Page 110
Data Access......Page 115
Setting Up the Application Database......Page 116
Understanding the Data Access Object Design Pattern......Page 117
Implementing the DAO with JDBC......Page 118
Configuring a Data Source in Spring......Page 120
3-1. Using a JDBC Template to Update a Database Problem......Page 122
Updating a Database with a Statement Creator......Page 123
Updating a Database with a SQL Statement and Parameter Values......Page 125
Batch Updating a Database......Page 126
3-2. Using a JDBC Template to Query a Database Problem......Page 127
Extracting Data with a Row Mapper......Page 128
Querying for Multiple Rows......Page 130
Querying for a Single Value......Page 131
Injecting a JDBC Template......Page 133
Extending the JdbcDaoSupport Class......Page 134
Using a Simple JDBC Template to Update a Database......Page 135
Using a Simple JDBC Template to Query a Database......Page 136
How It Works......Page 139
Solution......Page 141
Understanding Exception Handling in the Spring JDBC Framework......Page 142
Customizing Data Access Exception Handling......Page 145
3-7. Problems with Using ORM Frameworks Directly......Page 146
Persisting Objects Using the Hibernate API with Hibernate XML Mappings......Page 148
Persisting Objects Using the Hibernate API with JPA Annotations......Page 152
Persisting Objects Using JPA with Hibernate as the Engine......Page 153
Configuring a Hibernate Session Factory in Spring......Page 157
Configuring a JPA Entity Manager Factory in Spring......Page 161
Solution......Page 163
Using a Hibernate Template and a JPA Template......Page 164
Extending the Hibernate and JPA DAO Support Classes......Page 167
Solution......Page 169
How It Works......Page 170
3-11. Persisting Objects with JPA’s Context Injection Problem......Page 172
How It Works......Page 173
Summary......Page 176
Transaction Management in Spring......Page 177
4-1. Problems with Transaction Management......Page 178
Managing Transactions with JDBC Commit and Rollback......Page 184
Solution......Page 185
How It Works......Page 186
How It Works......Page 187
How It Works......Page 189
How It Works......Page 192
How It Works......Page 195
4-7. Setting the Propagation Transaction Attribute Problem......Page 196
Solution......Page 197
How It Works......Page 198
The REQUIRED Propagation Behavior......Page 199
The REQUIRES_NEW Propagation Behavior......Page 201
Solution......Page 202
How It Works......Page 204
The READ_UNCOMMITTED and READ_COMMITTED Isolation Levels......Page 205
The REPEATABLE_READ Isolation Level......Page 208
Setting the Isolation Level Attribute in Transaction Advices, Proxies, and APIs......Page 210
How It Works......Page 211
4-10. Setting the Timeout and Read-Only Transaction Attributes Problem......Page 212
How It Works......Page 213
How It Works......Page 214
Summary......Page 218
Solution......Page 219
How It Works......Page 220
Exposing an RMI Service......Page 221
Invoking an RMI Service......Page 222
Solution......Page 223
How It Works......Page 224
Creating EJB 2.x Components Without Spring’s Support......Page 225
Creating EJB 2.x Components with Spring’s Support......Page 228
How It Works......Page 230
Accessing EJB 2.x Components......Page 231
How It Works......Page 234
5-5. Accessing EJB 3.0 Components in Spring Problem......Page 235
Accessing EJB 3.0 Components with Spring’s Support......Page 236
Exposing a Hessian Service......Page 238
Exposing a Burlap Service......Page 240
Solution......Page 241
Contract-First Web Services......Page 242
5-8. Exposing and Invoking Web Services Using XFire Problem......Page 243
Exposing a Web Service Using XFire......Page 244
Inspecting the Generated WSDL File......Page 246
Exposing an Annotation-Based Web Service Using XFire......Page 248
Solution......Page 249
Creating Sample XML Messages......Page 250
Generating an XSD File from Sample XML Messages......Page 251
Previewing the Generated WSDL File......Page 252
5-10. Implementing Web Services Using Spring-WS Problem......Page 253
Solution......Page 254
Setting Up a Spring-WS Application......Page 255
Creating Service Endpoints......Page 256
Publishing the WSDL File......Page 258
How It Works......Page 259
Solution......Page 262
Creating Service Endpoints with XML Marshalling......Page 263
Invoking Web Services with XML Marshalling......Page 267
How It Works......Page 268
6-1. Exporting Spring Beans as JMX MBeans Problem......Page 271
How It Works......Page 272
Registering MBeans Without Spring’s Support......Page 274
Exporting Spring Beans as MBeans......Page 277
Exposing MBeans for Remote Access......Page 278
Assembling the Management Interface of MBeans......Page 279
Auto-Detecting MBeans by Annotations......Page 281
Publishing JMX Notifications......Page 283
Listening to JMX Notifications......Page 284
Accessing Remote MBeans Through an MBean Server Connection......Page 285
Accessing Remote MBeans Through an MBean Proxy......Page 287
How It Works......Page 288
Sending E-mail Using the JavaMail API......Page 290
Sending E-mail with Spring’s MailSender......Page 291
Defining an E-mail Template......Page 293
Sending MIME Messages......Page 294
Creating a Timer Task......Page 296
Using JDK Timer with Spring’s Support......Page 297
Solution......Page 298
Using Quartz Without Spring’s Support......Page 299
Using Quartz with Spring’s Support......Page 301
7-1. Sending and Receiving JMS Messages with Spring Problem......Page 305
How It Works......Page 306
Sending and Receiving Messages Without Spring’s Support......Page 307
Sending and Receiving Messages with Spring’s JMS Template......Page 312
Sending and Receiving Messages to and from a Default Destination......Page 315
7-2. Converting JMS Messages Problem......Page 317
Approach......Page 318
Solution......Page 320
Listening for JMS Messages with Message Listeners......Page 322
Listening for JMS Messages with POJOs......Page 324
Converting JMS Messages......Page 325
Using Spring’s JMS Schema......Page 327
Summary......Page 328
How It Works......Page 329
Solution......Page 330
Picking an Integration Style......Page 331
Building on an ESB Solution......Page 332
Building an MDP Using Spring Integration......Page 333
Using MessageHeaders for Fun and Profit......Page 337
Concerns in Dealing with a File System......Page 340
How it Works......Page 342
Modifying a Message’s Payload......Page 343
8-7. Error Handling Using Spring Integration Problem......Page 345
How It Works......Page 346
Building a Solution with Multiple Error channels......Page 347
Splitter......Page 348
Aggregators......Page 350
How It Works......Page 352
An Inbound Twitter Adapter......Page 353
A Simple MessageSource......Page 354
An Outbound Twitter Example......Page 360
How It Works......Page 363
How It Works......Page 364
SimpleMessagingGateway......Page 365
Breaking the Interface Dependency......Page 366
Summary......Page 370
Spring Batch......Page 371
Runtime Meta Model......Page 372
How It Works......Page 373
How It Works......Page 374
How It Works......Page 376
Solution......Page 377
How It Works......Page 378
The Job Configuration......Page 379
Input......Page 380
Output......Page 381
Writing a Custom ItemReader......Page 382
Writing a Custom ItemWriter......Page 383
How It Works......Page 384
Chaining Processors Together......Page 386
Transactions......Page 387
Solution......Page 388
Retry Template......Page 389
9-9. Controlling Step Execution Problem......Page 391
Concurrency......Page 392
Conditional Steps with Statuses......Page 393
Conditional Steps with Decisions......Page 394
Solution......Page 395
Accessing JobParameters......Page 396
Summary......Page 397
Distributed Spring......Page 399
Deploying a Simple Example with Terracotta......Page 401
Terracotta Architecture and Deployment......Page 406
How to Build a Terracotta XML Configuration File......Page 407
Approach......Page 409
Approach......Page 411
10-4. Load Balancing a Method Problem......Page 412
Approach......Page 413
Approach......Page 416
Solution......Page 418
Provisioning a Grid Node......Page 419
Node-Specific GridGain Configuration......Page 420
Summary......Page 423
jBPM and Spring......Page 425
Software Processes......Page 426
Approach......Page 429
Solution......Page 431
Approach......Page 434
The Application Context......Page 435
Approach......Page 440
Approach......Page 443
Summary......Page 446
OSGi and Spring......Page 447
Osgi and “JavaBeans™”......Page 448
The “Service”......Page 449
What is Maven?......Page 451
Installing Equinox......Page 452
Using the Service in a Client Bundle......Page 453
Approach......Page 456
12-3. How do I Export a Service Using Spring Dynamic Modules? Problem......Page 459
Approach......Page 460
Interfacing With the OSGi Runtime......Page 461
Ranking......Page 463
Service Attributes......Page 464
Approach......Page 465
You Want Spring To Process OSGi Annotations on Beans......Page 467
12-7. Using SpringSource dm Server Problem......Page 468
Approach......Page 469
Approach......Page 470
Summary......Page 471
A......Page 473
B......Page 474
C......Page 475
D......Page 477
E......Page 478
F......Page 479
I H......Page 480
J......Page 481
M......Page 483
N......Page 484
P......Page 485
Q......Page 486
R......Page 487
S......Page 488
T......Page 491
W......Page 492
X......Page 493

Spring enterprise recipes: a problem-solution approach
 1430224975, 9781430224976

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Recommend Papers