Friday, 27 June 2008

Building Spring 2 Enterprise Applications By Seth Ladd , Bram Smeets

Just now i finished reading Building Spring 2 Enterprise Applications Book By Seth Ladd,Bram Smeets

Nice book written by Seth Ladd,Bram Smeets.but Examples in chapter 8 are incomplete and unavailable in download code also.

Frankly i thought Spring In Action By Craig Walls with Ryan Breidenbach is better.

Also i thought this IBM link provided cool introduction about Spring MVC

I wanted to share few important points i found from this book.

1) Simplicity in software development means four things:
• To implement only the functionality that is absolutely required and nothing more
• To write code that is as clean, readable, and simple as possible
• To write code that is easy to test and is tested only once
• To streamline the development process cycle to be as agile and rapid as possible (taking into account the settings of your projects)

2) Introducing the Spring Framework Modules

Inversion of Control (IoC) Container: Also called the Core Container, creates and configures application objects and wires them together. This means that resources and collaborating objects are provided to objects, so the objects do not need to look them up. This moves an important responsibility out of your code and makes it easier to write and test code.

Aspect-Oriented Programming (AOP) framework:Works with cross-cutting concerns—one solution to a problem that’s used in multiple places. The Spring AOP framework links cross-cutting concerns to the invocation of specific methods on specific objects (not classes) in such a way that your code is unaware of their presence. The Spring Framework uses cross-cutting concerns and AOP to let your application deal with transactions without having a single line of transaction management code in your code base.

Data Access framework: Hides the complexity of using persistence APIs such as JDBC,Hibernate, and many others. Spring solves problems that have been haunting data-access developers for years: how to get hold of a database connection, how to make sure that the connection is closed, how to deal with exceptions, and how to do transaction management.

Transaction Management framework: Provides a very efficient way to add transaction management to your applications without affecting your code base. Adding transaction management is a matter of configuration, and it makes the lives of application developers much easier.

Resource Abstraction framework: Offers a wonderful feature for conveniently locating files when configuring your applications.

Validation framework: Hides the details of validating objects in web applications or rich client applications. It also deals with internationalization (i18n) and localization (l10n).

Spring Web MVC: Provides a Model-View-Controller (MVC) framework that lets you build powerful web applications with ease. It handles the mapping of requests to controllers and of controllers to views. It has excellent form-handling and form-validation capabilities, and integrates with all popular view technologies, including JSP, Velocity, FreeMarker, XSLT,JasperReports, Excel, and PDFs.

Spring Web Flow:Makes implementing web-based wizards and complex workflow processes very easy and straightforward. Spring Web Flow is a conversation-based MVC framework. Your web applications will look much smarter once you learn how to use this framework.

Acegi Security System: Adds authentication and authorization to objects in your application using AOP. Acegi can secure any web application, even those that do not use the Spring Framework.It offers a wide range of authentication and authorization options that will fit your most exotic security needs. Adding security checks to your application is straightforward and a matter of configuration; you don’t need to write any code, except in some special use cases.

Remote Access framework: Adds client-server capabilities to applications through configuration.Objects on the server can be exported as remotely available services. On the client, you can call these services transparently, also through configuration. Remotely accessing services over the network thus becomes very easy. Spring’s Remote Access framework supports HTTP based protocols and remote method invocation (RMI), and can access Enterprise JavaBeans as a client.

Spring Web Services: Takes the complexity out of web services and separates the concerns into manageable units. Most web service frameworks generate web service end points and definitions based on Java classes, which get you going really fast, but become very hard to manage as your project evolves. To solve this problem, Spring Web Services takes a layered approach and separates the transport from the actual web service implementation by looking at web services as a messaging mechanism. Handling the XML message, executing business logic, and generating an XML response are all separate concerns that can be conveniently managed.

Spring JMX: Exports objects via Java Management Extensions (JMX) through configuration.Spring JMX is closely related to Spring’s Remote Access framework. These objects can then be managed via JMX clients to change the value of properties, execute methods, or report statistics.JMX allows you to reconfigure application objects remotely and without needing to restart the application.

3) Dependency injection (DI) is the core feature of the Spring Framework Core Container. It provides a mechanism to pass, or inject, dependencies to objects.Dependency injection is a method of inversion of control (IoC).

