You are previewing Spring Roo 1.1 Cookbook.
O'Reilly logo
Spring Roo 1.1 Cookbook

Book Description

"

Over 60 recipes to help you speed up the development of your Java web applications using the Spring Roo development tool

  • Learn what goes on behind the scenes when using Spring Roo and how to migrate your existing Spring applications to use Spring Roo

  • Incrementally develop a Flight Booking enterprise application from scratch as various features of Spring Roo are introduced

  • Develop custom add-ons to extend Spring Roo features

  • Full of tips and code for addressing common concerns related to developing a real enterprise application using Spring Roo

In Detail

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.

A fast-paced guide that helps you effectively use Spring Roo for developing enterprise applications

"

Table of Contents

  1. Spring Roo 1.1 Cookbook
    1. Spring Roo 1.1 Cookbook
    2. Credits
    3. About the Author
    4. About the Reviewers
    5. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    6. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    7. 1. Getting Started with Spring Roo
      1. Introduction
      2. Setting up Roo
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      3. Using Spring Roo with Eclipse/STS
        1. See also
      4. Getting help and hints from Roo
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Passing arguments to Roo commands
          2. Log file for executed Roo commands
        5. See also
      5. Creating a Roo project
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      6. Importing a Roo project into Eclipse or IntelliJ IDEA IDE
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      7. Configuring logging
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      8. Viewing properties defined in a properties file
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      9. Managing properties defined in a properties file
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      10. Creating a Java class
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      11. Moving existing Spring projects to use Spring Roo
        1. @RooToString—customizing the name of the toString method
        2. @RooToString—excluding properties from the toString method
        3. See also
      12. Adding attributes to a Java class
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. @RooJavaBean—controlling the generation of getter and setter methods
        5. See also
      13. Creating a Java interface
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      14. Referring to a type from the Roo shell
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      15. Creating application artifacts from Roo script
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
    8. 2. Persisting Objects Using JPA
      1. Introduction
      2. Setting up a JPA provider for your project
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. JNDI-bound data source
        5. See also
      3. Viewing database configuration properties
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      4. Managing database configuration properties
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      5. Creating persistent entities
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Adding table column information in persistent entity fields
          2. The class argument in roo commands
        5. See also
      6. Adding JSR 303 constraints to persistent fields
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      7. Controlling auto-generated methods of persistent entities
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      8. Creating integration tests for persistent entities
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Customizing seed data creation
          2. Controlling integration test methods
          3. Generating integration tests at the time of entity creation
          4. Providing custom implementation for integration tests
        5. See also
      9. Creating new 'data on demand' for testing entities
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      10. Creating mock tests for persistent entities
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      11. Executing persistent entities tests
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      12. Creating applications that interact with multiple databases
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      13. Packaging your Roo project
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
    9. 3. Advanced JPA Support in Spring Roo
      1. Introduction
      2. Viewing candidate dynamic finder methods
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Listing dynamic finder methods for multiple persistent fields
          2. Limiting list of dynamic finder methods, based on a filter criteria
        5. See also
      3. Adding dynamic finder methods to an entity
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Adding custom finder methods
          2. Integration testing of dynamic finder methods
          3. Adding dynamic finders through @RooEntity annotation
        5. See also
      4. Creating a many-to-one (or one-to-one) relationship between entities
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Testing JPA entities that participate in relationships
          2. Dynamic finder method for a many-to-one relationship field
        5. See also
      5. Creating a one-to-many (or many-to-many)relationship between entities
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      6. Creating a mapped superclass
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Creating @Embeddable annotated classes
        5. See also
      7. Customizing Roo-generated identifier definition
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      8. Generating database metadata
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      9. Creating entities from a database
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Installing JDBC drivers for Oracle and DB2
          2. Modifying auto-generated JPA fields/relationships
          3. Incremental database reverse engineering
          4. Database table with composite primary key
        5. See also
    10. 4. Web Application Development with Spring Web MVC
      1. Introduction
      2. Auto-generating Spring MVC controllers andJSPX views from JPA entities
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Configuration information defined in web.xml
            1. contextConfigLocation initialization parameter
            2. ContextLoaderListener
            3. DispatcherServlet
            4. OpenEntityManagerInViewFilter
            5. HiddenHttpMethodFilter
            6. Exception pages
          2. Beans and configurations defined in webmvc-config.xml
            1. Controller auto-detection
            2. Annotation-driven development support and conversion service
            3. ResourceHttpRequestHandler
            4. DefaultServletHttpRequestHandler
            5. Theme and locale change interceptors
            6. ParameterizableViewController
            7. View resolution
            8. Tiles definitions
            9. Exception handling
            10. Miscellaneous configuration
          3. Roo-generated controllers
        4. There's more...
        5. See also
      3. Packaging, deploying, and using aRoo-generated Spring MVC application
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. Running Roo project in embedded Jetty container
        6. See also
      4. Modifying Roo-generated views
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Changing the displayed application name and welcome text
          2. Changing menu options
            1. Significance of z attribute of Roo installed JSP tags
          3. Understanding a Roo-generated JSPX file
          4. Switching elements from user-managed to Roo-managed mode
        4. See also
      5. Round-tripping support in Spring Roofor web controllers and views
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      6. Creating a Spring MVC controller for a specific JPA entity
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Overriding auto-generated controller methods
        5. See also
      7. Manually creating a Spring MVC controller for a JPA entity
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Scaffolding Spring Web MVC application for a one-to-many relationship
        5. See also
      8. Adding static views to a Roo-generated web application
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      9. Internationalizing Roo-generated web applications
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      10. Adding or modifying themes generated by Roo
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      11. Adding JSON support to domain objects and controllers
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      12. Creating and executing Selenium tests for web controllers
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Selenium test scripts
          2. Selenium test suite
        4. There's more...
        5. See also
    11. 5. Web Application Development with GWT, Flex, and Spring Web Flow
      1. Introduction
      2. Scaffolding GWT applications from JPA entities
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. GWT module descriptor
          2. The GWT module's entry point
          3. Dependency injection using GIN
          4. EntityProxy, RequestContext, and RequestFactory interfaces
          5. Activities and places
          6. Dealing with entity proxy-specific processing
        4. There's more...
          1. Compiling and running the GWT application in an embedded Jetty container
          2. Accessing the mobile version of the GWT application
          3. Round-tripping support for GWT applications
          4. Enabling remote logging
        5. See also
      3. Getting started with Flex application development
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Flexmojos Maven plugin configuration
        5. See also
      4. Scaffolding a Flex application from JPA entities
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      5. Getting started with Spring Web Flow
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Spring Web Flow configuration
          2. Developing applications using both Spring Web MVC and Spring Web Flow
        4. There's more...
        5. See also
    12. 6. Emailing, Messaging, Spring Security, Solr, and GAE
      1. Introduction
      2. Sending e-mails using JavaMail API
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Setting up e-mail sending support
          2. Setting up a mail message
          3. Sending mails
        4. There's more...
          1. Sending e-mails asynchronously
          2. Sending e-mails with attachments
          3. Sending e-mails with JavaMail Session configured in JNDI
        5. See also
      3. Sending and receiving JMS messages
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Setting up a JMS provider
          2. Sending message using JMS Template
          3. Creating a JMS message consumer
        4. There's more...
          1. Sending JMS messages asynchronously
        5. See also
      4. Configuring Spring Security for your application
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Spring Security application context XML file
            1. AuthenticationManager configuration
            2. Web request security configuration
      5. Using Spring Security with Apache Directory Server
        1. Flight Booking application requirements
        2. Getting ready
        3. How to do it...
        4. How it works...
          1. Setting up embedded Apache Directory Server
          2. Authenticating against the LDAP server
          3. Configuring web request security
          4. Configuring method-level security
          5. Adding @Secured annotation to JPA entity methods
      6. Deploying a GWT application on GAE
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. appengine-web.xml
          2. Maven GAE plugin
          3. Maven DataNucleus plugin
          4. Persistent entities
          5. Authentication and authorization in GAE applications
      7. Deploying a Spring Web MVC application on GAE
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Owned relationship
          2. Managing persisted data using Admin Console
        4. There's more...
        5. See also
      8. Adding search capability to your domain model with Sol
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Configuring Solr for Roo project
          2. Adding domain model data to Solr index and searching Solr documents
            1. Methods and attributes introduced by *_Roo_SolrSearch.aj AspectJ ITD
          3. Searching Solr documents
        4. There's more...
          1. Customizing Roo-generated *_Roo_SolrSearch.aj AspectJ ITD
    13. 7. Developing Add-ons and Removing Roo from Projects
      1. Introduction
      2. Setting up GnuPG for add-on development
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      3. Installing an installable add-on
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Trusting add-ons by default
          2. Installing add-ons not indexed by RooBot
        5. See also
      4. Developing a simple add-on
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. MysimpleCommands class
            1. Defining Roo commands
              1. Making Roo commands unavailable
          2. The MysimpleOperations interface and MysimpleOperationsImpl class
          3. MysimpleNameProperty enum type
        4. There's more...
          1. Deploying and running mysimple add-on
            1. Using the mysimple add-on in a Roo project
          2. Tab-completion feature with constant values
          3. Multiple command availability using @CliAvailabilityIndicator
          4. Templates in Roo add-ons
          5. The pom.xml file
          6. OSGi commands for troubleshooting
        5. See also
      5. Developing an advanced add-on
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. The MyadvancedCommands class
          2. The MyadvancedOperationsImpl class
          3. The MyadvancedMetadataProvider class
            1. Dependency registration and unregistration
            2. Registering and unregistering metadata creation trigger
            3. Code generation functionality of add-ons
        4. There's more...
        5. See also
      6. Converting non-OSGi JDBC drivers into OSGi-compliant bundles
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      7. Removing Roo with push-in refactoring
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Push-in refactoring—single AspectJ ITD file
          2. Push-in refactoring – across the whole project
        5. See also
      8. Adding Roo to a project using pull-out refactoring
        1. Getting ready
        2. How to do it...
        3. There's more...
        4. See also
      9. Upgrading to the latest version of Roo
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...