您的位置:首页 > 编程语言 > Java开发

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

2016-12-01 01:01 435 查看
上篇很虚的讲了一下我认为的微服务。既然微服务那么好,我现在如果想很快的搭建一个微服务系统,而且满足内聚、独立部署、分布式的特点,有没有很快的方式?

有的。由于身为菜鸟的我只对java熟悉,这里推荐一下Java的spring-boot框架,其他语言肯定也有大神已经给出了可以快速搭建系统的方案,自己动手丰衣足食啊。

闲话不多说,直接上代码:https://github.com/chxfantasy/micro-service-sample

这是一个可以完整run起来的spring-boot程序。

依赖

java 8

maven 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/

我只是个搬运工。。。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  分布式 java 框架