brought to you by... #147

CONTENTS INCLUDE:

n About SpringSource Tool Suite n Project Configuration Tools for Spring: n Starting a Project from Scratch n Bean Configuration n Validation The SpringSource Tool Suite n Bean Navigation & Analysis

Visit refcardz.com By Gordon Dickens, Chariot Solutions

the “Available Sites” link shows the currently configured plugin sites. ABOUT SPRINGSOURCE TOOL SUITE The Dashboard SpringSource Tool Suite (STS) is an Eclipse-based IDE with When you start STS, one of the first things you will see is the pre-installed plugins that provides valuable features for Spring Spring Dashboard. At the bottom of this view are two tabs: developers. In addition to support for the core , Dashboard and Extensions. The Dashboard tab contains five STS also provides visual editors, project validators, and Spring sections: Dashboard for other projects such as Spring Roo, , Groovy, 1. Create – Spring, , Grails & Groovy Projects Gradle, tcServer, and Spring Insight. 2. Updates – Update information for STS The main plugin for STS is Spring IDE, which provides the 3. Tutorials – Spring, Security, Web, Web Flow, WS Get More Refcardz! Refcardz! Get More fundamental Spring tooling features. STS comes preconfigured 4. Help & Docs – Forums, JIRA, STS New & Noteworthy with many other plugins such as M2Eclipse for Maven, Web 5. Feeds - RSS announcements from Spring and Spring Blog Tools Platform (WTP), Data Tools Platform (DTP), and AspectJ posts Development Tools (AJDT) and JUnit tooling. Why use STS? The Extensions tab contains two tabs: 1. Extensions tab provides options for installing Roo, Groovy, • Content aware XML Spring Bean editing and refactoring Grails, and other useful extensions such as Google (GWT & • Content-aware Spring shortcuts for Java classes GAE), CloudFoundry, DataNucleus, EGit, FindBugs, PMD, and more. • Visualizers for graphical configuration editing 2. The Find Updates tab checks for extension updates. • Validators for project configuration

• Dashboard Hot To Manage the Dashboard: Preferences > Spring > Dashboard • Spring tcServer and Insight Tip Add Spring blogs like: http://gordondickens.com/wordpress/feed/

Getting STS STS is available from SpringSource: PROJECT CONFIGURATION http://www.springsource.com/developer/sts To take advantage of Spring tooling features, add the Spring Project STS version numbers are different than the Eclipse versions. Nature to each project. Then you can view the project in Spring When choosing versions from the Spring site, go the current Project Explorer and define bean config files and config sets. version of STS to see the supported Eclipse versions. If you’re using Maven, you can configure this in your pom.xml file When installing STS from the native installer, it prompts you to using the maven-eclipse-plugin: install optional products such as Spring Roo, , and tcServer Developer edition. If these features are already installed and configured, uncheck these products.

Already have Eclipse? If you already have Eclipse 3.6, download the STS plugin as follows: 1. Before installing STS, ensure you have the current JDK installed. 2. Download the bookmarks file from: http://dist.springsource.com/ release/TOOLS/composite/e3.6/bookmarks.xml. 3. In Eclipse, select Preferences -> Install/Update -> Available Who is answering your Update Sites. Customers questions? 4. Click the “Import…” button, select the downloaded “bookmarks. xml”, and click “Open” to finish the import. If you are using another version of Eclipse, find installation instructions here: http://www.springsource.com/products/eclipse- downloads. The Enterprise Q&A System Manage the plugin sites from Help > Install New Software… Clicking SpringSource Tool Suite Tool SpringSource

DZone, Inc. | www.dzone.com 2 SpringSource Tool Suite

... org.apache.maven.plugins maven-eclipse-plugin 2.8 true true 1.5 org.springframework.ide.eclipse.core.springbuilder Project Explorer View This view provides you with the ability to look at the project by its org.springframework.ide.eclipse.core.springnature component types such as Spring Elements, Bean Config Files, Bean Config Sets, Web Service components, Java Resources, and more. ... Once the Maven Eclipse plugin is installed, you can generate the Eclipse project files from the command prompt with:

