Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Spring Roo 1.1 Cookbook
  • Table Of Contents Toc
Spring Roo 1.1 Cookbook

Spring Roo 1.1 Cookbook

4.7 (3)
close
close
Spring Roo 1.1 Cookbook

Spring Roo 1.1 Cookbook

4.7 (3)

Overview of this book

Spring Roo is an easy-to-use productivity tool for rapidly developing Java enterprise applications using well-recognized frameworks such as Spring, Hibernate, AspectJ, Spring Web Flow, Spring Security, GWT, and so on. Spring Roo takes care of creating maven-enabled projects, enterprise application architecture based on your choice of technologies, unit/integration tests based on your choice of testing framework, and so on. The bottom line is that if you're using Spring, then you must consider using Spring Roo for increased productivity. Spring Roo 1.1 Cookbook brings together a collection of recipes that demonstrate how the Spring Roo developer tool simplifies rapidly developing enterprise applications using standard technologies/frameworks such as JPA, GWT, Spring, Flex, Spring Web Flow, Spring Security, and so on. It introduces readers to developing enterprise applications for the real world using Spring Roo tool. The book starts off with basic recipes to make readers comfortable with using Spring Roo tool. As the book progresses, readers are introduced to more sophisticated features supported by Spring Roo in the context of a Flight Booking application. In a step-by-step by fashion, each recipe shows how a particular activity is performed, what Spring Roo does when a command is executed, and why it is important in the context of the application being developed. Initially, you make a quick start with using Spring Roo through some simple recipes. Then you learn how Spring Roo simplifies creating the persistence layer of an enterprise application using JPA. You are introduced to the various roo commands to create JPA entities, create relationships between JPA entities, create integration tests using Spring TestContext framework, and so on. Following this, the book shows you how Spring Roo simplifies creating the web layer of an enterprise application using Spring Web MVC, Spring Web Flow, and how to create selenium tests for controller objects. Subsequently, we focus on using Spring-BlazeDS, GWT, JSON, and so on. Spring Roo commands that are used to incorporate e-mail/messaging features into an enterprise application are demonstrated next. Finally, we wrap it up with some miscellaneous recipes that show how to extend Spring Roo via add-ons, incorporate security, create cloud-ready applications, remove Spring Roo from your enterprise application, and so on.
Table of Contents (14 chapters)
close
close
Spring Roo 1.1 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1
Index

Moving existing Spring projects to use Spring Roo


If you are moving your existing Spring-based project to Roo, you can make out from this recipe that you should do the following:

  1. Remove the toString method and add the @RooToString annotation to all your existing classes.

  2. Remove the implementation of Serializable interfaces from classes and instead annotate the classes with the @RooSerializable annotation.

  3. Remove getters and setters methods from your Java classes and instead annotate the classes with the @RooJavaBean annotation.

Tip

Registering the service class with Spring's application context

Using Spring Roo you can't create a service class, which is automatically registered with Spring's application context; therefore, if you want your service class to be auto-registered, then annotate it with the @Service annotation. The service class will be registered with Spring's application context as long as it is inside the top-level directory (for more information refer to the <component-scan> element, described in the Creating a Roo project recipe).

@RooToString—customizing the name of the toString method

We saw that using the @RooToString annotation creates a method named toString in the corresponding AspectJ ITD file. You can use the toStringMethod attribute of the @RooToString annotation to specify a custom name for the toString method, as shown here:

@RooToString(toStringMethod = "myTostring")
public class MyCustomClass { private String myAttr; }

In the given code, the toStringMethod attribute specifies myToString as the name of the method to act as the toString method for the MyCustomClass. The ITD file corresponding to the @RooToString annotation: MyCustomClass_Roo_ToString.aj will now create a method similar to toString but with the name myToString, as shown here:

privileged aspect MyCustomClass_Roo_ToString
{
   public String MyCustomClass.mytostring ()
   {
      StringBuilder sb = new StringBuilder();
      sb.append("MyAttr: " ).append(getMyAttr());
      return sb.toString();
   }
}

@RooToString—excluding properties from the toString method

In some cases, you may want to restrict properties from being part of the auto-generated toString method. The @RooToString annotation provides an excludeFields attribute, which lets you specify an array of attributes that should be excluded from the auto-generated toString method, as shown here:

@RooToString(excludeFields={"someAttribute"})
public class MyCustomClass { .. }

In this code, the @RooToString annotation instructs that the toString method of the MyCustomClass class must not include the someAttribute property.

See also

  • The Adding attributes to a Java class recipe explains how you can add attributes to a Java class using roo

  • The Creating a Java interface recipe explains how you can create a Java interface from the Roo shell

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Spring Roo 1.1 Cookbook
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon