Running Spring Tool Suite 4 in Docker

Reading Time: 6 minutes

If your serious about building your Java applications with Spring Boot then your definitely going to love developing with Spring Tool Suite 4. In this post, I go over how to run the STS4 IDE from a Docker Container as well as introduce you to its new and amazing features that you won’t be able to live without.

Running Spring Tool Suite 4 in Docker

By running Spring Tool Suite 4 in a Docker Container, you’ll benefit by easily reproducing the environment I’ll be introducing. You won’t have to spend time configuring or installing any additional plugins.

All you have to do is git clone from MVP Java’s GitHub account here  and you’ll  end up with the following …

Spring Tool Suite 4 in Docker git clone

We just need to turn on the execution bit for run.sh via “chmod 755 run.sh” and then run it “./run.sh“. Since this will be your first time, the Docker Image will be downloaded from MVP Java’s DockerHub account here and then the Docker Container will be created and run.

It should take a few minutes to download the docker image, it’s about 1.7 G so it’s probably a good time for a coffee break!

If you would like to see the YouTube version of this Blog Post then check it out here …

Once the download is complete, the Spring Tool Suite 4 Splash screen will appear and then prompt you to enter your work space directory.

Eventually, the Eclipse based Spring Tool Suite 4 IDE will be starring at you in the face (as show below). You can now git clone the Spring Boot application itself from my MVP Java GitHub account here.

Spring Tool Suite 4 Eclipse IDE

Business as Usual

The nice thing about the Spring Tool Suite download is that it includes both the Eclipse IDE (in this case) and the STS4 plugin in an all in one convenient download. You don’t have to install the STS plugin after the fact therefore no extra configuration is needed. You can start interacting with the built in Spring Initializr interface right away (just like you did in STS3) to create your Spring Boot application. We also still have the integrated Spring Guides so it’s business as usual for those features. Don’t Fix What’s not Broken, right 😉

Spring Tool Suite 4 – New Features

Rebuilt With Purpose

Re-written from ground up to be more responsive and lightweight. You’ll notice while using STS4 that it is non-blocking and very responsive. Now Spring Boot 2 capable, you’ll find the IDE has been tailored to take advantage of everything that Spring Boot can offer.

Newly designed architecture to support various IDE environments (IDE agnostic) such as Eclipse, Visual Studio Code and Atom. It’s not available for IntelliJ mainly because IntelliJ doesn’t support the language support tooling needed by STS however IntelliJ already has superb Spring Tooling as it is.

Spring Based Navigation – Spring Aware

Spring aware like never before. A new Spring context aware navigation feature is now available with keyboard shortcut CTRL+ 6 that allows you to move through your Spring application much like ‘Open Java Type’ in eclipse.

You can see in the image below all the Spring Beans that are matching the “init” search criteria.  This is not just a simple search and find operation, STS4 will retrieve and pack together an impressive amount of Spring related context information on each line returned from the search.

The first line returned not only tells you the Spring bean id found “dbInit” but it also informs you that it is associated with the “prod” Spring @Profile. We’re also informed of its Type “IApplicationInitiator” and where the resource is located in order to navigate to it. This is a new way to interface and navigate throughout your Spring application and becomes very useful as well when looking for Restful URLs.

Welcome To The Second Dimension

My favourite feature is the dynamic Spring configuration information overlaid onto your source code at run time. I found myself looking more at my source code in order to confirm which Spring bean type was injected, which profile was active and how my Spring Beans were built. Have you ever asked yourself the question …

Which Implementation got injected into this Spring bean?

Who hasn’t, right! Well now, the answer is provided directly in your source code. All this dynamic Spring info is all available at run time via the “Live Boot Hint Decorator” and the “CodeLens” features. These feautures can be enabled by navigating Eclipse’s menu’s Window->Preferences and then search for “Spring Boot Language Server

Spring Tool Suite 4 Code Decorators

** Ensure you have the Spring Boot Actuator startup dependency in your pom.xml in order to benefit from these features (they are in the GitHub Project).

Live Boot Hint Decorator

When your application is running, your source code annotations and Spring Beans will get highlighted in green (as shown below). These new gems will now reveal information on how Spring has configured your Spring Bean at run time. This information displays itself in a pop-up window when you hover over the highlighted/decorated code with the mouse.

You can see below that the “Application” Class is a Spring Bean because its Class name is highlighted.  Without this new extra dimension of information you wouldn’t know it was a Spring bean because there is no @Component or @Configuration/@Bean annotation present. One would have to navigate the code base to confirm if it was or wasn’t.

STS4 Live Boot Hint Decorator

A wealth of new information is now available in the decorator pop-up window. We can now tell that the  “Application” Class is being dependency injected into the “–> Main” Class/Bean  and that the Class/Bean”<– InitiatorJavaConfig”  is injecting a Spring bean with id “fileInit” into this Application Class/Bean. This is actually answering our question of which implementation is being injected into the constructor!

The constructor takes the Interface type “IApplicationInitiator” which in this project has two implementations (as @Bean “fileInit” and  “dbInit“). We now know that the implementation being injected by Spring is bean “fileInit“.

I find myself looking more at my source code for the answers and less at logs, created artefacts or monitoring application behaviours.

We have access to the Types and even where the resources are defined. This makes navigating through your Spring Boot application very intuitive. Don’t be surprised if you find yourself using the “Project Explorer View” much less in favour of the code decorator navigation features.

Hightlights Codelens

If ever you find it annoying having the decorator popping up every time the mouse hovers over anything highlighted, you can opt for the Codelens feature instead. I actually like enabling both features together as I find them both useful.

The Highlights Codelens STS4 feature provides less information and provides its information as text annotated above where the highlighted would of taken place. I’ve enabled both below in the @Configuration Class where you can see that CodeLens is informing us that the @Bean “fileInit” is being injected into the “–> Application” bean between line 18 and 19.  That confirms what we saw earlier. It’s also telling us that the @Bean “application” is being injected into the “–> Main” bean between line 24 and 25.

Another interesting piece of information is that we can tell which @Profile is active just by seeing that both the @Bean and @Profile annotations on line 19 and 20 are highlighted. This is however feedback from the Live Boot Hint Decorator.

STS4 Live Boot Hint Decorator and Code Lens

 Summary

Spring Tool Suite 4 offers some amazing new features such as Spring aware context searching, code decorators ,excellent Spring API integration and smart code completion. If your looking to develop modern style Spring applications using Spring Boot and Java annotations, then this will be the perfect fit for you.

Want to Get Docker Certified (DCA)? Then read my blog on How I Got Docker Certified