"Java Development Guide" Spring development in MyEclipse (1)

MyEclipse v2023.1.2 offline version download (Q technical communication: 742336981)

1. What is Spring?

Introducing Spring into MyEclipse is more difficult than most frameworks because it is not a single-purpose technology. Spring is considered a huge framework with best practices in almost every area of ​​Java software development, from pure Java-old-object (POJO) development, to web application development, to enterprise application development, to persistence layer management and Aspect-oriented programming (AOP). Spring supports all of this and does it using some of the best-designed and rigorously-tested code in the Java industry.

Due to its size, we need to focus this tutorial on the simplest Spring application, which is POJO development using dependency injection. It should be noted that dependency injection is a mechanism through which Spring handles the creation and initialization of appropriate types of child objects for the parent object when the parent object needs to refer to the child object. One example where this is useful in an enterprise Java programming environment is that your web application can immediately access the data access layer to read or write objects from the database. This is a classic example of allowing Spring to inject references to the data access layer into POJOs in a web application in order to load or save objects.

To demystify this process right off the bat, Spring handles this in Spring 1.2 by mapping object reference relationships in XML configuration files, while in Spring 2.0 this is handled through Java 5 annotations.

Using this declarative approach, Spring developers can actually soft-wire parts of their application together using these annotations or XML configuration files so that when the application is running, Spring creates and instantiates all object relationships "on demand" . The advantage of having everything soft-wired is that parts of the application can be quickly and easily swapped to other implementations (such as test implementations) by simply changing annotations or XML configuration information and re-running the application. In some cases there is even no need to recompile the application, which is a huge boon for developers working on large applications that require continuous testing or delivering large applications in iterations. Spring provides a very natural way to think about these problems, and it encourages you to maintain applications in a modular architecture that supports this functionality.

2. Spring project configuration

To add Spring facets to any Java project, right-click on the project in Explorer and select Configure Facets>Install Spring facets .

Spring development in MyEclipse

Add Spring facets

You can also add multiple facets to a project at the same time by opening the project's Project Facets property.

Spring development in MyEclipse

Add facet via project properties

MyEclipse supports Spring 1.2, Spring 2, Spring 2.5, Spring 3.0, Spring 3.1 and Spring 4.1. The corresponding libraries are classified and bundled with MyEclipse. Spring Java Configuration and Spring Web Flow support are also included.

Spring development in MyEclipse

Select Spring library

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

Spring development in MyEclipse

Spring Beans project property page

3. Wizard

The Spring Bean Definition File wizard allows you to easily create a configuration file with the required namespace. By default, the applicationContext.xml definition file is generated when you add the Spring facet to your project. Alternatively, if you created your own bean definition file, you can specify an existing bean definition file when adding the facet.

Spring development in MyEclipse

Create a Spring bean definition file

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

Spring development in MyEclipse

Spring development in MyEclipse

Spring Bean Menu and Bean Definition Editor

The Spring bean wizard validates user input and provides content assistance (Ctrl + Space) where possible.

Spring development in MyEclipse

Spring bean details

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

Spring development in MyEclipse

Create Spring data source

The Hibernate SessionFactory wizard is a dedicated wizard for Spring's LocalSessionFactoryBean.

Spring development in MyEclipse

Spring Hibernate session factory details

The Property Wizard supports a large number of Spring property types and is accessed by right-clicking a bean in the Spring Explorer view and selecting Add Properties. Alternatively, in the bean configuration file, right-click the bean to insert elements such as property elements.

Spring development in MyEclipse

Spring development in MyEclipse

Add node properties

Guess you like

Origin blog.csdn.net/AABBbaby/article/details/132753477