A project configured with Spring Project Nature will have an “S” over Hot the project, bean config files and directory icons containing bean Tip config files.

Spring Perspective The Spring Perspective is an Eclipse perspective displaying views such as Spring Explorer and other standard Eclipse views: Servers, Spring Explorer, Task List, Outline, Console, Markers, and Progress. This is a convenient layout that can be customized to your liking. Bean Config File Once you have added Spring Project Nature to your project, you Spring Explorer View can create or mark bean config files. This view provides the ability to see the Bean Config files within Spring projects. Here you can view the beans graph visualizer, create Creating a Spring config file – From Package Explorer, click the bean config files, define Bean Config sets, define new beans, validate directory for the XML file and choose: beans, and openf MVC request mappings. File > New > Spring Bean Configuration File Bean Config files are XML files defining beans and bean relationships within a project. If you are using a project and don’t remember Locating Spring config files - from Spring Explorer view, right-click where the Bean Config files are located, open Spring Explorer. Within the project: Spring Explorer, right-click a config file and choose from several Properties > Spring > Beans Support “Scan” button options: the directory for the XML file and choose: • Open Dependency Graph - the visualizer for bean File > New > Spring Bean Configuration File relationships. This is the same as the “Bean Graph” tab available in the bean editor. Hot Bean config files will appear with the “S” over the directory and file. • New Bean Definition - provides a dialog for entering bean Tip definitions. • RequestMapping - opens a view for MVC applications showing all the request mappings configured in this file. Validate - validates the bean configuration file based on Bean Config Sets Bean config sets allow you to group bean config files together. the Spring Bean Using Config Sets provides the ability to validate beans and bean • Validate - will validate the bean configuration file based relationships defined within multiple bean config files. Validation on the Spring configuration settings in also provides suggestions via content assist when editing. preferences. This feature is particularly useful when you have infrastructure • Properties - opens project beans, validation, config set beans such as dataSource defined within a test config file and dialog. In this dialog we have the option to scan for more the application’s entity, services, etc defined in a common bean configuration files with the “Scan” Button. config file that is the same for all deployment platforms. You do not have the ability to assign config sets to any components or tests. This is unnecessary as STS performs cross-file validation on all config sets. If the bean config files within a config set do not define all referenced beans, mark a config set by checking the “Is

DZone, Inc. | www.dzone.com 3 SpringSource Tool Suite

incomplete” checkbox. If checked, the BeansConfigValidator press CTRL-Space after the “T” to get a long list of beans matching doesn’t complain about missing bean references within this J and T. Narrow by then press CTRL-Space config set. after the “T” to get a shorter list where you can choose JmsTemplate. The complete package and classname is entered for you.

Spring MVC Request Mappings When configuring properties of a bean, content assist provides you Spring MVC is very powerful and easy to configure using with the available properties that you can set in the XML config. annotations. The MVC Request Mappings view displays the request mappings for an MVC project. In Spring Explorer, right-click an MVC project, config file, or config set and select RequestMappings to see the URL details in a tabular view. If it is not an MVC application, this view is empty. The view provides the By hitting CTRL-Space within the quotes of the property name, you following details: are prompted with all of the properties available to set. • Resource URL Spring also provides XML templates to quickly insert config within the xml files. For example, on a blank line in the bean config editor, type • Resource Method: GET, POST, etc. “bean” and press CTRL-Space. • Handler Method • JavaDoc Within the view, Double click on line to go to the code.

STARTING A PROJECT FROM SCRATCH Choose Bean - Inserts a Bean Tag and below shows the example of what will be inserted into the code: Spring Project This option is extremely bare bones and only creates a basic Java project with src directory and Spring Project Nature added. No Spring dependency jars or other structures are configured. It is recommended to use the Spring Template Projects instead. Hot View, add or modify XML bean templates in Preferences > Spring > Tip Beans Support > XML Templates See the Spring Dashboard for quick links to create Spring, Groovy, Grails, and Spring Roo projects.

