基于 tyboot 快速初始化 springboot 单体项目
tyboot源码:
示例项目 tybootdemo 源码
项目目录结构:
项目结构其中包名自行定义,;
controller 和 face 目录 为约定目录结构.建议保持一致.
配置文件建议使用多环境配置,启动的时候添加参数 spring.profiles.active 如下:
Run-->Edit Configurations...
环境参数pom.xml 文件内容:
tyboot的包放在个人私服,可以临时使用,建议将tyboot源码克隆以后自行打包到自己的私服
<?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>org.typroject</groupId>
<artifactId>tybootdemo</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>tybootdemo</name>
<description>tybootdemo</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<tyboot.version>1.1.20Ty-SNAPSHOT</tyboot.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<!-- 引用tyboot核心包 start -->
<dependency>
<groupId>org.typroject</groupId>
<artifactId>tyboot-core-foundation</artifactId>
<version>${tyboot.version}</version>
</dependency>
<dependency>
<groupId>org.typroject</groupId>
<artifactId>tyboot-core-restful</artifactId>
<version>${tyboot.version}</version>
<exclusions>
<exclusion>
<groupId>org.typroject</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.typroject</groupId>
<artifactId>tyboot-core-auth</artifactId>
<version>${tyboot.version}</version>
<exclusions>
<exclusion>
<groupId>org.typroject</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.typroject</groupId>
<artifactId>tyboot-core-rdbms</artifactId>
<version>${tyboot.version}</version>
<exclusions>
<exclusion>
<groupId>org.typroject</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.typroject</groupId>
<artifactId>tyboot-component-cache</artifactId>
<version>${tyboot.version}</version>
<exclusions>
<exclusion>
<groupId>org.typroject</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 引用tyboot核心包 end -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
<version>1.4.5.RELEASE</version>
</dependency>
</dependencies>
<!-- 目前使用的springboot版本为 2.1.6.RELEASE -->
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- tyboot的包放在个人私服,可以临时使用,建议将tyboot源码克隆以后自行打包到自己的私服 -->
<repositories>
<repository>
<id>maven-public</id>
<name>maven-public</name>
<url>http://repo.typroject.org:8081/repository/maven-public/</url>
</repository>
<repository>
<id>maven-snapshot</id>
<name>maven-snapshot</name>
<url>http://repo.typroject.org:8081/repository/maven-snapshots/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven-public</id>
<name>maven-public</name>
<url>http://repo.typroject.org:8081/repository/maven-public/</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties 文件内容:
推荐使用多环境配置
spring.application.name=tybootdemo
server.port=30010
server.servlet.context-path=/demo
server.compression.enabled=true
server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain
#默认就是2048 byte
server.compression.min-response-size=2048
#spring.jackson.default-property-inclusion=non_null
logging.config=classpath:logback-${spring.profiles.active}.xml
# mybatis_config
mybatis-plus.mapper-locations=classpath:mapper/*Mapper.xml
mybatis-plus.type-aliases-package=org.typroject.*.*.face.*.orm.entity
application-dev.properties 文件内容:
数据库和缓存配置 会接下来演示 示例功能用到.
# jdbc_config
spring.datasource.url=jdbc:mysql://192.168.1.212:3306/tybootdemo?characterEncoding=utf8&serverTimezone=Asia/Shanghai
spring.datasource.username=tybootdemo
spring.datasource.password=tybootdemo
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#not support for spring-boot v1.5+, use org.apache.tomcat.jdbc.pool.DataSource by default.
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.maximum-pool-size=15
spring.datasource.hikari.auto-commit=true
spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.pool-name=DatebookHikariCP
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 1
# REDIS (RedisProperties)
spring.redis.database=10
spring.redis.host=192.168.1.212
spring.redis.port=6379
spring.redis.password=xxxxx
spring.redis.timeout=0
logback-dev.xml 文件内容
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<!-- 控制台输出 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<!--myibatis log configure-->
<logger name="com.apache.ibatis" level="TRACE"/>
<logger name="java.sql.Connection" level="DEBUG"/>
<logger name="java.sql.Statement" level="DEBUG"/>
<logger name="java.sql.PreparedStatement" level="DEBUG"/>
<logger name="org.typroject" level="DEBUG"/>
<logger name="org.springframework" level="DEBUG"/>
<logger name="com.baomidou" level="DEBUG"/>
<!-- 日志输出级别 -->
<root level="DEBUG">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
至此 已经完成工程初始化,可以进一步使用tyboot所有的核心功能,包括
无sql编码体验
基于租户的数据隔离机制
数据缓存
基于简单固定窗口的请求频次限制
基于拦截器的请求拦截扩展
错误处理与异常定义
统一请求上下文
统一返回格式
登录认证方式扩展
认证机制
接口输入输出加密
便捷工具类
本地多账号登录
网友评论