如何快速构建基于java的微服务

上篇很虚的讲了一下我认为的微服务。既然微服务那么好,我现在如果想很快的搭建一个微服务系统,而且满足内聚、独立部署、分布式的特点,有没有很快的方式?
有的。由于身为菜鸟的我只对java熟悉,这里推荐一下Java的spring-boot框架,其他语言肯定也有大神已经给出了可以快速搭建系统的方案,自己动手丰衣足食啊。

闲话不多说,直接上代码:https://github.com/chxfantasy/micro-service-sample
这是一个可以完整run起来的spring-boot程序。

依赖

  1. java 8
  2. maven 3
  3. 但是因为我的程序里面配置了mongodb、redis、etcd等,要run起来我这个程序,这些依赖也不可少。后面会介绍在我的程序里去掉这些多余配置应该怎么做

运行命令

mvn spring-boot:run

集群部署:

1. 首先是编译和打包:mvn clean package -DskipTests(是否不运行单元测试)
2. 打包之后,在target/目录会生成 micro-service-sample-0.0.1-SNAPSHOT.jar, 将这个文件copy到服务器,直接java -jar micro-service-sample-0.0.1-SNAPSHOT.jar 就可以完成部署。当然,建议在java -jar命令中指定java的运行参数,堆大小栈大小等

代码包含的功能:

1. mybatis and a plug-in for paging, named pageHelper
2. multi database configuartions, primary db, slave db and read-only db
3. a custom annotation used for dynamicaly chosing db from multi dbs
4. using druid from alibaba as the datasource
5. basically some demo filters and intercepters, definited by annotations
6. a RequestLocaleResolver for internationality
7. logging based on slf4j and logback, with customising the log format
8. redis connection config and sample in unit test
9. mongodb connection config and sample in unit test, with mongodb deployed on Replica Set way
10. etcd, zookeeper
11. this sample does not contains the jms and mq module, for i think the guildline of spring-boot is detailed enough, http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-messaging

如果我想自己快速搞一个spring-boot应用,怎么搞?

http://start.spring.io/
我只是个搬运工。。。

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值