In contrast, dependency injection places the responsibility of resolving dependencies in the hands of an IoC container such as the Spring Framework. A configuration file defines how the dependencies of an application can be resolved. The configuration file is read by the container,which will create the objects that are defined in this file and inject these objects in other application
components. The Spring Framework Core Container supports two types of dependency injection to inject collaborating objects: setter injection and container injection.

4) EJB and the Spring Framework are often compared because they promise the same thing: an application deployment model with transparent enterprise service like transaction management,security, messaging, and remote access.

5) Spring Framework Core Container is essentially a factory that creates objects without revealing the exact classes that are used and how they are created.

In software engineering, factories encapsulate the process of obtaining objects, which is usually more complex than just creating new objects.The Core Container uses encapsulation to hide from the actual application the details of how an application is created and configured; the application doesn’t know how to assemble itself or how to bootstrap. Instead, these tasks are handed off to the Core Container by providing the location of one or more configuration files that contain information about each object in the application that must be created. Next, the Core Container needs to be bootstrapped to launch the application.

6) Which one is preferred: setter injection or constructor injection? It’s largely up to you to choose, although you should pick one and stick to it for the duration of a project for the sake of consistency.

Setter injection is more popular because it’s more self-documenting and isn’t affected by circular dependency problems, which may occur if you use constructor injection. Setter injection leaves beans in an indeterminate state, something you can avoid with constructor injection.

7) The container creates and configures a bean based on its bean definition, which provides a single point to configure the life cycle of the bean. Along with dependency injection, the container also provides life-cycle options that address the following:

Scope: The scope of a bean defines the behavior of the container when a bean is requested,either via dependency injection or dependency lookup. By default, beans are singleton, which means they are created and configured once and stored in a cache. When a singleton bean is requested, the container returns the instance from the cache. Optionally, beans can be prototype,which means they are created and configured by the container on each request. When a prototype bean is requested, the container creates and configures a new bean and doesn’t keep track of it.

Initialization: The initialization of beans is available for singleton and prototype beans. The container can invoke a method on a bean if it implements a specific interface that is part of the Spring Framework API or if a custom initialization method has been configured on the bean definition. This is an optional step in the life cycle of a bean.

Destruction: The destruction of beans is available only for singleton beans. The container can invoke a method on a bean if it implements a specific interface that is part of the Spring Framework API or if a custom destroy method has been configured on the bean definition.
This is an optional step in the life cycle of a singleton bean.

8) The beans that are returned by factory methods and factory object methods go through the entire bean life cycle, which means they are subject to the following:

• Singleton/prototype configuration
• Setter injections
• Initialization methods
• Destroy methods, if configured as singleton

9) AfterReturning Advice Spring AOP interface, means that it will be executed after a target method is executed.

The Spring AOP framework has specifically been designed to provide a limited set of AOP features yet is simple to use and configure. Most applications need the features offered by Spring AOP only if more advanced features are required. The Spring Framework integrates with more powerful AOP frameworks, such as AspectJ.

10) Proxy objects are created at runtime by ProxyFactoryBean; you don’t need to write any code to create them. All public methods on the target object are available on the proxy object, and you can decorate any of these methods with advice.

Spring AOP supports two proxy types: Java Development Kit (JDK) proxies and bytecode proxies.If you specify interface names in the ProxyFactoryBean configuration, you’ll create a JDK proxy; otherwise, you’ll create a bytecode proxy.

11) Spring AOP supports four advice types that each represents a specific scenario for advice implementations:

Around advice: Controls the execution of a join point. This type is ideal for advice that needs to control the execution of the method on the target object.

Before advice: Is executed before the execution of a join point. This type is ideal for advice that needs to performan action before the execution of the method on the target object.

After advice: Is executed after the execution of a join point. This type is ideal for advice that needs to perform an action after the execution of the method on the target object.

Throws advice: Is executed after the execution of a join point if an exception is thrown. This type is ideal for advice that needs to performan action when the execution of the method on the target object has thrown an exception.

12) Aspects are how developers encapsulate concerns that cut across classes, the natural unit of modularity in Java.

13) The ACID properties form the minimal contract that databases must respect to ensure data integrity, as follows:

Atomicity: All changes that are made between the start and the end of a transaction must either succeed or abort all together. To ensure this, a database will roll back (that is, undo) all changes that have occurred since the start of the transaction when internal errors occur or when asked to do so.