Spring Template Project From the File > New menu, you can create a Spring project using the predefined templates from SpringSource. These templates provide a convenient starting point for different Spring projects. The projects created from these templates are configured as Maven projects with the necessary project (JAR) dependencies. Note: Many of the templates may require manual updating of project configuration. Updating configuration is often in two main Bean Editor Tabs areas: version dependencies in pom.xml and bean config file A series of Tabs will display at the bottom of the editor based on the namespaces for the latest project versions. content of the XML namespaces used. Overview tabs for specific namespaces include JDBC, Spring Integration, Spring Batch and Web Flow. BEAN CONFIGURATION

Bean Editing The bean editor in STS provides features beyond a standard XML • Source – The XML editor editor. In the java editor, you are already familiar with content assist. Spring adds content assist when typing in bean declarations. For • Namespaces - Choose namespaces to include/exclude in example, in the bean config editor (and throughout Eclipse), you can the configuration file, without the risk of typos. use camel case when typing bean names. This provides the ability • Configure the namespace discovery in Preferences > to enter the class name without having to know the full package or Spring > Beans Support > Namespaces spelling of the bean. • Overview - General overview of the beans within a bean For example: definition file. A tree hierarchy shows the beans, nested If you want to configure JmsTemplate, type and beans and bean properties.

DZone, Inc. | www.dzone.com 4 SpringSource Tool Suite

• Namespace specific tabs – provide bean information for namespaces we have selected. Such as: context, jee, tx, STS Rule Description etc. Driver Manager Data Source Validates the project does not use this class

Beans Graph – Display’s graphical representation of beans (see Bean Inheritance Recommends bean inheritance for simplification Visualizers below) Import Elements at Top Recommends imports before other bean definitions

Hot Configure the namespace discovery by selecting Preferences > Parent Beans not Abstract Validates that parent beans are not abstract Tip Spring > Beans Support > Namespaces. Too Many Beans Validates too many beans in file – approx. 80 beans

Unnecessary Ref Check for ref elements and recommends ref attribute VALIDATION instead. instead of Spring project validation rules are available in Preferences > Spring > Unnecessary Value Checks for value element and recommends value attribute Project Validators section. instead. instead of There is only one option to verify Spring is in the classpath. This Dedicated Namespace Checks for cases where dedicated namespaces can be validator is disabled by default. There are three categories: Bean Syntax used validation, STS validation, and Spring validation. Once enabled, from Package Explorer view, R-Click on the project Bean Validation and select validate. There are 15 rules available, most enabled by default. These rules validate bean names, aliases, deprecation, @Required annotation, STS Validation errors will be displayed in the Markers and Problems constructor injection, and Autowired annotation types (@Autowired, views. @Resource, @EJB). Once corrected actions are made, you may need to remove the validation markers. R-Click on project > Spring Tools > Remove Bean Rule Description Validation Markers and then validate again.

Required Property Validates @Required annotation Annotation-based Validates @Autowired, @Resource and @EJB annotations Bean Refactoring Auto wiring The Bean Config editor provides the ability to refactor bean Bean Alias Validates alias names associated with bean definitions. In the editor, right-click on a bean definition, select “Refactor…” and you will see three options: Bean Class Validates a bean class 1. Refactor Property Element – Nested ref and Bean Constructor Validates non-abstract bean’s constructor arguments Argument value tags.

Bean Definition Holder Validates Root bean’s name and aliases 2. Move Bean Element (class)… - Move class to another package. Bean Definition Validates a bean’s definition 3. Rename Bean Element (id, class, property name)… - Rename bean id, can search for literal string Bean Deprecation Validates init, destroy and setters are not deprecated references and similarly named classes.

