赞
踩
微服务架构的系统是一个分布式的系统,按业务进行划分为独立的服务单元,解决单体系统的不足,同时也满足越来越复杂的业务需求。每个微服务仅关注于完成一件任务并很好地完成该任务。在所有情况下,每个任务代表着一个小的业务能力。
all in one的架构方式,我们把所有的功能单元放在一个应用里面。然后我们把整个应用部署到服务器上。如果负载能力不行,我们将整个应用进行水平复制,进行扩展,然后在负载均衡。
所谓微服务架构,就是打破之前all in one的架构方式,把每个功能元素独立出来。把独立出来的功能元素的动态组合,需要的功能元素才去拿来组合需要多一些时可以整合多个功能元素。所以微服务架构是对功能元素进行复制,而没有对整个应用进行复制。
高内聚,低耦合。
Spring Boot是微服务架构的基础。相比之前的Spring,它主要是省去了大量的样板式配置,取而代之的是根据条件的自动化配置,也提升了开发体验和增加一些新的特性,使开发人员把更多的精力放到业务代码上。
Spring Boot 核心功能:
步骤:
根据自己Java的版本,Maven仓库的Group和Artifact,以及创建好后的包名等填写好==》Next
我们需要添加Dependencies的话,勾选相应的,例如我们需要一个Web项目,选择Web==》勾选sprig Web==》next
测试类:TestController.java
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@RequestMapping("/test")
public String test(){
return "This is a test project.";
}
}
测试结果:
spring-boot-dependencies
核心依赖在父工程中spring-boot-starter-xxx
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
@SpringBootApplication
public class SpringbootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootApplication.class, args);
}
}
表面理解:
深层次:
注解@SpringBootApplication是一个复合 Annotation
核心的两个注解:@SpringBootConfiguration和@EnableAutoConfiguration
@SpringBootConfiguration:springboot的配置
该注解下还包含:@Configuration:表示一个普通的 JavaConfig 形式的 IoC 容器配置类
@EnableAutoConfiguration :是借助 @Import 的帮助,将所有符合自动配置条件的 bean 定义加载到 IoC 容器
@ComponentScan 的功能其实就是自动扫描并加载符合条件的组件或 bean 定义,最终将这些 bean 定义加载到容器中。
SpringbootApplication类的作用:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。