Mak | Spring Recipes | E-Book | www2.sack.de
E-Book

E-Book, Englisch, 736 Seiten

Mak Spring Recipes

A Problem-Solution Approach
1. ed
ISBN: 978-1-4302-0623-1
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark

A Problem-Solution Approach

E-Book, Englisch, 736 Seiten

ISBN: 978-1-4302-0623-1
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark



Spring Framework 2 Recipes by Gary Mak is the newest, latest Spring book from Apress and its Spring from the Source series. This book lets readers get down and dirty with Spring code for immediate copy/paste into the reader's specific application development project.

Gary Mak, founder and chief consultant of Meta-Archit Software Technology Limited, has been a technical architect and application developer on the enterprise Java platform for more than seven years. He is the author of the Apress books Spring Recipes: A Problem-Solution Approach and Pro SpringSource dm Server. In his career, Gary has developed a number of Java-based software projects, most of which are application frameworks, system infrastructures, and software tools. He enjoys designing and implementing the complex parts of software projects. Gary has a master's degree in computer science. His research interests include object-oriented technology, aspect-oriented technology, design patterns, software reuse, and domain-driven development. Gary specializes in building enterprise applications on technologies including Spring, Hibernate, JPA, JSF, Portlet, AJAX, and OSGi. He has been using the Spring Framework in his projects since Spring version 1.0. Gary has been an instructor of courses on enterprise Java, Spring, Hibernate, Web Services, and agile development. He has written a series of Spring and Hibernate tutorials as course materials, parts of which are open to the public, and they're gaining popularity in the Java community. In his spare time, he enjoys playing tennis and watching tennis competitions.

Mak Spring Recipes jetzt bestellen!

Autoren/Hrsg.


Weitere Infos & Material


