Spring Boot Demo

MIT GitHub stars GitHub forks GitHub watchers

spring boot demo 是一个用来学习 spring boot 的项目,总共包含 47 个集成demo,已经完成 36 个。包含集成 actuator(监控)、admin(可视化监控)、logback(日志)、aopLog(通过AOP记录web请求日志)、统一异常处理(json级别和页面级别)、freemarker(模板引擎)、thymeleaf(模板引擎)、Beetl(模板引擎)、Enjoy(模板引擎)、JdbcTemplate、JPA(ORM框架)、mybatis(ORM框架)、通用Mapper、PageHelper、mybatis-plus、BeetlSQL、upload(本地文件上传和七牛云文件上传)、redis(缓存)、ehcache(缓存)、email(发送各种类型邮件)、task(基础定时任务)、quartz(动态管理定时任务)、swagger(API接口管理测试)、security(基于RBAC的动态权限认证)、Session共享、Zookeeper(结合AOP实现分布式锁)、websocket(服务端推送监控服务器运行信息)、socket.io(聊天室)、ureport2(中国式报表)、打包成war文件、集成 ElasticSearch(基本操作和高级查询)、集成Dubbo(采用官方的starter)、neo4j(图数据库)、docker(容器化)。

分支

开发环境

运行方式

  1. git clone https://github.com/xkcoding/spring-boot-demo.git
  2. 使用 IDEA 打开 clone 下来的项目
  3. 在 IDEA 中打开项目
  4. 在 IDEA 中 Maven Projects 的面板导入根目录下 的 pom.xml
  5. Maven Projects 找不到的童鞋,可以勾上 View -> Tool Buttons ,然后Maven Projects的面板就会出现在IDEA的右侧
  6. 找到各个 module 的 Application 类就可以运行各个 module 了
  7. PS:运行各个 module 之前,请先注意有些模块是需要先初始化数据库数据的。

开发计划

查看 TODO 文件

