background preloader

Spring

Facebook Twitter

Hibernate

Ddd. Annotations. Distributed transactions in Spring, with and without XA - JavaWo. While it's common to use the Java Transaction API and the XA protocol for distributed transactions in Spring, you do have other options. The optimum implementation depends on the types of resources your application uses and the trade-offs you're willing to make between performance, safety, reliability, and data integrity. In this JavaWorld feature, SpringSource's David Syer guides you through seven patterns for distributed transactions in Spring applications, three of them with XA and four without.

Level: Intermediate The Spring Framework's support for the Java Transaction API (JTA) enables applications to use distributed transactions and the XA protocol without running in a Java EE container. Even with this support, however, XA is expensive and can be unreliable or cumbersome to administrate. It may come as a welcome surprise, then, that a certain class of applications can avoid the use of XA altogether. Distributed transactions and atomicity Full XA with 2PC Listing 1. Listing 2. Spruice - Project Hosting on Google Code. A simple add-on library for Spring that adds Guice like programmatic configuration. Spruice uses JMock style proxies for programmatic configuration of a Spring context.

Features Integrates with existing spring application contexts Fluent interface for configuring and wiring objects Fully type safe and refactoring friendly configuration Plain java code, so it is easy to create dynamic configurations without fighting with XML or annotations No Annotations or specialized interfaces required Support for init, start, stop, and destroy lifecycle methods without framework specific interfaces or magic strings in text files Container based dependency injection Pure POJO dependency injection Dependencies Example SpruiceModule module = new SpruiceModule() { public void wire(Binder binder) { BeanConfig<Car> carConfig = binder.autowire(Car.class); carConfig.startWith().start(); carConfig.stopWith().turnOff(); // bean name of 'car' is automatically created from the class name 'Car'.

Instance Configuration. An Introduction to Spring AOP. We Recommend These Resources This article discusses Spring AOP in a tutorial format. It covers some of the newer features of Spring AOP like annotations, improved XML configuration and more. It builds on the DIIntroTutorial. It is meant as a simple introduction to AOP. Enough information so you –can use AOP on a project. Spring 2.x AOP For some, AOP seems like voodoo magic.

The first time that I used AOP was with Spring's transaction management support. You can think of AOP as a way to apply services (called cross-cutting concerns) to objects. I've using AOP to apply caching services, transaction management, resource management, etc. to any number of objects in an application. You can think of AOP as a dynamic decorator design pattern. Sample Application Revisited or this introduction to AOP, let's take a simple example. Perhaps the objects that needed the SecurityService could access it as follows: if (! Transport.communicateWithBank(...); } A community effort to offer build, version and quality assurance. Spring: A Quick Journey Through Spring AOP.

Migrating to Spring 2: Part 3 - injecting dependencies into enti. Advanced data binding within the Spring Framework. Implement crosscutting concerns using Spring 2.0 AOP - Java Worl. Most developers will acknowledge how implementing crosscutting concerns such as logging, auditing, security and transactionality can adversely affect business logic implementation. Such concerns "seem" to increase the complexity of existing business logic, at times making it difficult if not impossible to clearly distinguish business logic from the crosscutting concern implementation. I had been hearing about aspect-oriented programming (AOP) being a solution for implementing crosscutting concerns. But having read through early AOP tools documentation, I was dissuaded from using AOP in my projects' recommendations, primarily because of a concern that average developers might not "get" AOP concepts, and the overall ability to debug applications, and maintain them, might be restricted to those few who understood AOP.

Recently released Spring 2.0 provides excellent, easy-to-use AOP capabilities. SecurityLoggingTransactionality Let us start with an example code snippet: AOP basics Logging. Spring 2.0: What&#039;s New and Why it Matters. Themes Since the open source project began in February, 2003, the Spring Framework has gone from strength to strength. It has powered past 1 million downloads; become a de facto standard in a wide range of industries; and changed the development of enterprise Java applications.

Most important, it has developed a large and loyal user base, which understands its key values and has contributed feedback that has helped it to advance rapidly. Spring's mission always been clear: To provide a non-invasive programming model. As far as possible, application code should be decoupled from the framework. Spring 2.0, which went final in October, 2006, further advances these values. Some decisions were easy. As work on Spring 2.0 progressed through 10 months of development, we also needed to take into account several trends that became evident in Spring usage in 2005-2006: Spring is increasingly used by very large organizations, who are adopting it strategically rather than project-by-project.

Outline. Spring 2.0 AOP - Spruce Up Your Domain Model. Just started playing around with Spring 2.0 and poke at some of the new features over the weekend. The coolest dude of them looked like the ability to attach post-instantiation processors to beans which have NOT been instantiated by the Spring container. This means a lot to me when I started thinking about how this feature can add value to the current scheme of things in a POJO based Spring configured application. Have a look at the following domain class from our current application : // models a security tradepublic class Trade { // state // getters and setters // domain behavior}A typical domain object is instantiated in the application either from the ORM layer (read Hibernate through persistence services) or by the user using factories.

Domain layer should be persistence agnostic The domain classes should be unit-testable without the service layer Proliferation of business logic in the controllers Let me explain a bit on the third point .. Enter Spring 2.0 Getaways. Getting Started with EasyMock2. Unit tests are no longer hype, but daily business. Developers love writing tests, and even do test-driven development. But testing units of code often is a problem: most parts of a software system do not work in isolation, but collaborate with other parts to get their jobs done. In unit testing, we do not want to test these collaborating objects, but only the unit under test. Mock objects provide a solution to this dilemma: they can be set up to behave as expected, so they are a perfect replacement for collaborators of the unit under test. Writing mock objects on your own can be tedious, but there are a lot of mock frameworks out there to help you with this task.

For those out there who already know EasyMock: What's so special about version 2? No more need for a dedicated control object.Heavy usage of generics eliminates casts.New matcher API allows fuzzy parameter matching.Check call order of more than one mock.Dynamically respond to mock method calls. Curious? Last Exit to Springfield. Don&#039;t repeat the DAO! Pragmatic byte code manipulation - Cglib.

AOP@Work: Dependency injection with AspectJ and Spring. AOP@Work: AOP myths and realities. Generically chain dynamic proxies. Programming with plain-old Java objects (POJOs) is rather popular these days. When we program with POJOs, we can apply object-oriented programming (OOP) pretty easily. But sometimes implementing cross-cutting aspects throughout an application using OOP proves difficult. For example, generally implementing logging or security in our POJO business objects throughout an application is difficult to achieve with OOP. Dynamic proxies, which were introduced in J2SE 1.3, offer an easier solution. The idea behind dynamic proxies is to include dynamic behavior around an object, yet neither change the object's existing code nor its interface. The famous Gang of Four (GoF) Decorator pattern provides a way to decorate an object (change its behavior) without changing the object code and allows us to add cross-cutting aspects to our business objects.

Prior to the introduction of dynamic proxies, there was no direct way to decorate objects dynamically. Suppose we have a simple business interface: Atrack: Home.