
Spring Cloud
Spring framework needs no introduction for Java developers. Spring offers dependency injection as its core feature and provides many supporting modules such as Web MVC, persistence, AOP, and a huge number of integrations with popular projects.
Spring also integrates nicely with most IDEs and offers Spring Tool Suite (STS), which is an eclipse-based IDE for spring application development. In case of NetBeans, there's a NB Spring plugin, which enables support for spring-based development.
Spring Boot makes it very easy to get started with Spring-based projects. It sets up default configurations, and thus requires minimal to zero setup. It provides starter maven dependencies, which helps make the application production ready in a short amount of time. Similar to the WildFly Swarms generator approach, to get started with Spring Boot, you could use the link: https://start.spring.io/.
If you prefer to use an IDE, then you could use STS or any other IDE with Spring support to generate the project.
Here's how the New project wizard looks when using NetBeans, File | New Project | Maven | Spring Boot Initialize Project (this is provided by the NB Spring plugin):

Having filled the fields as needed, you can select the Web dependency on the next step of the wizard. Once you finish the wizard, a Maven project is created with the following structure:
├── pom.xml
└── src
└── main
└── java
│ └── org
│ └── jee8ng
│ └── issuemanager
│ └── users
│ └── MicroUsersApplication.java
└── resources
├── application.properties
├── static
└── templates
Here's the relevant snippet of MicroUsersApplication.java:
@SpringBootApplication
public class MicroUsersApplication {
public static void main(String[] args) {
SpringApplication.run(MicroUsersApplication.class, args);
}
}
This allows the application to be started using its main method. The next step would be to create the REST endpoint, the Spring way. Create a class called HelloRestController.java with the following code:
@RestController
@RequestMapping("/hello")
public class HelloRestController {
@RequestMapping("")
public String get() {
return "hello microservice";
}
}
It's a fairly simple code, which will publish a REST endpoint at the /hello path. When invoked, it should return the text hello microservice.
If you open the pom.xml, it will have these essential snippets:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
The spring-boot-starter-web dependency is used to add support for full stack web development using the Tomcat web server and the Spring MVC framework.
Similar to wildfly-swarm-plugin, Spring provides a spring-boot-maven-plugin for Spring Boot projects. This enables the creation of an Uber JAR that can then be executed as a standalone application.
Open a terminal, and from the project root directory, run the following command, which will build and start the application:
mvn spring-boot:run
Once the application starts up, you can access the URL via a browser, or use the following curl command to fetch the response:
curl http://localhost:8080/hello
Response: hello microservice
Stopping the application is as simple as pressing Ctrl + C on the running terminal window.
After running mvn clean install to build the project, if you look within the target directory of the project, you can see the Uber JAR, which is approximately 14 MB in size:

Since the Uber JAR has the Spring runtime that contains an embedded Tomcat within it, we can execute it like any other standalone Java application:
java -jar issue-manager-users-0.0.1-SNAPSHOT.jar
This will start up the Tomcat instance and publish the REST endpoint. The Java Heap Memory (JHM) for this application can be as low as 18-25 MB (similar to WildFly Swarm).