Bean Factory Validates a factory beans and factory methods BEAN NAVIGATION & ANALYSIS Bean Init and Destroy Validates non-factory beans init and destroy method Method Within STS, you can quickly open a bean or view bean cross references or bean Bean Method Override Validates bean method override outline from the Eclipse Search and Navigate menu options.

Bean Property Validates bean’s property accessor method is in bean class Finding Spring Beans From Search > Beans, you can conduct a wildcard search for beans Bean Reference Validates bean references depends-on attribute, a value by name, class, property name, beans referencing, and child beans. holder or collection type Navigate > Open Spring Bean displays a search box where you can XML Parsing Problems Validates XML file is parseaable search for class names using camel-case. XSD Tool Annotation Validates attributes based on schema Beans Quick Cross References Within the bean config editor, select Navigate > Beans Quick Cross STS Validator References to show the beans cross references for the current bean The eight STS validator options are project-wide validation rules. file. From here, you can jump to the bean declaration. These validators are disabled by default. Note: • Beans Cross References view is for Spring • Cross References view is for AspectJ Beans Quick Outline Within the bean config editor, select Navigate > Beans Quick Outline to display an outline list of all bean declarations and property settings. You can search for a specific bean by ID and click a bean to see its definition.

DZone, Inc. | www.dzone.com 5 SpringSource Tool Suite

Beans Cross References View This view shows cross references based on the open file. By default, this view is VISUALIZERS empty until you click the “Link with Editor” in the title bar of the view (gold arrows). STS provides the ability to graphically view and edit Spring configuration. The five visualizers are beans, Spring Integration, Spring Batch, Web Flow, and Aspects.

Beans Graph SPRING ASPECT ORIENTED PROGRAMMING (AOP) The Beans Graph provides a visual diagram of the Beans and Bean Relationships within a config file or config set. Spring AOP support in STS is extends the installed AspectJ Development Tools (AJDT) plug-in. The Beans Graph provides a visual diagram of the Beans and Bean Relationships within a config file or config set. Spring Aspects Tooling Spring AOP support in STS extends the installed AspectJ Within a Bean Config file, the tab “Beans Graph” displays beans Development Tools (AJDT) plug-in. within the file. Right-click on a project. Under Spring Tools, there is an option to enable Spring Aspects Tooling. This enables AJDT weaving features within a project. With this setting, AJDT weaves itself into JDT with features:

• TD-aware reconciling/eager parsing • TD-aware content assist • TD-aware type hierarchies • Search for aspect elements using standard Java search

and Open Java type From Project Explorer, expand the project under Spring Elements, Source: http://wiki.eclipse.org/JDT_weaving_features right-click the Config Set name, and choose “Open Dependency Graph”. AOP Event Trace The AOP Event Trace view provides log-like detail during a project build. The view logs information about the Spring IDE’s internal AOP model creation. To enable this feature:

1. Add spring-aspects.jar to the project.

2. Right-click project > Spring Tools > Enable Spring Aspects Tooling.

3. Select Preferences > AspectJ Compiler > Other > Check Verbose & Pointcut matching timers.

Set preferences for Beans Graph in Preferences > Spring > Beans Support • Display Inner Beans • Display Infrastructure Beans • Display Extended Content (Autowired beans)

Spring Pointcut Matches This feature is enabled by default in Preferences > Spring> Beans From the Search menu, we can use Spring AOP Pointcut expressions Support > Editor > Enable embedded graph pages. and test pointcuts such as: Integration Graph execution(void set*(*)) When using Spring Integration, the “integration-graph” tab is available in the beans config editor. The graph displays the standard bean(transactionManager) Hohpe/Woolf diagrams from the Enterprise Integration Patterns book. This visualizer is editable using the tool pallet on the left. The tool pallet only shows tools based on the namespaces included in the XML file.

DZone, Inc. | www.dzone.com 6 SpringSource Tool Suite

Batch Graph When using Spring Batch, you see the batch-graph tab in the beans config editor. This visualizer is editable.