1;Title Page;2
2;Copyright Page;3
3;Contents at a Glance;4
4;Table of Contents;6
5;About the Author;13
6;About the Technical Reviewers;14
7;Acknowledgments;15
8;Introduction;16
8.1;Who This Book Is For;16
8.2;How This Book Is Structured;17
8.3;Conventions;19
8.4;Prerequisites;19
8.5;Downloading the Code;19
8.6;Contacting the Author;19
9;PART 1 Core;20
10;CHAPTER 1 Inversion of Control and Containers;21
10.1;1-1.Using a Container toManageYour Components;22
10.1.1;Problem;22
10.1.2;Solution;22
10.1.3;How It Works;22
10.1.3.1;Separating Interface from Implementation;22
10.1.3.2;Employing a Container;24
10.2;1-2.Using a Service Locator to Reduce Lookup Complexity;27
10.2.1;Problem;27
10.2.2;Solution;27
10.2.3;How It Works;27
10.3;1-3. Applying Inversion of Control and Dependency Injection;29
10.3.1;Problem;29
10.3.2;Solution;29
10.3.3;How It Works;29
10.4;1-4.Understanding Different Types of Dependency Injection;31
10.4.1;Problem;31
10.4.2;Solution;31
10.4.3;How It Works;31
10.4.3.1;Setter Injection (Type 2 IoC);31
10.4.3.2;Constructor Injection (Type 3 IoC);32
10.4.3.3;Interface Injection (Type 1 IoC);33
10.5;1-5. Configuring a Container with a Configuration File;35
10.5.1;Problem;35
10.5.2;Solution;35
10.5.3;How It Works;35
10.6;1-6. Summary;38
11;CHAPTER 2 Introduction to Spring;39
11.1;2-1. Introducing the Spring Framework;39
11.1.1;Introducing Spring’s Modules;40
11.1.2;Introducing Spring’s Releases;41
11.1.3;Introducing Spring’s Projects;43
11.2;2-2. Installing the Spring Framework;44
11.2.1;Problem;44
11.2.2;Solution;44
11.2.3;How It Works;44
11.2.3.1;Installing JDK;44
11.2.3.2;Installing a Java IDE;44
11.2.3.3;Downloading and Installing Spring;44
11.2.3.4;Exploring Spring’s Installation Directory;45
11.3;2-3. Setting Up a Spring Project;46
11.3.1;Problem;46
11.3.2;Solution;46
11.3.3;How It Works;46
11.3.3.1;Setting Up the Classpath;46
11.3.3.2;Creating the Bean Configuration File;46
11.3.3.3;Using Beans from the Spring IoC Container;47
11.4;2-4. Installing Spring IDE;48
11.4.1;Problem;48
11.4.2;Solution;48
11.4.3;How It Works;48
11.5;2-5.Using Spring IDE’s Bean-Supporting Features;50
11.5.1;Problem;50
11.5.2;Solution;50
11.5.3;How It Works;50
11.5.3.1;Creating a Spring Project;50
11.5.3.2;Creating a Spring Bean Configuration File;50
11.5.3.3;Viewing Spring Beans in Spring Explorer;53
11.5.3.4;Viewing Spring Beans in Spring Beans Graph;54
11.5.3.5;Using Content Assist in Bean Configuration Files;55
11.5.3.6;Validating Bean Configuration Files;55
11.5.3.7;Searching Spring Beans;56
11.6;2-6. Summary;57
12;CHAPTER 3 Bean Configuration in Spring;58
12.1;3-1. Configuring Beans in the Spring IoC Container;58
12.1.1;Problem;58
12.1.2;Solution;58
12.1.3;How It Works;59
12.1.3.1;Creating the Bean Class;59
12.1.3.2;Creating the Bean Configuration File;60
12.1.3.3;Declaring Beans in the Bean Configuration File;60
12.1.3.4;Defining Bean Properties by Shortcut;62
12.2;3-2. Instantiating the Spring IoC Container;62
12.2.1;Problem;62
12.2.2;Solution;62
12.2.3;How It Works;63
12.2.3.1;Instantiating a Bean Factory;63
12.2.3.2;Instantiating an Application Context;64
12.2.3.3;Getting Beans from the IoC Container;64
12.3;3-3. Resolving Constructor Ambiguity;65
12.3.1;Problem;65
12.3.2;Solution;65
12.3.3;How It Works;65
12.4;3-4. Specifying Bean References;68
12.4.1;Problem;68
12.4.2;Solution;68
12.4.3;How It Works;68
12.4.3.1;Specifying Bean References for Setter Methods;69
12.4.3.2;Declaring Inner Beans;72
12.5;3-5. Checking Properties with Dependency Checking;72
12.5.1;Problem;72
12.5.2;Solution;72
12.5.3;How It Works;73
12.5.3.1;Checking Properties of the Simple Types;73
12.5.3.2;Checking Properties of the Object Types;74
12.5.3.3;Checking Properties of All Types;74
12.5.3.4;Dependency Checking and Constructor Injection;74
12.6;3-6. Checking Properties with the @Required Annotation;75
12.6.1;Problem;75
12.6.2;Solution;75
12.6.3;How It Works;75
12.7;3-7. Auto-Wiring Beans with XML Configuration;77
12.7.1;Problem;77
12.7.2;Solution;77
12.7.3;How It Works;78
12.7.3.1;Auto-Wiring by Type;78
12.7.3.2;Auto-Wiring by Name;79
12.7.3.3;Auto-Wiring by Constructor;80
12.7.3.4;Auto-Wiring by Auto-Detection;80
12.7.3.5;Auto-Wiring and Dependency Checking;81
12.8;3-8. Auto-Wiring Beans with @Autowired and @Resource;81
12.8.1;Problem;81
12.8.2;Solution;81
12.8.3;How It Works;82
12.8.3.1;Auto-Wiring a Single Bean of Compatible Type;82
12.8.3.2;Auto-Wiring All Beans of Compatible Type;84
12.8.3.3;Auto-Wiring by Type with Qualifiers;86
12.8.3.4;Auto-Wiring by Name;87
12.9;3-9. Inheriting Bean Configuration;88
12.9.1;Problem;88
12.9.2;Solution;88
12.9.3;How It Works;88
12.10;3-10.Defining Collections for Bean Properties;91
12.10.1;Problem;91
12.10.2;Solution;91
12.10.3;How It Works;92
12.10.3.1;Lists, Arrays, and Sets;92
12.10.3.2;Maps and Properties;95
12.10.3.3;Merging the Collection of the Parent Bean;97
12.11;3-11. Specifying the Data Type for Collection Elements;98
12.11.1;Problem;98
12.11.2;Solution;98
12.11.3;How It Works;99
12.12;3-12.Defining Collections Using Factory Beans and the Utility Schema;101
12.12.1;Problem;101
12.12.2;Solution;101
12.12.3;How It Works;101
12.12.3.1;Specifying the Concrete Class for Collections;101
12.12.3.2;Defining Stand-Alone Collections;102
12.13;3-13. Scanning Components from the Classpath;103
12.13.1;Problem;103
12.13.2;Solution;104
12.13.3;How It Works;104
12.13.3.1;Scanning Components Automatically;106
12.13.3.2;Filtering Components to Scan;108
12.13.3.3;Naming Detected Components;108
12.14;3-14. Summary;109
13;CHAPTER 4 Advanced Spring IoC Container;110
13.1;4-1. Creating Beans by Invoking a Constructor;110
13.1.1;Problem;110
13.1.2;Solution;110
13.1.3;How It Works;110
13.2;4-2. Creating Beans by Invoking a Static Factory Method;114
13.2.1;Problem;114
13.2.2;Solution;114
13.2.3;How It Works;114
13.3;4-3. Creating Beans by Invoking an Instance Factory Method;115
13.3.1;Problem;115
13.3.2;Solution;115
13.3.3;How It Works;115
13.4;4-4. Creating Beans Using Spring’s Factory Bean;117
13.4.1;Problem;117
13.4.2;Solution;117
13.4.3;How It Works;117
13.5;4-5.Declaring Beans from Static Fields;119
13.5.1;Problem;119
13.5.2;Solution;119
13.5.3;How It Works;119
13.6;4-6.Declaring Beans from Object Properties;121
13.6.1;Problem;121
13.6.2;Solution;121
13.6.3;How It Works;121
13.7;4-7. Setting Bean Scopes;123
13.7.1;Problem;123
13.7.2;Solution;123
13.7.3;How It Works;123
13.8;4-8. Customizing Bean Initialization and Destruction;125
13.8.1;Problem;125
13.8.2;Solution;126
13.8.3;How It Works;126
13.8.3.1;Implementing the InitializingBean and DisposableBean Interfaces;128
13.8.3.2;Annotating the @PostConstruct and @PreDestroy Annotations;129
13.9;4-9.Making Beans Aware of the Container;131
13.9.1;Problem;131
13.9.2;Solution;131
13.9.3;How It Works;132
13.10;4-10. Creating Bean Post Processors;132
13.10.1;Problem;132
13.10.2;Solution;132
13.10.3;How It Works;133
13.11;4-11. Externalizing Bean Configurations;137
13.11.1;Problem;137
13.11.2;Solution;137
13.11.3;How It Works;137
13.12;4-12. Resolving Text Messages;138
13.12.1;Problem;138
13.12.2;Solution;138
13.12.3;How It Works;138
13.13;4-13. Communicating with Application Events;140
13.13.1;Problem;140
13.13.2;Solution;141
13.13.3;How It Works;141
13.13.3.1;Defining Events;141
13.13.3.2;Publishing Events;142
13.13.3.3;Listening to Events;142
13.14;4-14. Registering Property Editors in Spring;143
13.14.1;Problem;143
13.14.2;Solution;143
13.14.3;How It Works;143
13.15;4-15. Creating Custom Property Editors;146
13.15.1;Problem;146
13.15.2;Solution;146
13.15.3;How It Works;146
13.16;4-16. Loading External Resources;148
13.16.1;Problem;148
13.16.2;Solution;148
13.16.3;How It Works;149
13.16.3.1;Resource Prefixes;150
13.16.3.2;Injecting Resources;150
13.17;4-17. Summary;151
14;CHAPTER 5 Dynamic Proxy and Classic Spring AOP;152
14.1;5-1. Problems with Non-Modularized Crosscutting Concerns;153
14.1.1;Tracing the Methods;154
14.1.2;Validating the Arguments;157
14.1.3;Identifying the Problems;159
14.2;5-2.Modularizing Crosscutting Concerns with Dynamic Proxy;161
14.2.1;Problem;161
14.2.2;Solution;161
14.2.3;How It Works;162
14.2.3.1;Creating the Logging Proxy;162
14.2.3.2;Creating the Validation Proxy;165
14.3;5-3.Modularizing Crosscutting Concerns with Classic Spring Advices;167
14.3.1;Problem;167
14.3.2;Solution;168
14.3.3;How It Works;168
14.3.3.1;Before Advices;169
14.3.3.2;After Returning Advices;172
14.3.3.3;After Throwing Advices;173
14.3.3.4;Around Advices;175
14.4;5-4.Matching Methods with Classic Spring Pointcuts;177
14.4.1;Problem;177
14.4.2;Solution;177
14.4.3;How It Works;177
14.4.3.1;Method Name Pointcuts;177
14.4.3.2;Regular Expression Pointcuts;179
14.4.3.3;AspectJ Expression Pointcuts;179
14.5;5-5. Creating Proxies for Your Beans Automatically;180
14.5.1;Problem;180
14.5.2;Solution;180
14.5.3;How It Works;180
14.6;5-6. Summary;182
15;CHAPTER 6 Spring 2.x AOP and AspectJ Support;183
15.1;6-1. Enabling AspectJ Annotation Support in Spring;184
15.1.1;Problem;184
15.1.2;Solution;184
15.1.3;How It Works;184
15.2;6-2.Declaring Aspects with AspectJ Annotations;186
15.2.1;Problem;186
15.2.2;Solution;186
15.2.3;How It Works;187
15.2.3.1;Before Advices;187
15.2.3.2;After Advices;188
15.2.3.3;After Returning Advices;189
15.2.3.4;After Throwing Advices;190
15.2.3.5;Around Advices;191
15.3;6-3. Accessing the Join Point Information;192
15.3.1;Problem;192
15.3.2;Solution;192
15.3.3;How It Works;193
15.4;6-4. Specifying Aspect Precedence;194
15.4.1;Problem;194
15.4.2;Solution;194
15.4.3;How It Works;194
15.5;6-5. Reusing Pointcut Definitions;196
15.5.1;Problem;196
15.5.2;Solution;196
15.5.3;How It Works;196
15.6;6-6.Writing AspectJ Pointcut Expressions;198
15.6.1;Problem;198
15.6.2;Solution;198
15.6.3;How It Works;198
15.6.3.1;Method Signature Patterns;198
15.6.3.2;Type Signature Patterns;200
15.6.3.3;Bean Name Patterns;201
15.6.3.4;Combining Pointcut Expressions;201
15.6.3.5;Declaring Pointcut Parameters;202
15.7;6-7. Introducing Behaviors to Your Beans;203
15.7.1;Problem;203
15.7.2;Solution;203
15.7.3;How It Works;203
15.8;6-8. Introducing States to Your Beans;206
15.8.1;Problem;206
15.8.2;Solution;206
15.8.3;How It Works;206
15.9;6-9.Declaring Aspects with XML-Based Configurations;208
15.9.1;Problem;208
15.9.2;Solution;208
15.9.3;How It Works;209
15.9.3.1;Declaring Aspects;209
15.9.3.2;Declaring Pointcuts;210
15.9.3.3;Declaring Advices;210
15.9.3.4;Declaring Introductions;211
15.10;6-10. Load-Time Weaving AspectJ Aspects in Spring;212
15.10.1;Problem;212
15.10.2;Solution;212
15.10.3;How It Works;212
15.10.3.1;Load-Time Weaving by the AspectJ Weaver;215
15.10.3.2;Load-Time Weaving by Spring 2.5 Load-Time Weaver;216
15.11;6-11. Configuring AspectJ Aspects in Spring;217
15.11.1;Problem;217
15.11.2;Solution;217
15.11.3;How It Works;217
15.12;6-12. Injecting Spring Beans into Domain Objects;218
15.12.1;Problem;218
15.12.2;Solution;218
15.12.3;How It Works;219
15.13;6-13. Summary;222
16;PART 2 Fundamentals;223
17;CHAPTER 7 Spring JDBC Support;224
17.1;7-1. Problems with Direct JDBC;224
17.1.1;Setting Up the Application Database;225
17.1.2;Understanding the Data Access Object Design Pattern;226
17.1.3;Implementing the DAO with JDBC;227
17.1.4;Configuring a Data Source in Spring;229
17.1.5;Running the DAO;231
17.2;7-2.Using a JDBC Template to Update a Database;231
17.2.1;Problem;231
17.2.2;Solution;232
17.2.3;How It Works;232
17.2.3.1;Updating a Database with a Statement Creator;232
17.2.3.2;Updating a Database with a Statement Setter;234
17.2.3.3;Updating a Database with a SQL Statement and Parameter Values;234
17.2.3.4;Batch Updating a Database;235
17.3;7-3.Using a JDBC Template to Query a Database;236
17.3.1;Problem;236
17.3.2;Solution;237
17.3.3;How It Works;237
17.3.3.1;Extracting Data with a Row Callback Handler;237
17.3.3.2;Extracting Data with a Row Mapper;238
17.3.3.3;Querying for Multiple Rows;239
17.3.3.4;Querying for a Single Value;241
17.4;7-4. Simplifying JDBC Template Creation;242
17.4.1;Problem;242
17.4.2;Solution;242
17.4.3;How It Works;243
17.4.3.1;Injecting a JDBC Template;243
17.4.3.2;Extending the JdbcDaoSupport Class;244
17.5;7-5.Using the Simple JDBC Template with Java 1.5;245
17.5.1;Problem;245
17.5.2;Solution;245
17.5.3;How It Works;245
17.5.3.1;Using a Simple JDBC Template to Update a Database;245
17.5.3.2;Using a Simple JDBC Template to Query a Database;246
17.6;7-6.Using Named Parameters in a JDBC Template;248
17.6.1;Problem;248
17.6.2;Solution;249
17.6.3;How It Works;249
17.7;7-7.Modeling JDBC Operations As Fine-Grained Objects;251
17.7.1;Problem;251
17.7.2;Solution;251
17.7.3;How It Works;251
17.7.3.1;Update Operation Objects;251
17.7.3.2;Query Operation Objects;253
17.7.3.3;Function Operation Objects;254
17.8;7-8.Handling Exceptions in the Spring JDBC Framework;255
17.8.1;Problem;255
17.8.2;Solution;255
17.8.3;How It Works;256
17.8.3.1;Understanding Exception Handling in the Spring JDBC Framework;256
17.8.3.2;Customizing Data Access Exception Handling;259
17.9;7-9. Summary;260
18;CHAPTER 8 Transaction Management in Spring;262
18.1;8-1. Problems with TransactionManagement;263
18.1.1;Managing Transactions with JDBC Commit and Rollback;267
18.2;8-2. Choosing a TransactionManager Implementation;268
18.2.1;Problem;268
18.2.2;Solution;269
18.2.3;How It Works;269
18.3;8-3.Managing Transactions Programmatically with the Transaction Manager API;270
18.3.1;Problem;270
18.3.2;Solution;270
18.3.3;How It Works;270
18.4;8-4.Managing Transactions Programmatically with a Transaction Template;272
18.4.1;Problem;272
18.4.2;Solution;272
18.4.3;How It Works;272
18.5;8-5.Managing Transactions Declaratively with Classic Spring AOP;275
18.5.1;Problem;275
18.5.2;Solution;275
18.5.3;How It Works;276
18.6;8-6.Managing Transactions Declaratively with Transaction Advices;278
18.6.1;Problem;278
18.6.2;Solution;278
18.6.3;How It Works;278
18.7;8-7.Managing Transactions Declaratively with the @Transactional Annotation;280
18.7.1;Problem;280
18.7.2;Solution;280
18.7.3;How It Works;280
18.8;8-8. Setting the Propagation Transaction Attribute;281
18.8.1;Problem;281
18.8.2;Solution;281
18.8.3;How It Works;282
18.8.3.1;The REQUIRED Propagation Behavior;283
18.8.3.2;The REQUIRES_NEWPropagation Behavior;285
18.8.3.3;Setting the Propagation Attribute in Transaction Advices, Proxies, and APIs;285
18.9;8-9. Setting the Isolation Transaction Attribute;286
18.9.1;Problem;286
18.9.2;Solution;286
18.9.3;How It Works;287
18.9.3.1;The READ_UNCOMMITTED and READ_COMMITTED Isolation Levels;289
18.9.3.2;The REPEATABLE_READ Isolation Level;291
18.9.3.3;The SERIALIZABLE Isolation Level;293
18.9.3.4;Setting the Isolation Level Attribute in Transaction Advices, Proxies, and APIs;293
18.10;8-10. Setting the Rollback Transaction Attribute;294
18.10.1;Problem;294
18.10.2;Solution;294
18.10.3;How It Works;294
18.11;8-11. Setting the Timeout and Read-Only Transaction Attributes;295
18.11.1;Problem;295
18.11.2;Solution;296
18.11.3;How It Works;296
18.12;8-12.Managing Transactions with Load-TimeWeaving;297
18.12.1;Problem;297
18.12.2;Solution;297
18.12.3;How It Works;297
18.13;8-13. Summary;300
19;CHAPTER 9 Spring ORM Support;302
19.1;9-1. Problems with Using ORM Frameworks Directly;303
19.1.1;Persisting Objects Using the Hibernate API with Hibernate XML Mappings;304
19.1.2;Persisting Objects Using the Hibernate API with JPA Annotations;308
19.1.3;Persisting Objects Using JPA with Hibernate As the Engine;310
19.2;9-2. Configuring ORM Resource Factories in Spring;314
19.2.1;Problem;314
19.2.2;Solution;314
19.2.3;How It Works;314
19.2.3.1;Configuring a Hibernate Session Factory in Spring;314
19.2.3.2;Configuring a JPA EntityManager Factory in Spring;318
19.3;9-3. Persisting Objects with Spring’s ORMTemplates;321
19.3.1;Problem;321
19.3.2;Solution;321
19.3.3;How It Works;321
19.3.3.1;Using a Hibernate Template and a JPA Template;321
19.3.3.2;Extending the Hibernate and JPA DAO Support Classes;325
19.4;9-4. Persisting Objects with Hibernate’s Contextual Sessions;327
19.4.1;Problem;327
19.4.2;Solution;327
19.4.3;How It Works;327
19.5;9-5. Persisting Objects with JPA’s Context Injection;330
19.5.1;Problem;330
19.5.2;Solution;331
19.5.3;How It Works;331
19.6;9-6. Summary;334
20;CHAPTER 10 Spring MVC Framework;335
20.1;10-1.Developing a Simple Web Application with Spring MVC;335
20.1.1;Problem;335
20.1.2;Solution;336
20.1.3;How It Works;337
20.1.3.1;Setting Up a Spring MVC Application;339
20.1.3.2;Creating the Configuration Files;340
20.1.3.3;Creating Spring MVC Controllers;341
20.1.3.4;Creating JSP Views;345
20.1.3.5;Deploying the Web Application;346
20.2;10-2.Mapping Requests to Handlers;347
20.2.1;Problem;347
20.2.2;Solution;347
20.2.3;How It Works;347
20.2.3.1;Mapping Requests by Bean Names;347
20.2.3.2;Mapping Requests by Controller Class Names;348
20.2.3.3;Mapping Requests with Custom Mapping Definitions;349
20.2.3.4;Mapping Requests by Multiple Strategies;349
20.3;10-3. Intercepting Requests with Handler Interceptors;350
20.3.1;Problem;350
20.3.2;Solution;350
20.3.3;How It Works;351
20.4;10-4. Resolving User Locales;353
20.4.1;Problem;353
20.4.2;Solution;353
20.4.3;How It Works;354
20.4.3.1;Resolving Locales by an HTTP Request Header;354
20.4.3.2;Resolving Locales by a Session Attribute;354
20.4.3.3;Resolving Locales by a Cookie;354
20.4.3.4;Changing a User’s Locale;355
20.5;10-5. Externalizing Locale-Sensitive Text Messages;356
20.5.1;Problem;356
20.5.2;Solution;356
20.5.3;How It Works;356
20.6;10-6. Resolving Views by Names;357
20.6.1;Problem;357
20.6.2;Solution;357
20.6.3;How It Works;358
20.6.3.1;Resolving Views Based on URLs;358
20.6.3.2;Resolving Views from an XML Configuration File;358
20.6.3.3;Resolving Views from a Resource Bundle;359
20.6.3.4;Resolving Views with Multiple Resolvers;360
20.6.3.5;The Redirect Prefix;360
20.7;10-7.Mapping Exceptions to Views;360
20.7.1;Problem;360
20.7.2;Solution;361
20.7.3;How It Works;361
20.8;10-8. Constructing ModelAndView Objects;362
20.8.1;Problem;362
20.8.2;Solution;362
20.8.3;How It Works;363
20.9;10-9. Creating a Controller with a Parameterized View;365
20.9.1;Problem;365
20.9.2;Solution;365
20.9.3;How It Works;365
20.10;10-10.Handling Forms with Form Controllers;367
20.10.1;Problem;367
20.10.2;Solution;367
20.10.3;How It Works;367
20.10.3.1;Creating a Form Controller;368
20.10.3.2;Applying the Post/Redirect/Get Design Pattern;372
20.10.3.3;Initializing the Command Object;373
20.10.3.4;Providing Form Reference Data;375
20.10.3.5;Binding Properties of Custom Types;377
20.10.3.6;Validating Form Data;378
20.11;10-11.Handling Multipage Forms with Wizard Form Controllers;380
20.11.1;Problem;380
20.11.2;Solution;380
20.11.3;How It Works;381
20.11.3.1;Creating Wizard Form Pages;382
20.11.3.2;Creating a Wizard Form Controller;385
20.11.3.3;Validating Wizard FormData;387
20.12;10-12.Grouping Multiple Actions into a Controller;389
20.12.1;Problem;389
20.12.2;Solution;389
20.12.3;How It Works;389
20.12.3.1;Creating a Multi-Action Controller;391
20.12.3.2;Mapping URLs to Handler Methods;393
20.13;10-13. Creating Excel and PDF Views;395
20.13.1;Problem;395
20.13.2;Solution;395
20.13.3;How It Works;395
20.13.3.1;Creating Excel Views;397
20.13.3.2;Creating PDF Views;398
20.14;10-14.Developing Controllers with Annotations;399
20.14.1;Problem;399
20.14.2;Solution;399
20.14.3;How It Works;400
20.14.3.1;Developing Single-Action and Multi-Action Controllers;401
20.14.3.2;Developing a Form Controller;403
20.14.3.3;Comparison with the Traditional Controller Approach;406
20.15;10-15. Summary;407
21;CHAPTER 11 Integrating Spring with Other Web Frameworks;408
21.1;11-1. Accessing Spring in Generic Web Applications;408
21.1.1;Problem;408
21.1.2;Solution;409
21.1.3;How It Works;409
21.2;11-2. Integrating Spring with Struts 1.x;413
21.2.1;Problem;413
21.2.2;Solution;413
21.2.3;How It Works;414
21.2.3.1;Loading Spring’s Application Context into a Struts Application;415
21.2.3.2;Accessing Spring’s Application Context in Struts Actions;416
21.2.3.3;Declaring Struts Actions in Spring’s Bean Configuration File;418
21.3;11-3. Integrating Spring with JSF;420
21.3.1;Problem;420
21.3.2;Solution;420
21.3.3;How It Works;420
21.3.3.1;Resolving Spring Beans in JSF;423
21.3.3.2;Declaring JSF Managed Beans in Spring’s Bean Configuration File;424
21.4;11-4. Integrating Spring with DWR;425
21.4.1;Problem;425
21.4.2;Solution;425
21.4.3;How It Works;425
21.4.3.1;Exposing Spring Beans for Remote Invocation;427
21.4.3.2;Configuring DWR in Spring’s Bean Configuration File;428
21.5;11-5. Summary;429
22;CHAPTER 12 Spring Testing Support;430
22.1;12-1. Creating Tests with JUnit and TestNG;431
22.1.1;Problem;431
22.1.2;Solution;431
22.1.3;How It Works;431
22.1.3.1;Testing with JUnit 3.8;432
22.1.3.2;Testing with JUnit 4;433
22.1.3.3;Testing with TestNG;434
22.2;12-2. Creating Unit Tests and Integration Tests;436
22.2.1;Problem;436
22.2.2;Solution;436
22.2.3;How It Works;437
22.2.3.1;Creating Unit Tests for Isolated Classes;437
22.2.3.2;Creating Unit Tests for Dependent Classes Using Stubs and Mock Objects;441
22.2.3.3;Creating Integration Tests;445
22.3;12-3.Unit Testing Spring MVC Controllers;446
22.3.1;Problem;446
22.3.2;Solution;446
22.3.3;How It Works;446
22.3.3.1;Unit Testing Classic Spring MVC Controllers;446
22.3.3.2;Unit Testing Annotation-Based Spring MVC Controllers;449
22.4;12-4.Managing Application Contexts in Integration Tests;451
22.4.1;Problem;451
22.4.2;Solution;451
22.4.3;How It Works;452
22.4.3.1;Accessing the Context with JUnit 3.8 Legacy Support;452
22.4.3.2;Accessing the Context with the TestContext Framework in JUnit 4.4;453
22.4.3.3;Accessing the Context with the TestContext Framework in JUnit 3.8;455
22.4.3.4;Accessing the Context with the TestContext Framework in TestNG;456
22.5;12-5. Injecting Test Fixtures into Integration Tests;457
22.5.1;Problem;457
22.5.2;Solution;458
22.5.3;How It Works;458
22.5.3.1;Injecting Test Fixtures with JUnit 3.8 Legacy Support;458
22.5.3.2;Injecting Test Fixtures with the TestContext Framework in JUnit 4.4;459
22.5.3.3;Injecting Test Fixtures with the TestContext Framework in JUnit 3.8;460
22.5.3.4;Injecting Test Fixtures with the TestContext Framework in TestNG;461
22.6;12-6.Managing Transactions in Integration Tests;462
22.6.1;Problem;462
22.6.2;Solution;462
22.6.3;How It Works;463
22.6.3.1;Managing Transactions with JUnit 3.8 Legacy Support;464
22.6.3.2;Managing Transactions with the TestContext Framework in JUnit 4.4;465
22.6.3.3;Managing Transactions with the TestContext Framework in JUnit 3.8;467
22.6.3.4;Managing Transactions with the TestContext Framework in TestNG;467
22.7;12-7. Accessing a Database in Integration Tests;468
22.7.1;Problem;468
22.7.2;Solution;468
22.7.3;How It Works;468
22.7.3.1;Accessing a Database with JUnit 3.8 Legacy Support;468
22.7.3.2;Accessing a Database with the TestContext Framework;469
22.8;12-8.Using Spring’s Common Testing Annotations;472
22.8.1;Problem;472
22.8.2;Solution;472
22.8.3;How It Works;473
22.8.3.1;Using Common Testing Annotations with JUnit 3.8 Legacy Support;473
22.8.3.2;Using Common Testing Annotations with the TestContext Framework;473
22.9;12-9. Summary;474
23;PART 3 Advanced;476
24;CHAPTER 13 Spring Security;477
24.1;13-1. Securing URL Access;477
24.1.1;Problem;477
24.1.2;Solution;478
24.1.3;How It Works;478
24.1.3.1;Setting Up a Spring MVC Application That Uses Spring Security;480
24.1.3.2;Creating the Configuration Files;480
24.1.3.3;Creating the Controllers and Page Views;482
24.1.3.4;Securing URL Access;486
24.2;13-2. Logging In to Web Applications;488
24.2.1;Problem;488
24.2.2;Solution;488
24.2.3;How It Works;488
24.2.3.1;HTTP Basic Authentication;489
24.2.3.2;Form-Based Login;489
24.2.3.3;The Logout Service;491
24.2.3.4;Anonymous Login;492
24.2.3.5;Remember-Me Support;492
24.3;13-3. Authenticating Users;492
24.3.1;Problem;492
24.3.2;Solution;492
24.3.3;How It Works;493
24.3.3.1;Authenticating Users with In-Memory Definitions;493
24.3.3.2;Authenticating Users Against a Database;494
24.3.3.3;Encrypting Passwords;496
24.3.3.4;Authenticating Users Against an LDAP Repository;497
24.3.3.5;Caching User Details;501
24.4;13-4.Making Access Control Decisions;502
24.4.1;Problem;502
24.4.2;Solution;503
24.4.3;How It Works;503
24.5;13-5. Securing Method Invocations;506
24.5.1;Problem;506
24.5.2;Solution;506
24.5.3;How It Works;506
24.5.3.1;Securing Methods by Embedding a Security Interceptor;506
24.5.3.2;Securing Methods with Pointcuts;507
24.5.3.3;Securing Methods with Annotations;508
24.6;13-6.Handling Security in Views;509
24.6.1;Problem;509
24.6.2;Solution;509
24.6.3;How It Works;509
24.6.3.1;Displaying Authentication Information;509
24.6.3.2;Rendering View Contents Conditionally;510
24.7;13-7.Handling Domain Object Security;511
24.7.1;Problem;511
24.7.2;Solution;511
24.7.3;How It Works;512
24.7.3.1;Setting Up an ACL Service;512
24.7.3.2;Maintaining ACLs for Domain Objects;515
24.7.3.3;Making Access Control Decisions Based on ACLs;517
24.7.3.4;Handling Domain Objects Returned from Methods;520
24.8;13-8. Summary;521
25;CHAPTER 14 Spring Portlet MVC Framework;523
25.1;14-1.Developing a Simple Portlet with Spring Portlet MVC;523
25.1.1;Problem;523
25.1.2;Solution;523
25.1.3;How It Works;525
25.1.3.1;Setting Up a Portlet Application;525
25.1.3.2;Creating the Configuration Files;526
25.1.3.3;Creating Portlet Controllers;528
25.1.3.4;Mapping Portlet Requests to Handlers;529
25.1.3.5;Resolving View Names into Views;529
25.1.3.6;Creating Portlet Views;530
25.1.3.7;Deploying the Portlet Application;530
25.2;14-2.Mapping Portlet Requests to Handlers;531
25.2.1;Problem;531
25.2.2;Solution;532
25.2.3;How It Works;532
25.2.3.1;Mapping Requests by the Portlet Mode;534
25.2.3.2;Mapping Requests by a Parameter;538
25.2.3.3;Mapping Requests by Both the Portlet Mode and Parameter;540
25.3;14-3.Handling Portlet Forms with Simple Form Controllers;541
25.3.1;Problem;541
25.3.2;Solution;541
25.3.3;How It Works;541
25.3.3.1;Creating Form Controllers;543
25.3.3.2;Validating Form Data;547
25.4;14-4.Developing Portlet Controllers with Annotations;549
25.4.1;Problem;549
25.4.2;Solution;549
25.4.3;How It Works;549
25.4.3.1;Developing Multi-Action Controllers;549
25.4.3.2;Developing Form Controllers;552
25.5;14-5. Summary;555
26;CHAPTER 15 Spring Web Flow;556
26.1;15-1.Managing a Simple UI Flow with Spring Web Flow;556
26.1.1;Problem;556
26.1.2;Solution;556
26.1.3;How It Works;557
26.1.3.1;Setting Up a Spring MVC Application That Uses Spring Web Flow;558
26.1.3.2;Creating the Configuration Files;559
26.1.3.3;Creating Web Flow Definitions;561
26.2;15-2.Modeling Web Flows with Different State Types;563
26.2.1;Problem;563
26.2.2;Solution;564
26.2.3;How It Works;564
26.2.3.1;Defining View States;567
26.2.3.2;Defining Action States;571
26.2.3.3;Defining Decision States;572
26.2.3.4;Defining End States;573
26.2.3.5;Defining Subflow States;575
26.3;15-3. Securing Web Flows;576
26.3.1;Problem;576
26.3.2;Solution;576
26.3.3;How It Works;577
26.4;15-4. Persisting Objects in Web Flows;579
26.4.1;Problem;579
26.4.2;Solution;579
26.4.3;How It Works;579
26.4.3.1;Configuring JPA in Spring’s Application Context;580
26.4.3.2;Setting Up JPA for Spring Web Flow;581
26.4.3.3;Using JPA in Web Flows;582
26.5;15-5. Integrating Spring Web Flow with JSF;585
26.5.1;Problem;585
26.5.2;Solution;586
26.5.3;How It Works;586
26.5.3.1;Rendering JSF Views for Spring Web Flow;586
26.5.3.2;Using the JSF Components of Spring Faces;589
26.6;15-6. Summary;591
27;CHAPTER 16 Spring Remoting and Web Services;593
27.1;16-1. Exposing and Invoking Services Through RMI;594
27.1.1;Problem;594
27.1.2;Solution;594
27.1.3;How It Works;595
27.1.3.1;Exposing an RMI Service;596
27.1.3.2;Invoking an RMI Service;597
27.2;16-2. Exposing and Invoking Services Through HTTP;598
27.2.1;Problem;598
27.2.2;Solution;598
27.2.3;How It Works;599
27.2.3.1;Exposing a Hessian Service;599
27.2.3.2;Invoking a Hessian Service;601
27.2.3.3;Exposing a Burlap Service;601
27.2.3.4;Invoking a Burlap Service;601
27.2.3.5;Exposing an HTTP Invoker Service;602
27.2.3.6;Invoking an HTTP Invoker Service;602
27.3;16-3. Choosing aWeb Service Development Approach;602
27.3.1;Problem;602
27.3.2;Solution;602
27.3.3;How It Works;603
27.3.3.1;Contract-LastWeb Services;603
27.3.3.2;Contract-FirstWeb Services;603
27.3.3.3;Comparison;604
27.4;16-4. Exposing and InvokingWeb Services Using XFire;605
27.4.1;Problem;605
27.4.2;Solution;605
27.4.3;How It Works;605
27.4.3.1;Exposing aWeb Service Using XFire;605
27.4.3.2;Inspecting the GeneratedWSDL File;607
27.4.3.3;Invoking aWeb Service Using XFire;609
27.4.3.4;Exposing an Annotation-BasedWeb Service Using XFire;610
27.5;16-5.Defining the Contract ofWeb Services;611
27.5.1;Problem;611
27.5.2;Solution;611
27.5.3;How It Works;611
27.5.3.1;Creating Sample XMLMessages;611
27.5.3.2;Generating an XSD File from Sample XMLMessages;612
27.5.3.3;Optimizing the Generated XSD File;614
27.5.3.4;Previewing the GeneratedWSDL File;614
27.6;16-6. ImplementingWeb Services Using Spring-WS;615
27.6.1;Problem;615
27.6.2;Solution;615
27.6.3;How It Works;616
27.6.3.1;Setting Up a Spring-WS Application;616
27.6.3.2;MappingWeb Service Requests to Endpoints;618
27.6.3.3;Creating Service Endpoints;618
27.6.3.4;Publishing theWSDL File;620
27.7;16-7. InvokingWeb Services Using Spring-WS;622
27.7.1;Problem;622
27.7.2;Solution;622
27.7.3;How It Works;622
27.8;16-8.DevelopingWeb Services with XMLMarshalling;625
27.8.1;Problem;625
27.8.2;Solution;625
27.8.3;How It Works;626
27.8.3.1;Creating Service Endpoints with XMLMarshalling;626
27.8.3.2;InvokingWeb Services with XMLMarshalling;629
27.9;16-9. Creating Service Endpoints with Annotations;631
27.9.1;Problem;631
27.9.2;Solution;631
27.9.3;How It Works;631
27.10;16-10. Summary;632
28;CHAPTER 17 Spring Support for EJB and JMS;634
28.1;17-1. Creating EJB 2.x Components with Spring;634
28.1.1;Problem;634
28.1.2;Solution;635
28.1.3;How It Works;635
28.1.3.1;Creating EJB 2.x Components with Spring’s Support;638
28.2;17-2. Accessing EJB 2.x Components in Spring;640
28.2.1;Problem;640
28.2.2;Solution;641
28.2.3;How It Works;641
28.2.3.1;Accessing EJB 2.x Components Without Spring’s Support;642
28.2.3.2;Accessing EJB 2.x Components with Spring’s Support;644
28.3;17-3. Accessing EJB 3.0 Components in Spring;646
28.3.1;Problem;646
28.3.2;Solution;646
28.3.3;How It Works;646
28.3.3.1;Accessing EJB 3.0 Components Without Spring’s Support;647
28.3.3.2;Accessing EJB 3.0 Components with Spring’s Support;647
28.4;17-4. Sending and Receiving JMSMessages with Spring;649
28.4.1;Problem;649
28.4.2;Solution;649
28.4.3;How It Works;650
28.4.3.1;Sending and ReceivingMessages with Spring’s JMS Template;655
28.4.3.2;Sending and ReceivingMessages to and from a Default Destination;658
28.4.3.3;Extending the JmsGatewaySupport Class;660
28.4.3.4;Converting JMSMessages;661
28.4.3.5;Managing JMS Transactions;663
28.5;17-5. CreatingMessage-Driven POJOs in Spring;664
28.5.1;Problem;664
28.5.2;Solution;665
28.5.3;How It Works;665
28.5.3.1;Listening for JMSMessages withMessage Listeners;665
28.5.3.2;Listening for JMSMessages with POJOs;667
28.5.3.3;Converting JMSMessages;668
28.5.3.4;Managing JMS Transactions;669
28.5.3.5;Using Spring’s JMS Schema;669
28.6;17-6. Summary;670
29;CHAPTER 18 Spring Support for JMX, E-mail, and Scheduling;672
29.1;18-1. Exporting Spring Beans As JMX MBeans;672
29.1.1;Problem;672
29.1.2;Solution;673
29.1.3;How It Works;673
29.1.3.1;Registering MBeansWithout Spring’s Support;675
29.1.3.2;Exporting Spring Beans As MBeans;678
29.1.3.3;Exposing MBeans for Remote Access;679
29.1.3.4;Assembling theManagement Interface of MBeans;680
29.1.3.5;Auto-Detecting MBeans by Annotations;682
29.2;18-2. Publishing and Listening to JMX Notifications;684
29.2.1;Problem;684
29.2.2;Solution;684
29.2.3;How It Works;684
29.2.3.1;Publishing JMX Notifications;684
29.2.3.2;Listening to JMX Notifications;685
29.3;18-3. Accessing Remote JMX MBeans in Spring;686
29.3.1;Problem;686
29.3.2;Solution;686
29.3.3;How It Works;686
29.3.3.1;Accessing Remote MBeans Through an MBean Server Connection;686
29.3.3.2;Accessing Remote MBeans Through an MBean Proxy;688
29.4;18-4. Sending E-mail with Spring’s E-mail Support;689
29.4.1;Problem;689
29.4.2;Solution;689
29.4.3;How It Works;689
29.4.3.1;Sending E-mail Using the JavaMail API;691
29.4.3.2;Sending E-mail with Spring’sMailSender;692
29.4.3.3;Defining an E-mail Template;694
29.4.3.4;Sending MIMEMessages;695
29.5;18-5. Scheduling with Spring’s JDK Timer Support;697
29.5.1;Problem;697
29.5.2;Solution;697
29.5.3;How It Works;698
29.5.3.1;Creating a Timer Task;698
29.5.3.2;Using JDK Timer Without Spring’s Support;698
29.5.3.3;Using JDK Timer with Spring’s Support;699
29.6;18-6. Scheduling with Spring’s Quartz Support;700
29.6.1;Problem;700
29.6.2;Solution;700
29.6.3;How It Works;700
29.6.3.1;Using Quartz Without Spring’s Support;700
29.6.3.2;Using Quartz with Spring’s Support;702
29.7;18-7. Summary;705
30;CHAPTER 19 Scripting in Spring;706
30.1;19-1. Implementing Beans with Scripting Languages;706
30.1.1;Problem;706
30.1.2;Solution;706
30.1.3;How It Works;707
30.1.3.1;Scripting Beans with JRuby;707
30.1.3.2;Scripting Beans with Groovy;709
30.1.3.3;Scripting Beans with BeanShell;710
30.2;19-2. Injecting Spring Beans into Scripts;711
30.2.1;Problem;711
30.2.2;Solution;711
30.2.3;How It Works;711
30.2.3.1;Injecting Spring Beans into JRuby;712
30.2.3.2;Injecting Spring Beans into Groovy;713
30.2.3.3;Injecting Spring Beans into BeanShell;713
30.3;19-3. Refreshing Beans from Scripts;714
30.3.1;Problem;714
30.3.2;Solution;714
30.3.3;How It Works;714
30.4;19-4.Defining Script Sources Inline;715
30.4.1;Problem;715
30.4.2;Solution;715
30.4.3;How It Works;715
30.5;19-5. Summary;716
31;Index;718



Ihre Fragen, Wünsche oder Anmerkungen
Vorname*
Nachname*
Ihre E-Mail-Adresse*
Kundennr.
Ihre Nachricht*
Lediglich mit * gekennzeichnete Felder sind Pflichtfelder.
Wenn Sie die im Kontaktformular eingegebenen Daten durch Klick auf den nachfolgenden Button übersenden, erklären Sie sich damit einverstanden, dass wir Ihr Angaben für die Beantwortung Ihrer Anfrage verwenden. Selbstverständlich werden Ihre Daten vertraulich behandelt und nicht an Dritte weitergegeben. Sie können der Verwendung Ihrer Daten jederzeit widersprechen. Das Datenhandling bei Sack Fachmedien erklären wir Ihnen in unserer Datenschutzerklärung.