Powered by Blogger.

Spring Boot for Microservices

1 comment :
Spring Boot:
Spring Boot is an opinionated Java framework for building microservices based on the Spring dependency injection framework. Spring Boot allows developers to create microservices through reduced boilerplate, configuration, and developer friction. This is a similar approach to the two other frameworks we’ll look at. 
Spring Boot does this by: 
  • Favoring automatic, conventional configuration by default.
  • Curating sets of popular starter dependencies for easier consumption.
  • Simplifying application packaging.  
  • Baking in application insight (e.g., metrics and environment info)

Dependencies:
Spring was used in large enterprise applications that typically leveraged lots of different technology to do the heavy lifting: JDBC databases, message queues, file systems, application-level caching, etc. A developer would have to stop what she’s doing, switch cognitive contexts, figure out what dependencies belonged to which piece of functionality (“Oh, I need the JPA dependencies!”) and spend lots of time sorting out versioning mismatches or issues that would arise when trying to use these various pieces together. Spring Boot offers a large collection of curated sets of libraries for adding these pieces of functionality.  
These starter modules allow you to add things like: 
  • JPA persistence.
  • NoSQL databases like MongoDB, OracleDB, and Couchbase.
  • Redis caching.  
  • Tomcat/Jetty/Undertow servlet engine
  • JTA transactions.  

Adding a submodule to your application brings in the curated set of transitive dependencies and versions that are known to work together saving developers from having to sort out dependencies themselves.
The spring-tool-suite-4-4.2.0 can be installed a few different ways, including through package managers and by downloading Tools it straight from the website. Check for instructions on installing the STS most appropriate for your development environment. Once you’ve installed the STS tools, you should be able to check the version of Spring you have:
$ spring --version sts-4.2.0.RELEASE

Hello Example: Now that we have a Spring Boot application that can run, let’s add some simple functionality. We want to expose an HTTP/REST endpoint at /api/indexGet that will return “Hello Spring Boot from X” where X is the IP address where the service is running. To do this, navigate to src/main/java/com/a134mk/springboots. This location should have been created for you if you followed the preceding steps; remember, the groupId we passed to the spring init program did not apply groupId to the Java package hierarchy, and we’ve left it as it is which should be “com.a134mk”. Then create a new Java class called HolaRestController, as shown in code block. We’ll add a method named Hello() that returns a string along with the IP address of where the service is running. we’re going to make use of the following annotations in Example :
Let’s see what it takes to enable the actuator. Open up the pom.xml file for your Hello Spring Boot for microservice and add the following Maven dependency within
 the "<dependencies>...</dependencies>"  section:



@RestController 
 Tell Spring this is an HTTP controller capable of exposing HTTP endpoints (GET, PUT, POST, etc.). 
@RequestMapping 
 Map specific parts of the HTTP URI path to classes, methods, and parameters in the Java code. Note, import statements are omitted.


Go to Run->
OUTPUT:

Check Video for Similar Spring Boot Configuration:

Go Link...

1 comment :

  1. 1. In pom.xml add tag jar.
    2. you can build the maven project using command mvn package or maven install. It will create the .jar file inside target folder.
    3. run command from location where .jar is present - java -jar jarName.jar
    Now you can access your system

    ReplyDelete

Please Write a Message for Programming or something Related issues.