Aspect Visualization To see visualize Spring AOP aspects, select Preferences > Visualizer under Visualizers and then check Spring AOP Provider. You can also do this from the Visualizer view by clicking the down arrow in the view’s title bar and choosing preferences. In the view tools, select the “Hide Unaffected Bars” to show only the classes affected by aspects.

Note: You do not need to enable Spring aspects tooling for this Web Flow Graph feature to work. Spring Web Flow provides you with the ability to design Stateful page flows. The bean config editor provides the ability to edit the flows in XML or visually from theflow-graph tab.

ABOUT THE AUTHOR RECOMMENDED BOOK Gordon Dickens is an instructor/mentor/consultant Roo is a lightweight Java development tool that for Chariot Solutions (chariotsolutions.com) with works within existing processes, to rapidly produce experience in the IT consulting for over 15 years. high-quality, 100% Java code. Roo enforces correct Gordon’s background includes presenting at coding practices and patterns and instantly integrates conferences and user groups on Spring, Groovy not only with Spring, but also with virtually every & Grails, with experience developing Spring, mainstream Java technology. , Grails, Roo and OSGi applications. Gordon blogs at technophile.gordondickens.com and actively tweets Roo in Action is unique book that teaches how to code Java in Roo, open source tips at (twitter.com/gdickens). Gordon is a contributor with a particular focus on Spring-based applications. It starts by to Spring Roo in Action manning.com/rimple and very active in getting into the Roo mindset, along with a quick-and-dirty guide the Spring Framework, Roo, Spring Integration and Spring Batch to setting up Roo effectively. Through hands-on examples, readers projects. He currently teaches Maven and Spring as a Certified Spring will learn how Roo creates well-formed application structures and Instructor by SpringSource. supports best practices and tools.

#82

CONTENTS INCLUDE:

■ Browse our collection of over 100 Free Cheat Sheets About ■ Usage Scenarios Getting Started with dz.com ■ Underlying Concepts ■ Cost ... ® efcar ■ #64 Data Tier Technologies . Cloud Computing omply brought■ Platform to you Management by and more... e. C . Collaborat

isit r isit AldonChange By Daniel Rubio V

dz! also minimizes the needCONTENTS to make designINCLUDE: changes to support ABOUT CLOUD COMPUTING one time events. ■ HTML Basics dz.com ■ Upcoming Refcardz HTML vs XHTML Web applications have always been deployed on servers Automated growth & scalable technologies ■ Validation connected to what is now deemed the ‘cloud’. Having the capability■ to support one time events, cloud efcar

e Refcar Useful Open Sour computing platforms also facilitate the gradual growth curves ■ Page Structur #84 However, the demands and technology used on such servers ce T faced by web applications.■ ools isit r Key Structural Elementse Elements and m E: has changed substantiallyBy Paul in recent M. years, Duvall especially with V the entrance of service providers like Amazon, Google and Large scale growth scenarios involving specialized equipment NetBeans 7.0 Java Editor

tegration Continuous Integration: CONTENTS INCLUD ore... Patterns andMicrosoft. Anti-Patternse changes (e.g. loaddz! balancers and clusters) are all but abstracted away by ■ e at Every Change About Continuous In tterns orkspace to isolat relying on a cloud ’s technology. Cor ■ Build Softwar Description e in a Private W epository HTML BASICS These companies have long deployedntrol r web applications

■ Patterns and Anti-paol Develop softwar rging and to manage dz.com n that adapt and scale to large user bases, making them In addition, several cloud computing platforms support data e Patter fi les to a version-co ■ HTML ersion Contr HTML and XHTML ar V ore... orkspaceknowledgeableCommit allin manyline aspects to minimize r meelated to cloud computing. tier technologies that exceed the precedent set by Relational ■ Build Management Private W hat utilizes multiple e Refcar HTML is used as the graphical user interface in client-side Develop on a main Database Systems (RDBMS): Map Reduce, web service APIs, MySQL 5.5

