Springcloud Practice (i) basic knowledge: micro-service, Springcloud, Springboot__springcloud

Source: Internet
Author: User

Before studying the Springcloud, first comb the basics, the goal of this chapter is to understand the following basics:

The micro-service Springcloud Springboot finally ends this chapter by building a simple springboot HelloWorld.

First, what is the micro-service

Traditional enterprise structure inside, generally divides into the database, the service side processing, the front-end display. The service side is generally the monomer module or the monomer process, as the web end of the business more and more complex, to the service end of the request is more and more, service interface more and more. At first people used the service bus to solve the problem of service discovery and service governance. With the rise of the Internet, the interface of the call performance and stability issues more and more prominent, so go to the center of Service Management after a highly valued issue, in this context, more and more companies have adopted micro-services to carry out the design of the server , from the previous Taobao Dubbo, to later Springcloud, micro-service has become the most popular back-end service design of a technology selection.

Ii. introduction of Springcloud

After the emergence of the concept of micro-services, there are many related frameworks in the technical staff circulated, if the previous mentioned Dubbo, and other Elastic-job a series of technical framework, but are based on the micro-service of a point of the problem to solve, the emergence of Springcloud, Provides a comprehensive solution framework for the implementation of micro-service architecture for technicians.

Springcloud contains more than one subproject:

Spring Cloud Config: Configuration management tools

Spring Cloud Netflix: Core components, containing Eureka: Service Governance Components (service registry, service registration and discovery mechanism)

Hystrix: Fault-tolerant management component to implement circuit breaker mode

Ribbon: Client load Balancing Service invocation component

Spring Cloud Bus: events, message buses

Spring Cloud Cluster: Cluster

And so on, there are a lot of not listed.

Introduction to Spring Boot

Springcloud's engineering build is based on the spring boot implementation, so it is necessary to understand spring boot first, by creating a simple Web project to learn about Springboot: suggest using idea as a development tool

First, create a springboot project by building a model:


Click Next:


After you fill in the metadata related information for model, continue to next


After selecting Web,next here, fill in the name of the module:


After clicking Finish, the following engineering structure appears:


The above diagram shows the engineering structure in which Pom.xml is a configuration file for the MAVEN project, which is dependent on engineering, and we use the Spring INITIALZR Wizard, so we automatically populate the initial dependencies in Pom.xml; second default SRC main The directory has a Java, a resource, in Java, put the code in the resources of the project, such as configuration files, Application.yml is also a configuration file, is later joined, this is the Springboot feature profile, Hellocontroler in the code area is also a later code, which will show that the system defaults to an application entry class, Springbootapplication. The final test area is the area where the unit test code is placed.

After the project is established, we are ready to develop a small demo,helloword.

First, take a look at pom.xml.

<?xml version= "1.0" encoding= "UTF-8"?> <project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http ://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" http://maven.apache.org/POM/4.0.0 http:// Maven.apache.org/xsd/maven-4.0.0.xsd "> <modelVersion>4.0.0</modelVersion> <groupId> Com.study</groupid> <artifactId>springboot</artifactId> <version>0.0.1-snapshot</ version> <packaging>jar</packaging> <name>springboot</name> <description>demo Project for Spring boot</description> <parent> <groupId>org.springframework.boot</groupId> & Lt;artifactid>spring-boot-starter-parent</artifactid> <version>2.0.1.RELEASE</version> < Relativepath/> <!--lookup parent from repository--> </parent> <properties> <project.build.s Ourceencoding>utf-8</project.build.sourceencoding> <project.reporting.outputencOding>utf-8</project.reporting.outputencoding> <java.version>1.8</java.version> </ properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> & lt;artifactid>spring-boot-starter-web</artifactid> </dependency> <dependency> <groupid&gt ;org.springframework.boot</groupid> <artifactId>spring-boot-starter-test</artifactId> < scope>test</scope> </dependency> </dependencies> <build> <plugins> &LT;PLUGIN&G
				T <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-maven-plugin</
 artifactid> </plugin> </plugins> </build> </project>

If you later have other dependencies in your project, you can add yourself, the above is created when the project was created, remember the previous we selected the Web option, here there are sping-boot-starter-web.

Second, we write a controler, the default call is handled by this controler

Package Com.study.springboot.controler;

Import org.springframework.web.bind.annotation.RequestMapping;
Import Org.springframework.web.bind.annotation.RestController;

@RestController public
class Hellocontroller {

    @RequestMapping ("/sayhello") public
    String Hello () {
        Return "Hello world!";
    }

In Springboot, the annotation method is used to develop and improve the development efficiency, which is when the Http://localhost:port/sayhello call returns Hello World. Next, create the application configuration file, in the resource directory, we create a file application.yml

Server:
#配置服务器启动端口
  port:8028
#配置访问的上下文路径, which is the context path required after localhost:8028
  Context-path:/sayhello

Springboot uses the progressive style of the configuration file format yml, a bit like python, of course, you can also use the default application.properties

Above equals server.port=8028.

Finally, let's take a look at the demo entrance:

Package com.study.springboot;

Import org.springframework.boot.SpringApplication;
Import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication public
class Springbootapplication {public

	static void Main (string[] args) {
		Springapplication.run (Springbootapplication.class, args);
	}

This class does not do any processing, as it was created, and we run it directly:


After running, we enter the URL Http://localhost:8028/sayhello in the browser, the browser will return the following information:


A simple Springboot demo is done.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.