Consistency: After a transaction ends—is either committed or rolled back—the data should be left in a consistent state, meaning no constraints or indices can be violated and field constraints like not-nullable, field length, and field type must be respected.

Isolation: Transactions can run concurrently, meaning multiple transactions can insert, read,update, and delete data at the same time. Transactions should not be affected by the actions of other transactions. Because full isolation between transactions that work on the same data often involves locks, it may cause slow performance. For this reason, databases support different isolation levels that offer a trade-off between performance and the risk of being affected by
the actions of other transactions.

Durability: After a transaction has been committed, the changes must be stored in a durable way; for example, by saving them on the file system.

14) DispatcherServlet is the front controller for a Spring MVC application. All requests pass through this servlet, as it manages all of the different elements that have a chance to process the request. DispatcherServlet is not meant for subclassing; instead, it is simply declared and configured by you, just like a normal servlet inside a web application. All of the real work is performed by delegates.

15) Spring MVC relies heavily on its view resolution architecture. If you do not
specify a view resolver in your configuration files, Spring provides you with a default view resolver:InternalResourceViewResolver.However, you are free to specify in your application context any number of view resolvers, which will take care of resolving the logical view name to the actual view implementation

16) Spring's Web MVC framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, locale, and theme resolution as well as support for upload files. The default handler is a very simple Controller interface with just one method, ModelAndView handleRequest(request, response). Spring provides a controller hierarchy that can be subclassed. If your application needs to process user entry forms you might subclass AbstractFormController. If you need to process a multi-page entry into a single form you can subclass AbstractWizardFormController.


Hope you enjoy reading the book.

About the Authors

Seth Ladd is a software engineer and professional Spring Framework trainer and mentor specializing in object-oriented and testable web applications. He started his own company building websites at age 17, but now enjoys having a real job. Currently working for Camber Corporation, Seth has built and deployed systems for NEC, Rochester Institute of Technology, Brivo Systems, and National Information Consortium. He has architected and developed enterprise applications in Java and C for both the server and remotely connected embedded devices. He enjoys speaking and teaching, and is a frequent presenter at local Java user groups and at corporate developer conferences. Seth is very thankful for living and working in Kailua, Hawaii, with his wife.

Bram Smeets

Bram Smeets is a Java architect with over 8 years’ experience in developing enterprise Java applications. Currently, Bram is technical director at JTeam (www.jteam.nl), a Java software development company based in the Netherlands and senior consultant at SpringSource (www.springsource.com). He is a regular speaker at technology–focused conferences like The Ajax Experience and SpringOne. Using GWT, Bram has delivered several successful RIA projects at JTeam. He also delivered Ajax and GWT trainings at several companies.

8 comments:

Anonymous said...

Howdy! I'm at work browsing your blog from my new iphone! Just wanted to say I love reading your blog and look forward to all your posts! Carry on the outstanding work!

Review my blog post :: http://amountjeep75.wallinside.com/

Anonymous said...

Hi there would you mind letting me know which webhost you're utilizing? I've loaded your blog in
3 different browsers and I must say this blog loads a lot faster then most.
Can you suggest a good internet hosting provider
at a fair price? Thanks a lot, I appreciate it!


My web blog ... http://www.exiledloot.com

Anonymous said...

My family always say that I am wasting my time here at net, but I know I
am getting know-how every day by reading thes nice articles or reviews.



my website sac a main Louis vuitton

Anonymous said...

My relatives always say that I am killing my time here at web, except I know I am getting know-how every day
by reading thes fastidious posts.

My homepage - Christian Louboutin Outlet

Anonymous said...

Great work! That is the kind of info that are supposed to be shared across the internet.
Disgrace on Google for now not positioning this put up
higher! Come on over and visit my web site . Thanks =)

Feel free to visit my site ... Tory Burch Handbags

Anonymous said...

Fastidious answers in return of this issue with genuine arguments and telling everything regarding that.



Here is my web blog; Nike Free Sko

Anonymous said...

Thank you for every other magnificent post. The place
else may just anyone get that kind of information in such a perfect way of writing?
I've a presentation subsequent week, and I am at the look for such information.

Feel free to visit my web blog Michael Kors

Anonymous said...

Hi, I do think this is an excellent website. I stumbledupon it ;) I am going to come back once again since I saved
as a favorite it. Money and freedom is the best way to change, may you
be rich and continue to help other people.

Check out my weblog: Michael Kors