根目录下的 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.xkcoding</groupId>
    <artifactId>spring-boot-demo</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <modules>
        <module>spring-boot-demo-helloworld</module>
        <module>spring-boot-demo-properties</module>
        <module>spring-boot-demo-actuator</module>
        <module>spring-boot-demo-admin-client</module>
        <module>spring-boot-demo-admin-server</module>
        <module>spring-boot-demo-logback</module>
        <module>spring-boot-demo-log-aop</module>
        <module>spring-boot-demo-exception-handler</module>
        <module>spring-boot-demo-template-freemarker</module>
        <module>spring-boot-demo-template-thymeleaf</module>
        <module>spring-boot-demo-template-beetl</module>
        <module>spring-boot-demo-template-enjoy</module>
        <module>spring-boot-demo-orm-jdbctemplate</module>
        <module>spring-boot-demo-orm-jpa</module>
        <module>spring-boot-demo-orm-mybatis</module>
        <module>spring-boot-demo-orm-mybatis-mapper-page</module>
        <module>spring-boot-demo-orm-mybatis-plus</module>
        <module>spring-boot-demo-orm-beetlsql</module>
        <module>spring-boot-demo-upload</module>
        <module>spring-boot-demo-cache-redis</module>
        <module>spring-boot-demo-cache-ehcache</module>
        <module>spring-boot-demo-email</module>
        <module>spring-boot-demo-task</module>
        <module>spring-boot-demo-task-quartz</module>
        <module>spring-boot-demo-swagger</module>
        <module>spring-boot-demo-swagger-beauty</module>
        <module>spring-boot-demo-rbac-security</module>
        <module>spring-boot-demo-rbac-shiro</module>
        <module>spring-boot-demo-session</module>
        <module>spring-boot-demo-social</module>
        <module>spring-boot-demo-zookeeper</module>
        <module>spring-boot-demo-mq-rabbitmq</module>
        <module>spring-boot-demo-mq-rocketmq</module>
        <module>spring-boot-demo-mq-kafka</module>
        <module>spring-boot-demo-websocket</module>
        <module>spring-boot-demo-websocket-socketio</module>
        <module>spring-boot-demo-ureport2</module>
        <module>spring-boot-demo-uflo</module>
        <module>spring-boot-demo-urule</module>
        <module>spring-boot-demo-activiti</module>
        <module>spring-boot-demo-async</module>
        <module>spring-boot-demo-dubbo</module>
        <module>spring-boot-demo-war</module>
        <module>spring-boot-demo-elasticsearch</module>
        <module>spring-boot-demo-mongodb</module>
        <module>spring-boot-demo-neo4j</module>
        <module>spring-boot-demo-docker</module>
    </modules>
    <packaging>pom</packaging>

    <name>spring-boot-demo</name>
    <url>http://xkcoding.com</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <spring.boot.version>2.1.0.RELEASE</spring.boot.version>
        <mysql.version>8.0.12</mysql.version>
        <hutool.version>4.3.1</hutool.version>
        <guava.version>27.0-jre</guava.version>
        <user.agent.version>1.20</user.agent.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring.boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>${mysql.version}</version>
            </dependency>
            <!-- hutool工具类 -->
            <dependency>
                <groupId>cn.hutool</groupId>
                <artifactId>hutool-all</artifactId>
                <version>${hutool.version}</version>
            </dependency>
            <!-- guava工具类 -->
            <dependency>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>${guava.version}</version>
            </dependency>
            <!-- 解析 UserAgent 信息 -->
            <dependency>
                <groupId>eu.bitwalker</groupId>
                <artifactId>UserAgentUtils</artifactId>
                <version>${user.agent.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.0.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.20.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>${spring.boot.version}</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

各 Module 介绍

Module 名称 Module 介绍
spring-boot-demo-helloworld spring-boot 的一个 helloworld
spring-boot-demo-properties spring-boot 读取配置文件中的内容
spring-boot-demo-actuator spring-boot 集成 spring-boot-starter-actuator 用于监控 spring-boot 的启动和运行状态
spring-boot-demo-admin-client spring-boot 集成 spring-boot-admin 来可视化的监控 spring-boot 程序的运行状态,可以与 actuator 互相搭配使用,客户端示例
spring-boot-demo-admin-server spring-boot 集成 spring-boot-admin 来可视化的监控 spring-boot 程序的运行状态,可以与 actuator 互相搭配使用,服务端示例
spring-boot-demo-logback spring-boot 集成 logback 日志
spring-boot-demo-log-aop spring-boot 使用 AOP 切面的方式记录 web 请求日志
spring-boot-demo-exception-handler spring-boot 统一异常处理,包括2种,第一种返回统一的 json 格式,第二种统一跳转到异常页面
spring-boot-demo-template-freemarker spring-boot 集成 Freemarker 模板引擎
spring-boot-demo-template-thymeleaf spring-boot 集成 Thymeleaf 模板引擎
spring-boot-demo-template-beetl spring-boot 集成 Beetl 模板引擎
spring-boot-demo-template-enjoy spring-boot 集成 Enjoy 模板引擎
spring-boot-demo-orm-jdbctemplate spring-boot 集成 Jdbc Template 操作数据库,并简易封装通用 Dao 层
spring-boot-demo-orm-jpa spring-boot 集成 spring-boot-starter-data-jpa 操作数据库
spring-boot-demo-orm-mybatis spring-boot 集成原生mybatis,使用 mybatis-spring-boot-starter 集成
spring-boot-demo-orm-mybatis-mapper-page spring-boot 集成通用Mapper和PageHelper,使用 mapper-spring-boot-starterpagehelper-spring-boot-starter 集成
spring-boot-demo-orm-mybatis-plus spring-boot 集成 mybatis-plus,使用 mybatis-plus-boot-starter 集成
spring-boot-demo-orm-beetlsql spring-boot 集成 beetl sql,使用 beetl-framework-starter 集成
spring-boot-demo-upload spring-boot 文件上传示例,包含本地文件上传以及七牛云文件上传
spring-boot-demo-cache-redis spring-boot 整合 redis,操作redis中的数据,并使用redis缓存数据
spring-boot-demo-cache-ehcache spring-boot 整合 ehcache,使用 ehcache 缓存数据
spring-boot-demo-email spring-boot 整合 email,包括发送简单文本邮件、HTML邮件(包括模板HTML邮件)、附件邮件、静态资源邮件
spring-boot-demo-task spring-boot 快速实现定时任务
spring-boot-demo-task-quartz spring-boot 整合 quartz,并实现对定时任务的管理,包括新增定时任务,删除定时任务,暂停定时任务,恢复定时任务,修改定时任务启动时间,以及定时任务列表查询
spring-boot-demo-swagger spring-boot 集成原生的 swagger 用于统一管理、测试 API 接口
spring-boot-demo-swagger-beauty spring-boot 集成第三方 swagger 美化API文档样式,用于统一管理、测试 API 接口
spring-boot-demo-rbac-security spring-boot 集成 spring security 完成基于RBAC权限模型的权限管理,支持自定义过滤请求,动态权限认证,使用 JWT 安全认证,支持在线人数统计,手动踢出用户等操作
spring-boot-demo-rbac-shiro 待完成
spring-boot-demo-session spring-boot 集成 Spring Session 实现Session共享、重启程序Session不失效
spring-boot-demo-social 待完成
spring-boot-demo-zookeeper spring-boot 集成 Zookeeper 结合AOP实现分布式锁
spring-boot-demo-mq-rabbitmq 待完成
spring-boot-demo-mq-rocketmq 待完成
spring-boot-demo-mq-kafka 待完成
spring-boot-demo-websocket spring-boot 集成 websocket,后端主动推送前端服务器运行信息
spring-boot-demo-websocket-socketio spring-boot 使用 netty-socketio 集成 websocket,实现一个简单的聊天室
spring-boot-demo-ureport2 待完成
spring-boot-demo-uflo 待完成
spring-boot-demo-urule 待完成
spring-boot-demo-activiti 待完成
spring-boot-demo-async 待完成
spring-boot-demo-war spring-boot 打成 war 包的配置
spring-boot-demo-elasticsearch spring-boot 集成 ElasticSearch,集成 spring-boot-starter-data-elasticsearch 完成对 ElasticSearch 的高级使用技巧,包括创建索引、配置映射、删除索引、增删改查基本操作、复杂查询、高级查询、聚合查询等
spring-boot-demo-dubbo spring-boot 集成 Dubbo,分别为公共模块 spring-boot-demo-dubbo-common、服务提供方spring-boot-demo-dubbo-provider、服务调用方spring-boot-demo-dubbo-consumer
spring-boot-demo-mongodb 待完成
spring-boot-demo-neo4j spring-boot 集成 Neo4j 图数据库,实现一个校园人物关系网的demo
spring-boot-demo-docker spring-boot 容器化

官方提供的 starter 介绍

Name Description
spring-boot-starter The core Spring Boot starter, including auto-configuration support, logging and YAML.
spring-boot-starter-actuator Production ready features to help you monitor and manage your application.
spring-boot-starter-amqp are neat
spring-boot-starter-aop Support for aspect-oriented programming including spring-aop and AspectJ.
spring-boot-starter-artemis Support for “Java Message Service API” via Apache Artemis.
spring-boot-starter-batch Support for “Spring Batch” including HSQLDB database.
spring-boot-starter-cache Support for Spring’s Cache abstraction.
spring-boot-starter-cloud-connectors Support for “Spring Cloud Connectors” which simplifies connecting to services in cloud platforms like Cloud Foundry and Heroku.
spring-boot-starter-data-elasticsearch Support for the Elasticsearch search and analytics engine including spring-data-elasticsearch.
spring-boot-starter-data-gemfire Support for the GemFire distributed data store including spring-data-gemfire.
spring-boot-starter-data-jpa Support for the “Java Persistence API” including spring-data-jpa, spring-orm and Hibernate.
spring-boot-starter-data-mongodb Support for the MongoDB NoSQL Database, including spring-data-mongodb.
spring-boot-starter-data-rest Support for exposing Spring Data repositories over REST via spring-data-rest-webmvc.
spring-boot-starter-data-solr Support for the Apache Solr search platform, including spring-data-solr.
spring-boot-starter-freemarker Support for the FreeMarker templating engine.
spring-boot-starter-groovy-templates Support for the Groovy templating engine.
spring-boot-starter-hateoas Support for HATEOAS-based RESTful services via spring-hateoas.
spring-boot-starter-hornetq Support for “Java Message Service API” via HornetQ.
spring-boot-starter-integration Support for common spring-integration modules.
spring-boot-starter-jdbc Support for JDBC databases.
spring-boot-starter-jersey Support for the Jersey RESTful Web Services framework.
spring-boot-starter-jta-atomikos Support for JTA distributed transactions via Atomikos.
spring-boot-starter-jta-bitronix Support for JTA distributed transactions via Bitronix.
spring-boot-starter-mail Support for javax.mail.
spring-boot-starter-mobile Support for spring-mobile.
spring-boot-starter-mustache Support for the Mustache templating engine.
spring-boot-starter-redis Support for the REDIS key-value data store, including spring-redis.
spring-boot-starter-security Support for spring-security.
spring-boot-starter-social-facebook Support for spring-social-facebook.
spring-boot-starter-social-linkedin Support for spring-social-linkedin.
spring-boot-starter-social-twitter Support for spring-social-twitter.
spring-boot-starter-test Support for common test dependencies, including JUnit, Hamcrest and Mockito along with the spring-test module.
spring-boot-starter-thymeleaf Support for the Thymeleaf templating engine, including integration with Spring.
spring-boot-starter-velocity Support for the Velocity templating engine.
spring-boot-starter-web Support for full-stack web development, including Tomcat and spring-webmvc.
spring-boot-starter-websocket Support for WebSocket development.
spring-boot-starter-ws Support for Spring Web Services.

License

MIT

Copyright (c) 2018 Yangkai.Shen