Tagged: Ros images micro-service NIS res modular Fast com
Spring Cloud-based microservices build learning-2 spring boot Why use spring boot instead of spring
Spring boot, with its automated configuration, rapid development, and ease of deployment, is ideal for use as a development framework for specific microservices in a microservices architecture. Not only does it help us quickly build microservices, but it also makes it easy to integrate the spring cloud into the system, and if we use traditional spring constructs, we need to do more of the dependency management in order to make them run well.
The purpose of spring boot is not to rewrite spring or replace spring, but rather to simplify the original boilerplate configuration of spring by designing a large number of automated configurations, allowing developers to quickly build applications.
Spring boot, in addition to solving the configuration problem, also through a series of starters Poms definition, let us in the integration of various functions, Instead of maintaining those intricate dependencies in Maven's Pom.xml file, it's easier to rely on administrative work by referencing them in a modular starter module definition.
Applications built with spring boot do not need to install Tomcat, package the app into a war package, publish to Tomcat Central, but simply package the spring boot app as a jar and run it directly with the Java-jar command to launch a standardized web application.
Simple implementation of the spring Boot-based RESTful API system requirements:
- Java7 and above
- Spring Framework4.2.7 and above
- Version Maven3.2 and above
Note: MAVEN's environment variables and integration with Eclipse are simple and are no longer explained here.
Building a MAVEN Project
1. Use the official spring initializer tool to generate the base project, fill in the group and aftifact information and click the arrow button to download the project compression package. Website: http://start.spring.io/
2. Open Eclipse, right-left margin, select Import, select options, click Next
3. Select the base project you just downloaded and click Finish
4. The project directory structure is as follows:
Src/main/java folder is generally used to put Java source code
Src/main/resources folders are typically used to put project configuration files
Src/test/java folders are typically used to write test programs
5. Add the Spring-boot-starter-web dependency in the Pom.xml file:
< Dependency > < groupId >org.springframework.boot</groupId> < Artifactid>spring-boot-starter-web</artifactid> </ Dependency >
With the Ctril+s shortcut key saved, MAVEN will automatically download the relevant jar package.
6. Implementing RESTful APIs
1. Create a new package and name it Com.microservice.hellocontroller
2. Create a new Hellocontroller class with the following contents:
Package Com.microservice.hellocontroller; Import org.springframework.web.bind.annotation.RequestMapping; Import Org.springframework.web.bind.annotation.RestController; @RestController Public class Hellocontroller { @RequestMapping ("/hello") public String index () { return "Hello World"; }}
3. Make the following changes at the application entrance:
@ComponentScan ("Com.microservice.hellocontroller")// Here is a string to fill in the package name of your controller class @ Springbootapplicationpublicclass helloapplication { public staticvoid main (string[] args) { springapplication.run (helloapplication. class , args);} }
4. Launch the app and access the Http://localhost:8080/hello via the browser
A RESTful foundation project based on spring boot ends here.
Reference documents:
Spring Cloud Micro-service combat
Reprint Annotated Source: http://www.cnblogs.com/xiemubg/p/7280201.html
Spring Cloud-based microservices build learning-2 spring Boot