Eclipse Java Spring

1. Overview

  1. Eclipse Spring Plugin
  2. Spring In Eclipse
  3. Eclipse Java Spring Tomcat
  1. In our last tutorial, we saw Spring MVC Framework.In this Spring JDBC Tutorial, we are going to discuss Spring JDBCTemplate with Eclipse IDE. Using plain old JDBC for working with a database, it becomes complicated to use an unnecessary code for opening/closing database or handle exceptions etc.
  2. The all-new Spring Tools can be used in various coding environments, ranging from Eclipse as a full-featured integrated development environment to Visual Studio Code and Theia as lightweight code editors. Continue to use your preferred environment and add great Spring tooling to it.
  3. The Eclipse Marketplace dialog appears, type Spring Tool Suite or STS into the Find textfield and hit Enter. Eclipse will send query to its server and display results as shown below: Select the version that matches your Eclipse’s version and click Install button. Here we select Spring Tool Suite (STS) for Eclipse Juno (3.8 + 4.2).

By default, Spring Data uses Hibernate as the default JPA implementation provider.

However, Hibernate is certainly not the only JPA implementation available to us.

In this article, we'll go through steps necessary to set up EclipseLink as the implementation provider for Spring Data JPA.

The Spring IDE feature button is the furthest right feature button and the button to its left represents the OEPE plug-ins. Oracle Enterprise Pack for Eclipse with the Spring Framework. The Spring Framework has become a widely used framework for generation of enterprise Java applications because of the many advantages that it offers.

2. Maven Dependency

To use it in our Spring application, we just need to add the org.eclipse.persistence.jpa dependency in the pom.xml of our project:

By default, Spring Data comes with the Hibernate implementation.War thunder coupons.

Since we want to use EclipseLink instead as the JPA provider, we don't need it anymore.

Therefore we can remove it from our project by excluding its dependencies:

The next step is to tell the Spring Framework that we want to use EclipseLink as the JPA implementation.

3. Spring Configuration

JpaBaseConfiguration is an abstract class which defines beans for JPA in Spring Boot. To customize it, we have to implement some methods like createJpaVendorAdapter() or getVendorProperties().

Spring provides a configuration implementation for Hibernate out of the box called HibernateJpaAutoConfiguration. However, for EclipseLink, we have to create a custom configuration.

First, we need to implement the createJpaVendorAdapter() method which specifies the JPA implementation to use.

Spring provides an implementation of the AbstractJpaVendorAdapter for EclipseLink called EclipseLinkJpaVendorAdapter that we're going to use in our method:

Also, we have to define some vendor-specific properties which will be used by EclipseLink.

We can add these via the getVendorProperties() method:

The class org.eclipse.persistence.config.PersistenceUnitProperties contains properties which we can define for EclipseLink.

In this example, we've specified that we want to use weaving and re-create the database schema when the application runs.

And that's it! This is the whole implementation necessary to change from the default Hibernate JPA provider to EclipseLink.

Note that Spring Data uses the JPA API and not any vendor specific methods. So, in theory, there should be no problem when switching from one vendor to another.

4. Conclusion

In this quick tutorial, we covered how to change the default JPA implementation provider used by Spring Data.

We saw how quick and simple it is to change from Hibernate which is the default to EclipseLink.

As always, the full implementation of the examples is available over on Github.

Get started with Spring Data JPA through the reference Learn Spring Data JPA course:>> CHECK OUT THE COURSE
Written by Nam Ha Minh
Last Updated on 20 February 2020 Print Email
Thanks to new Maven archetypes for Spring and Maven integration plug-in for Eclipse, creating skeleton stuffs for a Spring MVC project has never been easier. Forget the days we have to manually add JARs, create XML files, find and put appropriate Maven dependencies, etc. This tutorial shows you how quickly to create a basic Spring MVC project and get it up and running, using the Maven archetype called spring-mvc-archetype from group Id co.ntier.Firstly, make sure you have the Maven Integration for WTP (m2e-wtp) plug-in installed in your Eclipse IDE:
    • If you are using Eclipse Juno (4.2) or older, follow the tutorial Installing Maven plug-in for existing Eclipse IDE.
    • If you have Eclipse Kepler (4.3) or newer, Maven is already integrated in the IDE so this step can be skipped.
Now let’s go through few steps to create a new Spring MVC project using Eclipse IDE. Depending on your installation, the archetype spring-mvc-archetype is installed or not. If not, we’ll see how to download and install it the following steps.In Eclipse IDE, click menu File > New > Maven Project (or File > New > Other… > Maven Project). The New Maven ProjectEclipse Java Spring dialog appears:Make sure you don’t check the option Create a simple project (skip archetype selection), and click Next. In the next screen, Select an Archetype, you may see a lot of archetypes in the list, so type spring-mvc into the Filter textfield to filter out the list, as shown below:If you don’t see the spring-mvc-archetype, click the Add Archetype… button. In the EclipseAdd Archetype dialog, type the following information:
    • Archetype Group Id: co.ntier
    • Archetype Artifact Id: spring-mvc-archetype
    • Archetype Version: 1.0.2
    • Repository URL: leave empty

Note that you must leave the Repository URL field empty.Click OK and wait for a moment while Eclipse is downloading the archetype. Finally you would see the spring-mvc-archetype in the list. Select it and click Next. In the next screen, Specify Archetype parameters, enter the following information (for example):
    • Group Id: MySpringMvc
    • Artifact Id: MySpringMvc
    • Version: leave this as default, 0.0.1-SNAPSHOT.
    • Package: net.codejava.spring
Click Finish and wait a while when Eclipse is generating the project. And finally we have a project structure looks like below:As we can see, all the necessary stuffs of a Spring MVC project are generated automatically. Let’s look at the main things:Spring in eclipse
    • this configuration class uses annotations in replacement of XML since annotations are preferred. It configures a default view resolver and a resource handler. We don’t see Spring application context XML file any more.
    • this controller is generated to handler the default URL mapping (/). Look at its code, it redirects the user to the “home” view.
    • home.jsp: This JSP page will be displayed when the user access this application using the default URL (/). This is simply a hello world page.
    • web.xml: bootstraps the Spring context loader listener and Spring dispatcher servlet.
    • pom.xml: All dependencies for a Spring MVC application are listed here.
Now, without writing any code so far, we can get this basic Spring MVC application up and running. Drag the project into a server, e.g. Tomcat v7.0, in Servers view, and then start the server. Then open the SpringInternal Web Browser view and type the following URL:


Hit Enter, we should see the “Hello World!” page as seen below:

Important Notes:

The spring-mvc-archetype from co.ntier was created long time ago so it comes with old versions of Java (1.6), Spring framework (3.1.0) with cglib 2.2.2, Servlet 2.4, etc. So it's strongly recommended to update the pom.xml file for newer versions, for example:If you use Spring 5, you need to remove the cglib dependency as it is no longer needed, and update the MvcConfiguration class to implement the

Eclipse Spring Plugin

WebMvcConfigurer interface like this:Watch this video to see the steps visually:So to conclude, using the Maven archetype spring-mvc-archetype definitely saves us a lot of time in configuring the fundamental stuffs, avoiding common mistakes and following best practices. But basically, you still need to understand what the generated stuffs do, e.g. annotation types, bootstrap code in

Spring In Eclipse

web.xml and dependencies in pom.xml. Although you may take more than one minute to read this till now, following the above steps take just a minute :). Enjoy coding!

Related Spring Tutorials:


Eclipse Java Spring Tomcat

About the Author:

Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.