Spring Development in MyEclipse
1. What is Spring?
Introducing Spring is harder than most frameworks because it’s not a single-purpose technology. Spring can be thought of as a huge framework of best practices for almost every area of Java software development. Everything from Plain-Old-Java-Object (POJO) development, to web application development, to enterprise application development, to persistence layer management and aspect oriented programming (AOP). Spring supports it all and does so with some of the most well designed and heavily tested code in the Java industry.
Because of its size, we need to focus this tutorial on the simplest application of Spring which is POJO development utilizing dependency injection. To clarify, dependency injection is a mechanism by which Spring handles creation and initialization of the proper type of child object for a parent object at the moment the parent object needs the reference to the child. An example of where this is useful in the context of enterprise Java programming is for your web application to instantly have access to your data-access layer in order to read or write an object from the database. This is a classic example of allowing Spring to inject the reference to the data-access layer into a POJO in the web application in order to load or save an object.
To immediately demystify this process, Spring handles this by mapping out object reference relationships in XML configuration files in Spring 1.2, and with Spring 2.0, this is handled with Java 5 annotations.
Using this declarative method, Spring developers can actually soft-wire their application portions together using these annotations or XML configuration files such that when the application runs, Spring creates and instantiates all the object relationships “on demand”. The advantage to having everything soft-wired is that portions of an application can quickly and easily be swapped out for alternative implementations (e.g. testing implementations) by simply changing around the annotations or XML configuration information and rerunning the application. There isn’t even a need to recompile the application in some cases. This can be a huge boon to developers working on large applications that require constant testing or when delivering a larger application in iterations. Spring provides a very natural way of thinking about these problems, encouraging you to maintain your application in a modular architecture that supports this plugging and unplugging capability.
2. Spring Project Configuration
You can add the Spring facet to any Java project by selecting the project in the Explorer and selecting MyEclipse>Project Facets>Install Spring Facet.

You can also add multiple facets to a project simultaneously by opening the Project Facets property of the project.

MyEclipse supports Spring 1.2, Spring 2, Spring 2.5, Spring 3.0, Spring 3.1, and Spring 4.1. Corresponding libraries are categorized and bundled with MyEclipse. Spring Java Configuration and Spring Web Flow support is also included.

Selecting Spring libraries
Use the Spring project properties page to add and group related bean configuration files. Open project properties by right-clicking the project, and selecting Properties. Expand MyEclipse>Project Facets>Spring, and select Beans.

3. Wizards
The Spring Bean Definition File wizard allows you to easily create configuration files with required namespaces. An applicationContext.xml definition file is generated for you by default when you add the Spring facet to a project. Or, if you create your own, you can specify an existing bean definition file when adding the facet.

MyEclipse includes a set of advanced bean wizards that you can access by either right-clicking the Outline view or the applicationContext.xml source tab. Using the bean definition editor, you can access the New Bean wizard as well as edit bean details for each namespace selected on the Namespaces tab.


Spring bean wizards validate user input and provide content assist (CTRL+Space) where possible.

The Data Source wizard allows you to easily create a Spring data source bean corresponding to an existing MyEclipse driver. Add a new data source by right-clicking anywhere in the applicationContext.xml file in the source view editor, and selecting Spring>New DataSource. You can also access this menu by right-clicking anywhere in the Outline view.

The Hibernate SessionFactory wizard is a specialized wizard for Spring’s LocalSessionFactoryBean.

The Property wizard supports a large number of Spring property types. Access the Property wizard by right-clicking a bean in the Spring Explorer view, and selecting Add Properties. Or, in the bean configuration file, right-click a bean to insert elements such as the property element.
Adding node properties
4. Managing Multiple Beans & Projects
Use the Outline view to manage Spring beans. You can also change the outline to a Spring-style outline using the Outline view menu. Or, use the bean configuration file editor to manage Spring beans.
Spring outline
The Spring Explorer is a filtered tree view that displays all Spring projects in your workspace along with any beans, config sets and Spring Web Flow elements it may contain. This view is namespace aware and can be highly filtered and customized.



Spring Explorer content
The Spring Explorer view also specially annotates beans defined via Spring Java Configuration.

All Spring projects contain a Spring Elements child when seen in the Project Explorer view using the Spring perspective. This item can be expanded to show beans, config sets and web flow definitions just like the Spring Explorer view described above. The ability to see a list of all beans that reference a particular Java class is a key feature.

Like the Spring Explorer, the Spring elements shown in this view can be filtered and customized. You can also use a special Spring working set to cut down the clutter in the Project Explorer.

The Graph viewer presents a graphical view of the relationships between various beans in a given configuration file. Access the graphical view by clicking the Beans Graph in the applicationContext.xml file editor.

Use the Open Bean wizard (ALT+Shift+B) or double-click a bean in the graph to quickly navigate to any bean.

Perform various bean searches and Pointcut Matches in your workspace from the Search menu.
Bean pointcut matches search
5. Spring Config Editor
The Spring Config editor is the default editor for Spring bean configuration files.

The Source view provides content assist for class, bean Id and property attributes in addition to standard XML support.



The Spring Configuration editor is also namespace aware and provides intelligent content assist and validation for defined elements.


Use the visual editor tabs to manage bean entities. Edit namespaces and bean details for each namespace selected in the configuration. Right-click elements to add child elements, and configure elements using the Element Details section.

To learn more details about the Spring Bean Config editor, scroll to the bottom of the Element Details section to access additional documentation.

Renaming a Java class automatically makes changes in bean definitions referencing that class. Java classes can also be renamed directly from the bean configuration file.

Bean Ids and properties can also be renamed. Renaming a bean property makes changes in the corresponding Java class. Rename elements in the following ways:
- On the Beans tab of applicationContext.xml, select the element and edit the element details.
- In the Source view of applicationContext.xml, right-click the element, and select Refactor>Rename Bean Element from the menu.
- In the Source view of applicationContext.xml, place the cursor in the element, and press ALT+SHIFT+R.


In addition to standard XML validation, the editor also performs Spring-specific validation. These validators can be controlled both at the project and workspace level. Validation errors are noted in the config file Source view, and detailed in the Problems view.


6. AOP Support
The Beans Cross References view shows you all beans being advised as well as those that advise other beans.

The Spring Configuration editor as well as the Java editor displays special markers for methods and classes affected by your project’s AOP configuration.


The Spring AOP Event Trace view gives you an idea of what is going on under the hood as Spring IDE’s internal AOP model is being built.

AOP support requires the AOP Reference Model Builder, which can be enabled/disabled at both the project and global level. If you do not use AOP in your projects, you can turn it off globally.

7. Web Flow Support
MyEclipse also adds Spring Web Flow support and includes multiple versions of Spring Web Flow libraries. Include Spring Web Flow when you install the Spring facet to your project. Or, you can include it at a later time in the project’s Spring properties.

Web flow container

Defining a Web Flow definition file
Use the visual editor to easily create states, actions, and transitions usng the right-click menu. Use the Element Details section to add element information. Use the Flow-graph tab to visually design your web flow.


The Source view provides web flow-specific content assist support.

Validation for web flow definition files is customizable.

8. Resources
Reference
- Introduction to Spring – Knight MyEclipse Spring Project
- Spring 1.2 Reference Manual
- Spring 2.0 Reference Manual
- Spring 3.0 Reference Manual
- Spring Forums
- Spring Wiki
Basics
Web Development
- Spring MVC Example Application Development Guide
- Simplifying Web Development
- Spring Web Flow Reference Manual