background preloader

Annotations

Facebook Twitter

Mapper

Project Lombok. Stereotype Annotations Cut Down XML Configuration in Spring. Nnotations have been part of the Spring Model-View-Controller (MVC) Framework since Spring 2.0. In Spring, annotations can greatly reduce the amount of XML bean configuration and wiring needed. Given the many components of the Spring MVC environment (handler mapping, controller, view resolver, and view), XML configuration can turn unwieldy in a hurry. So, Spring MVC configuration is certainly one area that can really benefit from reduced configuration. As of Spring 2.5, the framework added new annotations to more easily configure and assemble the components of a multi-layered application, such as you might find in an MVC-designed system. Are these new annotations critical to your applications? In Spring framework 3.0 there will be a number of deprecations, for example, the old MVC controller hierarchy. That makes these new annotations, in particular those associated to Spring MVC, pretty important.

Stereotype Annotations. Annotation based Caching in Java. I probably had to write cache to store results of expensive operations or queries a dozens of times over last ten years of Java. And this week, I had to redo again. Though, there are a lot of libraries such as JCS , Terracota or Tangosol, but I just decided to write a simple implementation myself. First I defined an annotation that will be used to mark any class or methods cachable: 1 import java.lang.reflect.*; 2 import java.lang.annotation.*; 3 4 5 6 7 8 9 @Target({ElementType.TYPE, ElementType.METHOD}) 10 @Retention(RetentionPolicy.RUNTIME) 11 public @interface Cacheable { 12 13 14 15 boolean cache() default true; 1617 18 19 20 21 22 int maxCapacity() default 1000; 2324 25 26 27 28 boolean synchronizeAccess() default false; 2930 int timeoutInSecs() default 300; 3132 33 34 35 public boolean canReloadAsynchronously() default false; 36 } 3738 I then defined a map class to store cache: A couple of interfaces to load or search key/values: A utility class for storing pair of objects:

Annotation-Based Transactions in Spring - Wheeler Software. I n this article, I'm going to show you how to use transaction management annotations in Spring. I'm using Spring 2.5 though these features have been available at least since Spring 2.0. Spring provides several different approaches to transaction management: Programmatic: You can write your transactions using Java source code directly. Normally you wouldn't do this unless you needed fine-grained control over some particular transaction. Declarative: You can declare transaction definitions in either a centralized way using XML or in a distributed way using annotations: XML-based: You can configure transactions in Spring's centralized application context file.

Proxy-based: In this approach you wrap your service beans with transactional proxies. AOP-based: Here you define AOP aspects to endow your service beans with transactional semantics. Annotation-based: You can use Java 5 annotations to distribute transaction configuration across Java classes. A Practical Guide to Using an Aspect Library (part I) « What's on your bookshelf?

| Main | Tips for using Eclipse effectively » February 20, 2006 A Practical Guide to Using an Aspect Library (part I) This entry represents part one of a two-part guide to using an aspect library (with AspectJ). Introduction With the arrival of AspectJ 5 and the Spring 2.0 milestone builds, many of you will be working with AspectJ-based aspect libraries for the first time. I'm assuming that for the time being you don't want to write your own aspects: you just want to use the capabilities of an existing library. The library supports an @Configurable annotation. @Configurable public class Account {...} When the annotation is used like this without a value, an instance of Account will be dependency injected by Spring, using the fully-qualifed class name of Account as the bean name. @Configurable("accountBean") public class Account {...} @Configurable(autowire=Autowire.BY_NAME) public class Account {...} Development, unit testing, and simple integration testing Comments.

Seema Richard's Blog: Annotation based configuration in Spr. Posted by seemarich on November 27, 2007 at 4:14 AM PST It is now possible to configure Spring's dependency injection with annotations. This means that annotations can be used in Spring to mark fields, methods and classes that need dependency injection. Collaborating beans by inspecting the contents of the BeanFactory.

Can be used to indicate fields that are to be auto-wired. Annotated components in the classpath is also supported now. Combined, the amount of configuration and dependency mapping in the Spring configuration files is reduced drastically. According to the Spring development team, the core theme of Spring 2.5 that was released in October 2007 is to provide comprehensive support for configuration annotations in application components.

Enhanced in Spring 2.5. I'll briefly discuss the annotation-driven configuration and auto-detection support in Spring 2.5 with the help of a simple tutorial. What you need before you start You need the following software to try out the tutorial. Java 5.0.