├── .gitignore
├── LICENSE
├── ReadMe.md
├── boot-datasource
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── cn
│ │ │ └── com
│ │ │ └── wudskq
│ │ │ ├── BootDataSourceApplication.java
│ │ │ ├── annotation
│ │ │ └── DataSource.java
│ │ │ ├── aspectj
│ │ │ └── DataSourceAspect.java
│ │ │ ├── config
│ │ │ └── DruidConfig.java
│ │ │ ├── controller
│ │ │ └── DruidController.java
│ │ │ ├── core
│ │ │ └── text
│ │ │ │ ├── CharsetKit.java
│ │ │ │ ├── Convert.java
│ │ │ │ └── StrFormatter.java
│ │ │ ├── datasource
│ │ │ ├── DynamicDataSource.java
│ │ │ └── DynamicDataSourceContextHolder.java
│ │ │ ├── enums
│ │ │ └── DataSourceType.java
│ │ │ ├── mapper
│ │ │ └── DruidMapper.java
│ │ │ ├── properties
│ │ │ └── DruidProperties.java
│ │ │ ├── sevice
│ │ │ └── impl
│ │ │ │ ├── DruidSevice.java
│ │ │ │ └── DruidSeviceImpl.java
│ │ │ └── utils
│ │ │ ├── StringUtils.java
│ │ │ └── spring
│ │ │ └── SpringUtils.java
│ └── resources
│ │ ├── application.yml
│ │ ├── logback.xml
│ │ ├── mapper
│ │ └── DruidMapper.xml
│ │ └── sql
│ │ └── druid.sql
│ └── test
│ └── java
│ └── cn
│ └── com
│ └── wudskq
│ └── DruidSourceTest.java
├── boot-kafka
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── cn
│ │ └── com
│ │ └── wudskq
│ │ ├── BootKafkaApplication.java
│ │ ├── config
│ │ ├── KafkaOneConfig.java
│ │ └── KafkaTwoConfig.java
│ │ ├── consumer
│ │ └── Consumer.java
│ │ └── producer
│ │ └── ProducerController.java
│ └── resources
│ └── application.yml
├── boot-mqtt
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── cn
│ │ └── com
│ │ └── wudskq
│ │ ├── MqttBootApplication.java
│ │ ├── config
│ │ └── MqttConfig.java
│ │ ├── controller
│ │ └── MqttController.java
│ │ └── model
│ │ └── MqttDTO.java
│ └── resources
│ └── application.yml
├── boot-mybatis-Interceptor
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── cn
│ │ └── com
│ │ └── wudskq
│ │ ├── MybatisInterceptorApplication.java
│ │ ├── annotation
│ │ ├── CreateBy.java
│ │ ├── CreateTime.java
│ │ ├── SensitiveData.java
│ │ ├── SensitiveField.java
│ │ ├── UpdateBy.java
│ │ └── UpdateTime.java
│ │ ├── controller
│ │ └── MybatisController.java
│ │ ├── interceptor
│ │ ├── ConvertParameter.java
│ │ ├── CustomInterceptor.java
│ │ ├── DecryptInterceptor.java
│ │ └── EncryptInterceptor.java
│ │ ├── mapper
│ │ └── MybatisMapper.java
│ │ ├── model
│ │ ├── Plan.java
│ │ └── common
│ │ │ └── BaseDTO.java
│ │ ├── sevice
│ │ ├── MybatisSevice.java
│ │ ├── aes
│ │ │ ├── AESDecrypt.java
│ │ │ ├── AESEncrypt.java
│ │ │ ├── DecryptUtil.java
│ │ │ └── EncryptUtil.java
│ │ └── impl
│ │ │ └── MybatisSeviceImpl.java
│ │ └── utils
│ │ └── AESUtil.java
│ └── resources
│ ├── application.yml
│ ├── mapper
│ └── MybatisMapper.xml
│ └── sql
│ └── plan.sql
├── boot-mybatis-plus-interceptor
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── cn
│ │ └── com
│ │ └── wudskq
│ │ ├── MybatisPlusInterceptorApplication.java
│ │ ├── config
│ │ └── MyMetaObjectHandler.java
│ │ ├── controller
│ │ └── MybatisPlusController.java
│ │ ├── mapper
│ │ └── MybatisPlusMapper.java
│ │ ├── model
│ │ ├── Plan.java
│ │ └── common
│ │ │ └── BaseDTO.java
│ │ └── sevice
│ │ ├── MybatisPlusSevice.java
│ │ └── impl
│ │ └── MybatisPlusSeviceImpl.java
│ └── resources
│ ├── application.yml
│ └── mapper
│ └── MybatisMapper.xml
├── boot-rabbitmq
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── cn
│ │ └── com
│ │ └── wudskq
│ │ ├── BootRabbitMqApplication.java
│ │ └── listener
│ │ └── AmqListener.java
│ └── resources
│ └── application.yml
├── boot-redis
└── pom.xml
├── boot-security
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── cn
│ │ └── com
│ │ └── wudskq
│ │ ├── BootSecurityApplication.java
│ │ ├── conf
│ │ ├── JWTConfig.java
│ │ ├── Knife4jConfiguration.java
│ │ └── WebSecurityConfig.java
│ │ ├── controller
│ │ ├── IndexController.java
│ │ └── TSysUserController.java
│ │ ├── dao
│ │ ├── TSysResMapper.java
│ │ ├── TSysRoleMapper.java
│ │ ├── TSysRoleResMapper.java
│ │ ├── TSysUserMapper.java
│ │ └── TSysUserRoleMapper.java
│ │ ├── expection
│ │ ├── MyException.java
│ │ ├── TopException.java
│ │ └── UserAccessDeniedHandler.java
│ │ ├── filter
│ │ └── JWTAuthenticationFilter.java
│ │ ├── handler
│ │ ├── UserAuthenticationProvider.java
│ │ ├── UserLoginFailureHandler.java
│ │ ├── UserLoginSuccessHandler.java
│ │ ├── UserLogoutSuccessHandler.java
│ │ └── UserNotLoginHandler.java
│ │ ├── model
│ │ ├── SysUserDetails.java
│ │ ├── dto
│ │ │ ├── TSysRes.java
│ │ │ ├── TSysRole.java
│ │ │ ├── TSysRoleRes.java
│ │ │ ├── TSysUser.java
│ │ │ └── TSysUserRole.java
│ │ └── vo
│ │ │ └── Result.java
│ │ ├── permssion
│ │ └── UserPermissionEvaluator.java
│ │ ├── service
│ │ ├── TSysResService.java
│ │ ├── TSysRoleResService.java
│ │ ├── TSysRoleService.java
│ │ ├── TSysUserRoleService.java
│ │ ├── TSysUserService.java
│ │ └── impl
│ │ │ ├── SysUserDetailsService.java
│ │ │ ├── TSysResServiceImpl.java
│ │ │ ├── TSysRoleResServiceImpl.java
│ │ │ ├── TSysRoleServiceImpl.java
│ │ │ ├── TSysUserRoleServiceImpl.java
│ │ │ └── TSysUserServiceImpl.java
│ │ └── util
│ │ ├── JWTTokenUtil.java
│ │ └── Md5Util.java
│ └── resources
│ ├── application.yml
│ └── project.sql
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | ######################################################################
2 | # Build Tools
3 |
4 | .gradle
5 | /build/
6 | !gradle/wrapper/gradle-wrapper.jar
7 |
8 | target/
9 | !.mvn/wrapper/maven-wrapper.jar
10 |
11 | ######################################################################
12 | # IDE
13 | HELP.md
14 | /target/
15 | !.mvn/wrapper/maven-wrapper.jar
16 | ### 通用 ###
17 | *.class
18 | rebel.xml
19 |
20 | ### STS ###
21 | .apt_generated
22 | .classpath
23 | .factorypath
24 | .project
25 | .settings
26 | .springBeans
27 | .sts4-cache
28 |
29 | ### IntelliJ IDEA ###
30 | .idea
31 | *.iws
32 | *.iml
33 | *.ipr
34 |
35 | ### NetBeans ###
36 | /nbproject/private/
37 | /nbbuild/
38 | /dist/
39 | /nbdist/
40 | /.nb-gradle/
41 | /build/
42 |
43 | ### VS Code ###
44 | .vscode/
45 |
46 | nbproject/private/
47 | build/*
48 | nbbuild/
49 | dist/
50 | nbdist/
51 | .nb-gradle/
52 |
53 | ######################################################################
54 | # Others
55 | *.log
56 | *.xml.versionsBackup
57 | *.swp
58 |
59 | !*/build/*.java
60 | !*/build/*.html
61 | !*/build/*.xml
62 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 wudskq
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/ReadMe.md:
--------------------------------------------------------------------------------
1 | ## SpringBoot整合示例项目
2 |
3 |         
4 |
5 | **Spring Boot 中依赖集成的示例项目, 每个模块都为单独工程, 可单独作为最小依赖进行运行**
6 |
7 | 示例代码:
8 |
9 | - [boot-datasource](https://github.com/wudskq/spring-boot-project-case/tree/dev/boot-datasource) 配置多数据源
10 | - [boot-kafka](https://github.com/wudskq/spring-boot-project-case/tree/dev/boot-kafka) 集成Kafka
11 | - [boot-mqtt](https://github.com/wudskq/spring-boot-project-case/tree/dev/boot-mqtt) 集成MQTT
12 | - [boot-mybatis-Interceptor](https://github.com/wudskq/spring-boot-project-case/tree/dev/boot-mybatis-Interceptor) 配置Mybatis拦截器
13 | - [boot-mybatis-plus-interceptor](https://github.com/wudskq/spring-boot-project-case/tree/dev/boot-mybatis-plus-interceptor) 配置Mybatis-Plus拦截器
14 | - [boot-rabbitmq](https://github.com/wudskq/spring-boot-project-case/tree/dev/boot-rabbitmq) 集成RabbitMQ
15 | - [boot-redis](https://github.com/wudskq/spring-boot-project-case/tree/dev/boot-redis) 集成Redis
16 | - [boot-security](https://github.com/wudskq/spring-boot-project-case/tree/dev/boot-security) 集成SpringSecurity
17 |
--------------------------------------------------------------------------------
/boot-datasource/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | boot-project
7 | cn.com.wudskq
8 | 1.0.0
9 |
10 | 4.0.0
11 |
12 | boot-datasource
13 |
14 |
15 | 8
16 | 8
17 |
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter
23 |
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-starter-web
28 |
29 |
30 |
31 | mysql
32 | mysql-connector-java
33 |
34 |
35 |
36 | com.alibaba
37 | druid-spring-boot-starter
38 | 1.2.6
39 |
40 |
41 |
42 | org.mybatis
43 | mybatis
44 | 3.5.7
45 |
46 |
47 |
48 | com.baomidou
49 | mybatis-plus
50 | 3.4.3
51 |
52 |
53 |
54 | com.baomidou
55 | mybatis-plus-boot-starter
56 | 3.4.3
57 |
58 |
59 |
60 | org.springframework.boot
61 | spring-boot-starter-jdbc
62 |
63 |
64 |
65 | org.apache.commons
66 | commons-lang3
67 | 3.9
68 |
69 |
70 |
71 | org.aspectj
72 | aspectjweaver
73 |
74 |
75 |
76 | junit
77 | junit
78 | test
79 |
80 |
81 |
82 | org.springframework.boot
83 | spring-boot-test
84 |
85 |
86 |
87 | org.springframework
88 | spring-test
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/boot-datasource/src/main/java/cn/com/wudskq/BootDataSourceApplication.java:
--------------------------------------------------------------------------------
1 | package cn.com.wudskq;
2 |
3 | import org.mybatis.spring.annotation.MapperScan;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
7 |
8 | /**
9 | * @author chenfangchao
10 | * @title: cn.com.wudskq.BootDataSourceApplication
11 | * @projectName boot-project
12 | * @description: TODO boot配置多数据源
13 | * @date 2022/4/2 11:13 AM
14 | */
15 | //排除数据源自动配置
16 | @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
17 | @MapperScan("cn.com.wudskq.**.mapper")
18 | public class BootDataSourceApplication {
19 | public static void main(String[] args) {
20 | SpringApplication.run(BootDataSourceApplication.class,args);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/boot-datasource/src/main/java/cn/com/wudskq/annotation/DataSource.java:
--------------------------------------------------------------------------------
1 | package cn.com.wudskq.annotation;
2 |
3 |
4 |
5 | import cn.com.wudskq.enums.DataSourceType;
6 |
7 | import java.lang.annotation.*;
8 |
9 | /**
10 | * 自定义多数据源切换注解
11 | *
12 | * 优先级:先方法,后类,如果方法覆盖了类上的数据源类型,以方法的为准,否则以类上的为准
13 | *
14 | * @author seat
15 | */
16 | @Target({ ElementType.METHOD, ElementType.TYPE })
17 | @Retention(RetentionPolicy.RUNTIME)
18 | @Documented
19 | @Inherited
20 | public @interface DataSource
21 | {
22 | /**
23 | * 切换数据源名称
24 | */
25 | public DataSourceType value() default DataSourceType.MASTER;
26 | }
27 |
--------------------------------------------------------------------------------
/boot-datasource/src/main/java/cn/com/wudskq/aspectj/DataSourceAspect.java:
--------------------------------------------------------------------------------
1 | package cn.com.wudskq.aspectj;
2 |
3 |
4 | import cn.com.wudskq.annotation.DataSource;
5 | import cn.com.wudskq.datasource.DynamicDataSourceContextHolder;
6 | import cn.com.wudskq.utils.StringUtils;
7 | import org.aspectj.lang.ProceedingJoinPoint;
8 | import org.aspectj.lang.annotation.Around;
9 | import org.aspectj.lang.annotation.Aspect;
10 | import org.aspectj.lang.annotation.Pointcut;
11 | import org.aspectj.lang.reflect.MethodSignature;
12 | import org.slf4j.Logger;
13 | import org.slf4j.LoggerFactory;
14 | import org.springframework.core.annotation.AnnotationUtils;
15 | import org.springframework.core.annotation.Order;
16 | import org.springframework.stereotype.Component;
17 |
18 | import java.util.Objects;
19 |
20 | /**
21 | * 多数据源处理
22 | *
23 | * @author seat
24 | */
25 | @Aspect
26 | @Order(1)
27 | @Component
28 | public class DataSourceAspect
29 | {
30 | protected Logger logger = LoggerFactory.getLogger(getClass());
31 |
32 | @Pointcut("@annotation(cn.com.wudskq.annotation.DataSource)"
33 | + "|| @within(cn.com.wudskq.annotation.DataSource)")
34 | public void dsPointCut()
35 | {
36 |
37 | }
38 |
39 | @Around("dsPointCut()")
40 | public Object around(ProceedingJoinPoint point) throws Throwable
41 | {
42 | DataSource dataSource = getDataSource(point);
43 |
44 | if (StringUtils.isNotNull(dataSource))
45 | {
46 | DynamicDataSourceContextHolder.setDataSourceType(dataSource.value().name());
47 | }
48 |
49 | try
50 | {
51 | return point.proceed();
52 | }
53 | finally
54 | {
55 | // 销毁数据源 在执行方法之后
56 | DynamicDataSourceContextHolder.clearDataSourceType();
57 | }
58 | }
59 |
60 | /**
61 | * 获取需要切换的数据源
62 | */
63 | public DataSource getDataSource(ProceedingJoinPoint point)
64 | {
65 | MethodSignature signature = (MethodSignature) point.getSignature();
66 | DataSource dataSource = AnnotationUtils.findAnnotation(signature.getMethod(), DataSource.class);
67 | if (Objects.nonNull(dataSource))
68 | {
69 | return dataSource;
70 | }
71 |
72 | return AnnotationUtils.findAnnotation(signature.getDeclaringType(), DataSource.class);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/boot-datasource/src/main/java/cn/com/wudskq/config/DruidConfig.java:
--------------------------------------------------------------------------------
1 | package cn.com.wudskq.config;
2 |
3 |
4 | import cn.com.wudskq.datasource.DynamicDataSource;
5 | import cn.com.wudskq.enums.DataSourceType;
6 | import cn.com.wudskq.properties.DruidProperties;
7 | import cn.com.wudskq.utils.spring.SpringUtils;
8 | import com.alibaba.druid.pool.DruidDataSource;
9 | import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
10 | import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
11 | import com.alibaba.druid.util.Utils;
12 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
13 | import org.springframework.boot.context.properties.ConfigurationProperties;
14 | import org.springframework.boot.web.servlet.FilterRegistrationBean;
15 | import org.springframework.context.annotation.Bean;
16 | import org.springframework.context.annotation.Configuration;
17 | import org.springframework.context.annotation.Primary;
18 |
19 | import javax.servlet.*;
20 | import javax.sql.DataSource;
21 | import java.io.IOException;
22 | import java.util.HashMap;
23 | import java.util.Map;
24 |
25 | /**
26 | * druid 配置多数据源
27 | *
28 | * @author seat
29 | */
30 | @Configuration
31 | public class DruidConfig
32 | {
33 | @Bean
34 | @ConfigurationProperties("spring.datasource.druid.master")
35 | public DataSource masterDataSource(DruidProperties druidProperties)
36 | {
37 | DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
38 | return druidProperties.dataSource(dataSource);
39 | }
40 |
41 | @Bean
42 | @ConfigurationProperties("spring.datasource.druid.slave")
43 | @ConditionalOnProperty(prefix = "spring.datasource.druid.slave", name = "enabled", havingValue = "true")
44 | public DataSource slaveDataSource(DruidProperties druidProperties)
45 | {
46 | DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
47 | return druidProperties.dataSource(dataSource);
48 | }
49 |
50 | @Bean
51 | @ConfigurationProperties("spring.datasource.druid.slave1")
52 | @ConditionalOnProperty(prefix = "spring.datasource.druid.slave1", name = "enabled", havingValue = "true")
53 | public DataSource slaveDataSource1(DruidProperties druidProperties)
54 | {
55 | DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
56 | return druidProperties.dataSource(dataSource);
57 | }
58 |
59 | @Bean(name = "dynamicDataSource")
60 | @Primary
61 | public DynamicDataSource dataSource(DataSource masterDataSource)
62 | {
63 | Map