e the foundation of all web development. efcar ■ Build Practices and m Repository active code lines e within a system t ts of work pr TION This Refcard will introducear to you to cloud computing, with an etc. Some platformsograms support written lar gein JavaScript.scale RDBMS Server deployments. The sr By e Mainline Developing softw by task-oriented uni and Java also r c attribute describes wher Andy Harris war Get Mor emphasis on these providers, so you can better understand codelines and the alt attribute describes alternate text that is displayed if

ask Level Commit isit r isit ce code changes ol as the output mechanism.eceive data The fr emer what it is a cloudganize computing sour es as aplatform T can offer your web the image is unavailable.

V ocess of building soft Codeline Policy Or ce without likewise use HTML and XHTML as their visual-side engine. languages HTML like PHP e the image Get Mor om web pages and use HTML s version contr applications.it and submit chang h unique name e from sour CLOUD COMPUTING PLATFORMS AND ABOUT CONTINUOUS INTEGRAoject’ was once a very loosely-defi Nested tags file can be found,

tion (CI) is the pr e.com Task-Level Comm Label the build wit ies to build softwar re minimum UNDERLYING CONCEPTS

dz! dz! oblem standar ging Ajax technologies Tags can be (and fr guration HTML 5 Canvas committed to a pr USAGE SCENARIOSAutomate all activit pendencies to the ba dization, but as it has become mor Continuous Integra Label Build manual confi same deployment need for standar ned language with very little cannot overlap, so zon onment , a solution to a pr e-installed tool de equently ar lem) target envir Amazon EC2: Industry standard software and virtualization b> with every change. Automated Build Reduce pr whether you chooseds tohas write become HTML mor or XHTML, understanding e) nested inside each other a patterns (i.e. ns (i.e., ineffective .d deployment, use the is fi epository Pay onlyncies what you consumeAR or EAR) in each Amazon’s cloudthe curr computing platform is heavily based on ne. r For each tagged e important, the

x” the particularre solutions prob thatuce Web application deployment until a few years agoonment was similar ent standar e appar is not legal, but e Refcar e Minimal Depende package (e.g. W dent libraries get envir industry standarthat willd simplifysoftwar alle and your virtualization other web coding. technology Fortunately. HTML ntext) and edanti-patter to “fi ent. Regar HTML VS XHTML . T CI can be explained vi t can fi le that all tar ds will help you pr ags Binaryto Integrity most phone services:Centralize plans all depen withte alloted resources, with an and XHTML ar

Get Mor Get appear to befects. bene They arresults when compa The various resources consumed by web applicationsly, continually (e.g. Every page (HTML or XHTML shar Perform a Private velopment team individual operating system sinstances. Browser manufactur

Staged Builds Repository adverse ef ntegration tion Build periodical common.) All ar bandwidth, memory, CPU) are tallied on aom per CI server-unit to basis de web developers came up with clever workar produce unintended Private Build Perform an Integra edback fr extension. HTML ers added many competing estandar than anybody s Refcard (starting from zero) by all major cloud computing platforms. As a user of Amazon’s eEC2 essentially cloud computing plain text platform, you are tion term Continuous I y occur es certain elements in result is a lack of standar the pattern. Send automated fe ith builds based on processor s such as ors as soon as the assigned an operating systemfiles should in the not same be cr way as on all hosting The latest web standar tional use of theand test” cycle, thi Integration Build er documentation w e.com

Continuous Integra clude concept While the conven Generate develop efers to thetion “build of CI to in

expands on the no DZone, Inc. Cloud Computing 140 Preston Executive Dr. Suite 100 Cary, NC 27513 DZone communities deliver over 6 million pages each month to 888.678.0399 more than 3.3 million software developers, architects and decision 919.678.0300 makers. DZone offers something for everyone, including news, Refcardz Feedback Welcome tutorials, cheat sheets, blogs, feature articles, source code and more. [email protected]

“DZone is a developer’s dream,” says PC Magazine. $7.95 Sponsorship Opportunities Copyright © 2011 DZone, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, [email protected] Version 1.0 without prior written permission of the publisher.