1. Spring Boot怎么用
(1).Maven pom.xml中配置
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
</parent>
(2).创建Application.java
/*
@SpringBootApplication继承了@EnableAutoConfiguration、@ComponentScan
@EnableAutoConfiguration主要是用来开启自动配置是扫描jar包,配置了META-INF/spring.factories
里面的类和针对当前包以及子包下的自定义组件
@ComponentScan扫描当前类所在包(包括子包)类的注解
*/
@SpringBootApplication
public class SpringBootMain {
public static void main(String[] args) throws Exception {
SpringApplication.run(SpringBootMain.class, args);
}
}
(3).创建Application.yml
server:
port: 8080
address: localhost
(4).启动main方法
2. Spring Boot如何集成MyBatis
(1).添加MyBatis starter Maven依赖
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.2.0</version>
</dependency>
(2).在MyBatis接口中添加注解@Mapper
(3).Application.yml中配置数据源信息
spring:
datasource:
url: jdbc:mysql://localhost:3306/spring-boot?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
platform: mysql
3. 微服务架构
支撑互联网变化多样的产品需求,使用服务和数据得到可重用性
特点:
微服务遵循单一原则,服务抽取的粒度要细
微服务之间采用RESTful等轻量级协议传输
优点:
1. 服务拆分粒度更细,有利于资源重复利用,提高开发效率
2. 可以更加精准的制定每个服务的优化方案,提高系统可维护性
3. 微服务架构采用去中心化思想,服务之间采用RESTful等轻量协议通信,相比ESB更轻量
4. 适用于互联网时代,产品迭代周期更短
缺点:
1.微服务过多,服务治理成本高,不利于系统维护
2.分布式系统开发的技术成本高(容错、分布式事务等),对团体挑战大
4. 微服务技术栈
负载均衡,网关路由:高可用、集群部署,校验、请求转发、服务集成
服务治理:服务注册、发现,Dubbo(阿里巴巴)、Dubbox(当当)、Eureka(Netflix)等
容错:避免雪崩
监控跟踪:监控资源利用、服务响应、容器资源利用情况,Hydra(京东)、Zipkin(Twitter)、Sleuth(Spring Cloud)等
消息总线:消息队列、异步通信
配置管理:统一配置管理,Disconf(百度)、QConf(360)、Diamood(淘宝)
5. Spring Cloud
Spring Cloud 为开发人员构建微服务架构提供了完整的解决方案,Spring Cloud是若干个框架的集合,它包括spring-cloud-config、spring-cloud-bus等近20个子项目,它提供了服务治理、服务网关、智能路由、负载均衡、断路器、监控跟踪、分布式消息队列、配置管理等领域的解决方案