├── .gitignore ├── LICENSE ├── bcrypt-environment ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── ktz │ │ └── deploy │ │ └── bcrypt │ │ ├── BcryptEnvironmentApplication.java │ │ ├── config │ │ ├── BeanConfiguration.java │ │ └── SecurityConfig.java │ │ └── controller │ │ └── EncoderController.java │ └── resources │ └── application.yml ├── druid-environment ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── ktz │ │ └── deploy │ │ └── druid │ │ ├── DruidEnvironmentApplication.java │ │ ├── entity │ │ └── User.java │ │ └── mapper │ │ └── UserMapper.java │ └── resources │ ├── application.yml │ └── mapper │ └── UserMapper.xml ├── dynamic-datasource-environment ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── ktz │ │ └── deploy │ │ └── dynamic │ │ └── datasource │ │ ├── DynamicDatasourceEnvironmentApplication.java │ │ ├── controller │ │ └── TestController.java │ │ ├── entity │ │ └── SysUser.java │ │ ├── mapper │ │ └── UserMapper.java │ │ └── service │ │ ├── UserService.java │ │ └── impl │ │ └── UserServiceImpl.java │ └── resources │ ├── application.yml │ └── mapper │ └── UserMapper.xml ├── elasticsearch-environment ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── ktz │ │ └── deploy │ │ └── elasticsearch │ │ ├── ElasticsearchEnvironmentApplication.java │ │ ├── controller │ │ ├── CreateIndexController.java │ │ ├── DataController.java │ │ └── SearchController.java │ │ ├── documents │ │ └── GoodsInfoDocument.java │ │ ├── dto │ │ └── SearchDto.java │ │ ├── entity │ │ └── GoodsInfo.java │ │ └── mapper │ │ └── GoodsInfoMapper.java │ └── resources │ ├── application.yml │ ├── esmapper │ └── GoodsInfo.xml │ └── mapper │ └── GoodsInfoMapper.xml ├── feign-environment ├── feign-caller-service │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── ktz │ │ └── deploy │ │ └── feign │ │ └── service │ │ └── feign │ │ ├── MessageFeignService.java │ │ └── fallback │ │ └── MessageFeignFallback.java ├── feign-caller │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── ktz │ │ │ └── deploy │ │ │ └── feign │ │ │ ├── FeignCallerApplication.java │ │ │ └── controller │ │ │ └── MemberController.java │ │ └── resources │ │ └── application.yml ├── feign-provider │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── ktz │ │ │ └── deploy │ │ │ └── feign │ │ │ ├── FeignProviderApplication.java │ │ │ └── api │ │ │ └── MemberApi.java │ │ └── resources │ │ └── application.yml └── pom.xml ├── global-exception-environment └── src │ └── main │ └── java │ └── com │ └── ktz │ └── deploy │ ├── controller │ └── TestController.java │ ├── exception │ ├── GlobalException.java │ └── GlobalExceptionHandler.java │ └── response │ ├── ResponseCode.java │ └── ResponseData.java ├── hikaricp-environment ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── ktz │ │ └── deploy │ │ └── hikaricp │ │ ├── HikaricpEnvironmentApplication.java │ │ ├── entity │ │ └── User.java │ │ └── mapper │ │ └── UserMapper.java │ └── resources │ ├── application.yml │ └── mapper │ └── UserMapper.xml ├── jdbc-environment ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── ktz │ │ └── deploy │ │ └── jdbc │ │ ├── JdbcEnvironmentApplication.java │ │ ├── config │ │ └── DataSourceConfig.java │ │ ├── controller │ │ ├── IndexController.java │ │ └── MarketSuperviseController.java │ │ ├── entity │ │ └── dto │ │ │ ├── AbsDepartmetData.java │ │ │ ├── DepartDataDto.java │ │ │ ├── MarketSuperviseParam.java │ │ │ ├── Page.java │ │ │ ├── ProvBase.java │ │ │ └── ProvTable.java │ │ ├── enums │ │ ├── DepartEnum.java │ │ └── DepartTableEnum.java │ │ └── service │ │ ├── DepartmentDataService.java │ │ ├── IndexService.java │ │ └── impl │ │ ├── DepartmentDataServiceImpl.java │ │ └── IndexServiceImpl.java │ └── resources │ └── application.yml ├── kafka-environment ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── ktz │ │ └── deploy │ │ └── kafka │ │ ├── KafkaEnvironmentApplication.java │ │ ├── config │ │ └── KafkaConfig.java │ │ ├── consumer │ │ └── ConsumerController.java │ │ └── producer │ │ └── ProducerController.java │ └── resources │ └── application.yml ├── log-environment ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── ktz │ │ └── deploy │ │ └── log │ │ ├── LogEnvironmentApplication.java │ │ ├── annotation │ │ └── LogAnnotation.java │ │ ├── aspect │ │ └── LogAspect.java │ │ └── controller │ │ └── LogController.java │ └── resources │ ├── application.yml │ └── logback-spring.xml ├── mongodb-environment ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── ktz │ │ └── deploy │ │ └── mongodb │ │ ├── MongodbEnvironmentApplication.java │ │ ├── controller │ │ └── MongoController.java │ │ └── entity │ │ └── User.java │ └── resources │ └── application.yml ├── nacos-environment ├── nacos-consumer │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── ktz │ │ │ └── deploy │ │ │ └── nacos │ │ │ └── consumer │ │ │ ├── NacosConsumerApplication.java │ │ │ ├── config │ │ │ └── ConsumerConfiguration.java │ │ │ ├── controller │ │ │ ├── FeignController.java │ │ │ └── TestController.java │ │ │ └── service │ │ │ ├── EchoService.java │ │ │ └── fallback │ │ │ └── EchoServiceFallback.java │ │ └── resources │ │ ├── application-dev.yml │ │ └── bootstrap.yml ├── nacos-provider │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── ktz │ │ │ └── deploy │ │ │ └── nacos │ │ │ └── provider │ │ │ ├── NacosProviderApplication.java │ │ │ └── controller │ │ │ └── EchoController.java │ │ └── resources │ │ ├── application-dev.yml │ │ └── bootstrap.yml └── pom.xml ├── oauth2-environment ├── oauth2-resource │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ ├── com │ │ │ └── ktz │ │ │ │ └── deploy │ │ │ │ └── oauth2 │ │ │ │ └── resource │ │ │ │ ├── OAuth2ResourceApplication.java │ │ │ │ ├── config │ │ │ │ └── ResourceServerConfiguration.java │ │ │ │ ├── controller │ │ │ │ └── TbContentController.java │ │ │ │ ├── domain │ │ │ │ ├── TbContent.java │ │ │ │ └── TbContentCategory.java │ │ │ │ ├── dto │ │ │ │ └── ResponseResult.java │ │ │ │ ├── mapper │ │ │ │ ├── TbContentCategoryMapper.java │ │ │ │ └── TbContentMapper.java │ │ │ │ └── service │ │ │ │ ├── TbContentCategoryService.java │ │ │ │ ├── TbContentService.java │ │ │ │ └── impl │ │ │ │ ├── TbContentCategoryServiceImpl.java │ │ │ │ └── TbContentServiceImpl.java │ │ └── tk │ │ │ └── mybatis │ │ │ └── mapper │ │ │ └── MyMapper.java │ │ └── resources │ │ ├── application.yml │ │ └── mapper │ │ ├── TbContentCategoryMapper.xml │ │ └── TbContentMapper.xml ├── oauth2-server │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ ├── com │ │ │ └── ktz │ │ │ │ └── deploy │ │ │ │ └── oauth2 │ │ │ │ └── server │ │ │ │ ├── OAuth2ServerApplication.java │ │ │ │ ├── configure │ │ │ │ ├── AuthorizationServerConfiguration.java │ │ │ │ ├── Secret.java │ │ │ │ ├── UserDetailsServiceImpl.java │ │ │ │ └── WebSecurityConfiguration.java │ │ │ │ ├── domain │ │ │ │ ├── TbPermission.java │ │ │ │ └── TbUser.java │ │ │ │ ├── mapper │ │ │ │ ├── TbPermissionMapper.java │ │ │ │ └── TbUserMapper.java │ │ │ │ └── service │ │ │ │ ├── TbPermissionService.java │ │ │ │ ├── TbUserService.java │ │ │ │ └── impl │ │ │ │ ├── TbPermissionServiceImpl.java │ │ │ │ └── TbUserServiceImpl.java │ │ └── tk │ │ │ └── mybatis │ │ │ └── mapper │ │ │ └── MyMapper.java │ │ └── resources │ │ ├── application.yml │ │ └── mapper │ │ ├── TbPermissionMapper.xml │ │ └── TbUserMapper.xml └── pom.xml ├── redis-environment ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── ktz │ │ └── deploy │ │ └── redis │ │ ├── RedisEnvironmentApplication.java │ │ ├── config │ │ └── RedisConfig.java │ │ └── entity │ │ └── User.java │ └── resources │ └── application.yml ├── redisson-environment ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── ktz │ │ └── deploy │ │ └── redisson │ │ ├── RedissonEnvironmentApplication.java │ │ ├── config │ │ └── RedissonConfig.java │ │ ├── controller │ │ └── OrderController.java │ │ └── service │ │ ├── OrderService.java │ │ └── impl │ │ └── OrderServiceImpl.java │ └── resources │ └── application.yml ├── swagger-environment ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── ktz │ │ └── deploy │ │ └── swagger │ │ ├── SwaggerEnvironmentApplication.java │ │ ├── config │ │ └── Swagger2.java │ │ ├── controller │ │ └── UserController.java │ │ └── entity │ │ └── User.java │ └── resources │ └── application.yml ├── undertow-environment ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── ktz │ │ └── deploy │ │ └── undertow │ │ ├── UndertowEnvironmentApplication.java │ │ └── controller │ │ └── HelloController.java │ └── resources │ └── application.yml └── websocket-environment ├── pom.xml └── src └── main ├── java └── com │ └── ktz │ └── deploy │ └── websocket │ ├── WebsocketApplication.java │ ├── config │ ├── WebsocketConfig.java │ └── WebsocketServer.java │ └── controller │ └── WsController.java └── resources └── application.yml /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | .idea/ 15 | *.jar 16 | *.war 17 | *.nar 18 | *.ear 19 | *.zip 20 | *.tar.gz 21 | *.rar 22 | 23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 24 | hs_err_pid* 25 | -------------------------------------------------------------------------------- /bcrypt-environment/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | .mvn/wrapper/ 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea/ 18 | *.iws 19 | *.iml 20 | *.ipr 21 | /target 22 | 23 | ### NetBeans ### 24 | /nbproject/private/ 25 | /nbbuild/ 26 | /dist/ 27 | /nbdist/ 28 | /.nb-gradle/ 29 | build/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | -------------------------------------------------------------------------------- /bcrypt-environment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.5.RELEASE 9 | 10 | 11 | com.ktz.deploy 12 | bcrypt-environment 13 | 0.0.1-SNAPSHOT 14 | bcrypt-environment 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-security 30 | 31 | 32 | 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-maven-plugin 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /bcrypt-environment/src/main/java/com/ktz/deploy/bcrypt/BcryptEnvironmentApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.bcrypt; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BcryptEnvironmentApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BcryptEnvironmentApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /bcrypt-environment/src/main/java/com/ktz/deploy/bcrypt/config/BeanConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.bcrypt.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 6 | 7 | @Configuration 8 | public class BeanConfiguration { 9 | 10 | @Bean 11 | public BCryptPasswordEncoder bCryptPasswordEncoder(){ 12 | return new BCryptPasswordEncoder(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /bcrypt-environment/src/main/java/com/ktz/deploy/bcrypt/config/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.bcrypt.config; 2 | 3 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 4 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 5 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 6 | 7 | @EnableWebSecurity 8 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 9 | 10 | @Override 11 | protected void configure(HttpSecurity http) throws Exception { 12 | http 13 | .authorizeRequests() 14 | .antMatchers("/**").permitAll() 15 | .anyRequest().authenticated() 16 | .and().csrf().disable(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /bcrypt-environment/src/main/java/com/ktz/deploy/bcrypt/controller/EncoderController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.bcrypt.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | @RestController 10 | public class EncoderController { 11 | 12 | @Autowired 13 | private BCryptPasswordEncoder bCryptPasswordEncoder; 14 | 15 | private static String oldPassword; 16 | 17 | /** 18 | * 加密 19 | * 20 | * @param password 21 | * @return 22 | */ 23 | @GetMapping("/encoder") 24 | public String encoder(@RequestParam String password) { 25 | oldPassword = bCryptPasswordEncoder.encode(password); 26 | return oldPassword; 27 | } 28 | 29 | /** 30 | * 判断密码是否一致 无需手动解密 31 | * 32 | * @param password 33 | * @return 34 | */ 35 | @GetMapping("/un_encoder") 36 | public boolean unEncoder(@RequestParam String password) { 37 | return bCryptPasswordEncoder.matches(password, oldPassword); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /bcrypt-environment/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /druid-environment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.5.RELEASE 9 | 10 | 11 | com.ktz.deploy 12 | druid-environment 13 | 0.0.1-SNAPSHOT 14 | druid-environment 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-data-jdbc 25 | 26 | 27 | com.baomidou 28 | mybatis-plus-boot-starter 29 | 3.1.2 30 | 31 | 32 | mysql 33 | mysql-connector-java 34 | runtime 35 | 36 | 37 | com.alibaba 38 | druid-spring-boot-starter 39 | 1.1.21 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-web 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-maven-plugin 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /druid-environment/src/main/java/com/ktz/deploy/druid/DruidEnvironmentApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.druid; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * Description: 8 | * 9 | * @author kaituozhe_sh 10 | */ 11 | @SpringBootApplication 12 | public class DruidEnvironmentApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(DruidEnvironmentApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /druid-environment/src/main/java/com/ktz/deploy/druid/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.druid.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * ClassName: User 7 | * Description: 8 | * date: 2020/3/8 10:44 9 | * 10 | * @author kaituozhe_sh 11 | */ 12 | public class User implements Serializable { 13 | } 14 | -------------------------------------------------------------------------------- /druid-environment/src/main/java/com/ktz/deploy/druid/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.druid.mapper; 2 | 3 | /** 4 | * Description: 5 | * date: 2020/3/8 10:45 6 | * 7 | * @author kaituozhe_sh 8 | */ 9 | public interface UserMapper { 10 | } 11 | -------------------------------------------------------------------------------- /druid-environment/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | spring: 3 | datasource: 4 | type: com.alibaba.druid.pool.DruidDataSource 5 | username: root 6 | password: root 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/problem?characterEncoding=utf8&useUnicode=true&useSSL=false&useTimezone=true&serverTimezone=GMT%2B8 9 | druid: 10 | initial-size: 5 # 初始化时建立物理连接的个数。初始化发生在显示调用init方法,或者第一次getConnection时 11 | max-active: 10 # 连接池中最多支持多少个活动会话 12 | min-idle: 1 # 最小空闲连接,回收空闲连接时,将保证至少有min-idle个连接 13 | max-wait: 60000 # 程序向连接池中请求连接超时,超过max-wait的值后,认为本次请求失败,即连接池没有可用连接,单位毫秒,设置-1时表示无限等待 14 | # 获取连接时最大等待时间,单位毫秒。配置max-wait之后,默认启用公平锁,并发效率会有所下降,如果需要可以通过配置useUnfairLock属性为true使用费公平锁 15 | pool-prepared-statements: true # 是否缓存preparedStatement,也就是PSCache。PSCache对支持游标的数据库性能提升巨大,比如说oracle。在mysql下建议关闭 16 | validation-query: SELECT 1 FROM DUAL # 检查池中的连接是否仍可用的SQL语句,druid会连接到数据库执行该SQL,如果正常返回,则表示连接可用,否则表示连接不可用 17 | validation-query-timeout: 10000 # 单位:秒,检测连接是否有效的超时时间。底层调用jdbdStatement对象的void setQueryTimeout(int seconds)方法 18 | test-on-borrow: true # 程序 申请 连接时,进行连接有效性检查(低效,影响性能) 19 | test-on-return: false # 程序 返还 连接时,进行连接有效性检查(低效,影响性能) 20 | test-while-idle: true # 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于time-between-eviction-runs-millis,执行validation-query检测连接是否有效 21 | time-between-eviction-runs-millis: 60000 # 有两个含义: 22 | # Destroy现场会检测连接的间隔时间,如果连接空闲时间大于等于min-evictable-idle-time-millis则关闭物理连接 23 | # test-while-idle的判断依据 24 | min-evictable-idle-time-millis: 30000 # 池中某个连接的空闲时长达到N毫秒后,连接池在下次检查空闲连接时,将回收该连接,要小于防火墙超时设置 25 | filters: stat # stat:监控统计 log4j/slf4j:日志监控 wall:防御SQL注入 26 | mybatis-plus: 27 | mapper-locations: classpath:/mapper/*Mapper.xml 28 | type-aliases-package: com.ktz.deploy.druid.entity 29 | global-config: 30 | db-config: 31 | id-type: AUTO 32 | logic-delete-value: 1 33 | logic-not-delete-value: 0 34 | configuration: 35 | map-underscore-to-camel-case: true 36 | cache-enabled: false 37 | -------------------------------------------------------------------------------- /druid-environment/src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /dynamic-datasource-environment/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | .mvn/wrapper/ 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea/ 18 | *.iws 19 | *.iml 20 | *.ipr 21 | /target 22 | 23 | ### NetBeans ### 24 | /nbproject/private/ 25 | /nbbuild/ 26 | /dist/ 27 | /nbdist/ 28 | /.nb-gradle/ 29 | build/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | -------------------------------------------------------------------------------- /dynamic-datasource-environment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.5.RELEASE 9 | 10 | 11 | com.ktz.deploy 12 | dynamic-datasource-environment 13 | 0.0.1-SNAPSHOT 14 | dynamic-datasource-environment 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | 28 | 29 | mysql 30 | mysql-connector-java 31 | runtime 32 | 33 | 34 | 35 | com.baomidou 36 | dynamic-datasource-spring-boot-starter 37 | 2.5.4 38 | 39 | 40 | 41 | com.baomidou 42 | mybatis-plus-boot-starter 43 | 3.1.2 44 | 45 | 46 | 47 | org.projectlombok 48 | lombok 49 | true 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /dynamic-datasource-environment/src/main/java/com/ktz/deploy/dynamic/datasource/DynamicDatasourceEnvironmentApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.dynamic.datasource; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | @MapperScan("com.ktz.deploy.dynamic.datasource.mapper*") 7 | @SpringBootApplication 8 | public class DynamicDatasourceEnvironmentApplication { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(DynamicDatasourceEnvironmentApplication.class, args); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /dynamic-datasource-environment/src/main/java/com/ktz/deploy/dynamic/datasource/controller/TestController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.dynamic.datasource.controller; 2 | 3 | import com.ktz.deploy.dynamic.datasource.service.UserService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @ClassName TestController 10 | * @Description 11 | * @Author kaituozhesh 12 | * @Date 2020/3/16 11:28 13 | * @Version V1.0 14 | **/ 15 | @RestController 16 | public class TestController { 17 | 18 | @Autowired 19 | private UserService userService; 20 | 21 | @GetMapping("/get") 22 | public Object get(Integer id) { 23 | return userService.selectByPrimaryKey(id); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /dynamic-datasource-environment/src/main/java/com/ktz/deploy/dynamic/datasource/entity/SysUser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 the original author or authors. 3 | */ 4 | package com.ktz.deploy.dynamic.datasource.entity; 5 | 6 | import lombok.Data; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * @author Zhao Wanzi 12 | */ 13 | @Data 14 | public class SysUser { 15 | /** 16 | * id 17 | */ 18 | private Long id; 19 | 20 | private String uid; 21 | 22 | private String loginUser; 23 | 24 | private String loginPassword; 25 | 26 | private int type; 27 | 28 | private String createBy; 29 | 30 | 31 | private Date createDate; 32 | 33 | 34 | private String updateBy; 35 | 36 | private Date updateDate; 37 | 38 | 39 | private String remarks; 40 | 41 | 42 | private String smsCode; 43 | 44 | 45 | private String pwd; 46 | 47 | 48 | private Integer frozen; 49 | 50 | private Integer loginStats; 51 | 52 | 53 | private String delFlag; 54 | 55 | 56 | private String userName; 57 | 58 | 59 | private String names; 60 | 61 | private String hangye; 62 | 63 | private String orgName; 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /dynamic-datasource-environment/src/main/java/com/ktz/deploy/dynamic/datasource/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.dynamic.datasource.mapper; 2 | 3 | import com.baomidou.dynamic.datasource.annotation.DS; 4 | import com.ktz.deploy.dynamic.datasource.entity.SysUser; 5 | 6 | @DS("lanhuapp-test") 7 | public interface UserMapper { 8 | 9 | SysUser selectByPrimaryKey(Integer id); 10 | } 11 | -------------------------------------------------------------------------------- /dynamic-datasource-environment/src/main/java/com/ktz/deploy/dynamic/datasource/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.dynamic.datasource.service; 2 | 3 | 4 | import com.ktz.deploy.dynamic.datasource.entity.SysUser; 5 | 6 | /** 7 | * @author Zhao Wanzi 8 | */ 9 | public interface UserService { 10 | 11 | 12 | SysUser selectByPrimaryKey(Integer id); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /dynamic-datasource-environment/src/main/java/com/ktz/deploy/dynamic/datasource/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 the original author or authors. 3 | */ 4 | package com.ktz.deploy.dynamic.datasource.service.impl; 5 | 6 | 7 | import com.ktz.deploy.dynamic.datasource.entity.SysUser; 8 | import com.ktz.deploy.dynamic.datasource.mapper.UserMapper; 9 | import com.ktz.deploy.dynamic.datasource.service.UserService; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | 13 | /** 14 | * @author Zhao Wanzi 15 | */ 16 | @Service 17 | public class UserServiceImpl implements UserService { 18 | 19 | @Autowired 20 | private UserMapper userMapper; 21 | 22 | @Override 23 | public SysUser selectByPrimaryKey(Integer id) { 24 | return userMapper.selectByPrimaryKey(id); 25 | } 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /dynamic-datasource-environment/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | dynamic: 4 | primary: lanhuapp-test 5 | datasource: 6 | lanhuapp-test: 7 | username: xry 8 | password: zjxry!@#123 9 | driver-class-name: com.mysql.cj.jdbc.Driver 10 | url: jdbc:mysql://rm-bp14yb5jkz9ih8vg21o.mysql.rds.aliyuncs.com:3306/lanhuapp-test?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai 11 | lanhuapp: 12 | username: xry 13 | password: zjxry!@#123 14 | driver-class-name: com.mysql.cj.jdbc.Driver 15 | url: jdbc:mysql://rm-bp14yb5jkz9ih8vg21o.mysql.rds.aliyuncs.com:3306/lanhuapp?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai 16 | druid: 17 | initial-size: 5 18 | max-active: 10 19 | min-idle: 1 20 | max-wait: 60000 21 | pool-prepared-statements: true 22 | validation-query: SELECT 1 FROM DUAL 23 | validation-query-timeout: 10000 24 | test-on-borrow: true 25 | test-on-return: false 26 | test-while-idle: true 27 | time-between-eviction-runs-millis: 60000 28 | min-evictable-idle-time-millis: 30000 29 | filters: stat 30 | mybatis-plus: 31 | mapper-locations: classpath:/mapper/*Mapper.xml 32 | type-aliases-package: com.ktz.deploy.dynamic.datasource.entity 33 | global-config: 34 | db-config: 35 | id-type: AUTO 36 | logic-delete-value: 1 37 | logic-not-delete-value: 0 38 | configuration: 39 | map-underscore-to-camel-case: true 40 | cache-enabled: false -------------------------------------------------------------------------------- /dynamic-datasource-environment/src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | id, `uid`, hangye, org_name, create_by, create_date, update_by, update_date, remarks, del_flag 8 | 9 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /elasticsearch-environment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.5.RELEASE 9 | 10 | 11 | com.ktz.deploy 12 | elasticsearch-environment 13 | 0.0.1-SNAPSHOT 14 | elasticsearch-environment 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | 28 | 29 | com.bbossgroups.plugins 30 | bboss-elasticsearch-spring-boot-starter 31 | 5.9.1 32 | 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-data-jdbc 38 | 39 | 40 | com.baomidou 41 | mybatis-plus-boot-starter 42 | 3.1.2 43 | 44 | 45 | mysql 46 | mysql-connector-java 47 | runtime 48 | 49 | 50 | com.alibaba 51 | druid-spring-boot-starter 52 | 1.1.21 53 | 54 | 55 | 56 | 57 | 58 | org.projectlombok 59 | lombok 60 | true 61 | 62 | 63 | com.alibaba 64 | fastjson 65 | 1.2.62 66 | 67 | 68 | 69 | 70 | 71 | 72 | org.springframework.boot 73 | spring-boot-maven-plugin 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /elasticsearch-environment/src/main/java/com/ktz/deploy/elasticsearch/ElasticsearchEnvironmentApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.elasticsearch; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @MapperScan("com.ktz.deploy.elasticsearch.mapper*") 8 | @SpringBootApplication 9 | public class ElasticsearchEnvironmentApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ElasticsearchEnvironmentApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /elasticsearch-environment/src/main/java/com/ktz/deploy/elasticsearch/controller/CreateIndexController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.elasticsearch.controller; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.frameworkset.elasticsearch.boot.BBossESStarter; 5 | import org.frameworkset.elasticsearch.client.ClientInterface; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | /** 12 | * ClassName: GoodsInfoDocument 13 | * Description: 索引创建 14 | * date: 2020/3/8 19:45 15 | * 16 | * @author kaituozhe_sh 17 | */ 18 | @RestController 19 | @RequestMapping("/create") 20 | @Slf4j 21 | public class CreateIndexController { 22 | 23 | @Autowired 24 | private BBossESStarter bbossESStarter; 25 | 26 | /** 27 | * 创建商品索引 28 | * 29 | * @return 30 | */ 31 | @GetMapping("/goods_info_index") 32 | public String createGoodsInfoIndex() { 33 | ClientInterface clientUtil = bbossESStarter.getConfigRestClient("esmapper/GoodsInfo.xml"); 34 | boolean exist = clientUtil.existIndice("goods_info"); 35 | if (exist) { 36 | clientUtil.dropIndice("goods_info"); 37 | } 38 | String indiceMapping = clientUtil.createIndiceMapping("goods_info", "createGoodsInfoIndex"); 39 | log.info("创建商品索引 message:" + indiceMapping); 40 | return "success"; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /elasticsearch-environment/src/main/java/com/ktz/deploy/elasticsearch/controller/DataController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.elasticsearch.controller; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; 5 | import com.ktz.deploy.elasticsearch.documents.GoodsInfoDocument; 6 | import com.ktz.deploy.elasticsearch.entity.GoodsInfo; 7 | import com.ktz.deploy.elasticsearch.mapper.GoodsInfoMapper; 8 | import org.frameworkset.elasticsearch.ElasticSearchHelper; 9 | import org.frameworkset.elasticsearch.boot.BBossESStarter; 10 | import org.frameworkset.elasticsearch.client.ClientInterface; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.GetMapping; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import java.util.List; 17 | 18 | /** 19 | * ClassName: DataController 20 | * Description: 数据导入 21 | * date: 2020/3/8 19:56 22 | * 23 | * @author kaituozhe_sh 24 | */ 25 | @RestController 26 | @RequestMapping("/data") 27 | public class DataController { 28 | 29 | @Autowired 30 | private GoodsInfoMapper goodsInfoMapper; 31 | 32 | @Autowired 33 | private BBossESStarter bBossESStarter; 34 | 35 | @GetMapping("/goods_info_import") 36 | public String importGoodsInfoData() { 37 | List goodsInfos = goodsInfoMapper.selectList(Wrappers.lambdaQuery()); 38 | List goodsInfoDocuments = JSON.parseArray(JSON.toJSONString(goodsInfos), GoodsInfoDocument.class); 39 | ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil(); 40 | clearIndexSearchData("goods_info"); 41 | clientUtil.addDocuments("goods_info", goodsInfoDocuments); 42 | return "success"; 43 | } 44 | 45 | private boolean clearIndexSearchData(String indexName) { 46 | ClientInterface client = bBossESStarter.getConfigRestClient("esmapper/GoodsInfo.xml"); 47 | String indexData = client.deleteByQuery(indexName + "/_delete_by_query", "deleteIndexData"); 48 | System.out.println("清空" + indexName + "数据:" + indexData); 49 | return true; 50 | } 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /elasticsearch-environment/src/main/java/com/ktz/deploy/elasticsearch/controller/SearchController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.elasticsearch.controller; 2 | 3 | import com.ktz.deploy.elasticsearch.documents.GoodsInfoDocument; 4 | import com.ktz.deploy.elasticsearch.dto.SearchDto; 5 | import org.frameworkset.elasticsearch.boot.BBossESStarter; 6 | import org.frameworkset.elasticsearch.client.ClientInterface; 7 | import org.frameworkset.elasticsearch.entity.ESDatas; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | /** 14 | * ClassName: SearchController 15 | * Description: 搜索 16 | * date: 2020/3/8 19:57 17 | * 18 | * @author kaituozhe_sh 19 | */ 20 | @RestController 21 | @RequestMapping("/query") 22 | public class SearchController { 23 | 24 | @Autowired 25 | private BBossESStarter bBossESStarter; 26 | 27 | @GetMapping("/search_goods") 28 | public Object search(SearchDto search) { 29 | System.out.println(search); 30 | ClientInterface client = bBossESStarter.getConfigRestClient("esmapper/GoodsInfo.xml"); 31 | ESDatas searchList = client.searchList("goods_info/_search", "GoodsSearch", search, GoodsInfoDocument.class); 32 | return searchList.getDatas(); 33 | } 34 | 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /elasticsearch-environment/src/main/java/com/ktz/deploy/elasticsearch/documents/GoodsInfoDocument.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.elasticsearch.documents; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableName; 4 | import com.frameworkset.orm.annotation.ESId; 5 | import lombok.Data; 6 | import org.frameworkset.elasticsearch.entity.ESBaseData; 7 | 8 | import java.io.Serializable; 9 | import java.math.BigDecimal; 10 | 11 | /** 12 | * ClassName: GoodsInfoDocument 13 | * Description: 14 | * date: 2020/3/8 19:40 15 | * 16 | * @author kaituozhe_sh 17 | */ 18 | @Data 19 | @TableName("goods_info") 20 | public class GoodsInfoDocument extends ESBaseData implements Serializable { 21 | 22 | private static final long serialVersionUID = 1L; 23 | @ESId 24 | private String infoId; 25 | // 商品唯一号 26 | private String goodsSn; 27 | // 分类ID 28 | private Long categoryId; 29 | // 一级分类ID 30 | private Long cateParentId; 31 | // 分类名称 32 | private String categoryName; 33 | // 品牌ID 34 | private Long brandId; 35 | // 品牌名称 36 | private String brandName; 37 | // 系列ID 38 | private Long seriesId; 39 | // 系列名称 40 | private String seriesName; 41 | // 商品名称 42 | private String goodsName; 43 | // SPU编号 44 | private String goodsCode; 45 | // 所属国家 46 | private String areaCode; 47 | // 产品图片 48 | private String showPics; 49 | // 上架状态 0->下架;1->上架;2-预上架 50 | private Integer publishStatus; 51 | // 新品状态 1-精品,2-新品,3-热销,12,23,13,123 52 | private String newStatus; 53 | // 中文显示 54 | private String newStatusStr; 55 | // 推荐状态;0->不推荐;1->推荐 56 | private Integer recommandStatus; 57 | // 市场价 58 | private String price; 59 | // 最低价 60 | private BigDecimal minPrice; 61 | // 本店价 62 | private String localPrice; 63 | // 副标题 64 | private String subTitle; 65 | // 商品描述 66 | private String description; 67 | // 关键词 68 | private String keywords; 69 | // 供应商ID 70 | private Long supplyId; 71 | // 排序 72 | private Integer sortOrder; 73 | // 删除状态:0->未删除;1->已删除 74 | private Integer disabled; 75 | 76 | public void setPrice(String price) { 77 | if (price.indexOf("-") != -1) { 78 | this.setMinPrice(new BigDecimal(price.substring(0, price.indexOf("-")))); 79 | } else { 80 | this.setMinPrice(new BigDecimal(price)); 81 | } 82 | this.price = price; 83 | } 84 | } 85 | 86 | -------------------------------------------------------------------------------- /elasticsearch-environment/src/main/java/com/ktz/deploy/elasticsearch/dto/SearchDto.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.elasticsearch.dto; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * ClassName: SearchDto 7 | * Description: 8 | * date: 2020/3/8 21:15 9 | * 10 | * @author kaituozhe_sh 11 | */ 12 | @Data 13 | public class SearchDto { 14 | private Long categoryId; 15 | private Long brandId; 16 | private Long seriesId; 17 | private String newStatus; 18 | } 19 | -------------------------------------------------------------------------------- /elasticsearch-environment/src/main/java/com/ktz/deploy/elasticsearch/entity/GoodsInfo.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.elasticsearch.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import lombok.Data; 8 | 9 | import java.io.Serializable; 10 | 11 | @Data 12 | @TableName("goods_info") 13 | public class GoodsInfo implements Serializable { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | @TableId(value = "id", type = IdType.AUTO) 18 | private Long id; 19 | 20 | @TableField("goods_sn") 21 | private String goodsSn; 22 | 23 | @TableField("category_id") 24 | private Long categoryId; 25 | 26 | @TableField("category_name") 27 | private String categoryName; 28 | 29 | @TableField("brand_id") 30 | private Long brandId; 31 | 32 | @TableField("brand_name") 33 | private String brandName; 34 | 35 | @TableField("series_id") 36 | private Long seriesId; 37 | 38 | @TableField("series_name") 39 | private String seriesName; 40 | 41 | @TableField("goods_name") 42 | private String goodsName; 43 | 44 | 45 | @TableField("new_status") 46 | private String newStatus; 47 | 48 | @TableField("price") 49 | private String price; 50 | 51 | @TableField("sort_order") 52 | private Integer sortOrder; 53 | 54 | 55 | 56 | } -------------------------------------------------------------------------------- /elasticsearch-environment/src/main/java/com/ktz/deploy/elasticsearch/mapper/GoodsInfoMapper.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.elasticsearch.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.ktz.deploy.elasticsearch.entity.GoodsInfo; 5 | 6 | /** 7 | * Description: 8 | * date: 2020/3/8 20:48 9 | * 10 | * @author kaituozhe_sh 11 | */ 12 | public interface GoodsInfoMapper extends BaseMapper { 13 | } 14 | -------------------------------------------------------------------------------- /elasticsearch-environment/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | elasticsearch: 3 | bboss: 4 | elasticsearch: 5 | rest: 6 | hostNames: 127.0.0.1:9200 # es服务ip:端口 集群用逗号隔开 如果是https协议 https://ip+端口 多个逗号隔开 7 | sliceScrollThreadCount: 100 # slice scroll 查询线程数 8 | sliceScrollThreadQueue: 100 # slice scroll 查询等待队列数 9 | sliceScrollBlockedWaitTimeout: 0 #单位毫秒 10 | # 访问容器环境/云环境或者其他通过代理转发环境中部署的Elasticsearch时,请关闭:elasticsearch.discoverHost=false 11 | discoverHost: false # 集群节点自动发现discover控制开关 如果开启discover机制,客户端就会具备自动发现新增的ES集群节点的能力,elasticsearch.rest.hostNames中就可以只配置初始的几个节点,不需要配置全部节点。 12 | showTemplate: true # DSL脚本调试日志开关,将showTemplate设置为true,同时将日志级别设置为INFO,则会将query dsl脚本输出到日志文件中: 13 | includeTypeName: true # 向下兼容 14 | slowDslThreshold: 1000 # 定义慢dsl耗时阈值,执行时间长超过指定阈值的dsl为慢dsl,必须指定大于0的数值 15 | slowDslCallback: com.ktz.deploy.elasticsearch #如果没有指定回调处理接口,将直接打印警告信息到日志文件,WARN级别 , 如果dsl过长,需要截取掉部分内容再打印到日志文件中:超过2048的dsl将被截取掉超过的内容,替换为.....,否则调用SlowDslCallback接口方法slowDslHandle传递慢dsl的相关信息 16 | http: 17 | maxTotal: 600 # 最大连接数 18 | defaultMaxPerRoute: 200 # 每个地址允许的最大连接数 19 | retryTime: 3 # 连接失败重试次数 20 | timeoutConnection: 10000 # 建立连接超时时间 21 | timeoutSocket: 50000 # socket通讯超时时间,如果在通讯过程中出现sockertimeout异常,可以适当调整timeoutSocket参数值,单位:毫秒 22 | connectionRequestTimeout: 10000 # 申请连接超时时间,设置为0不超时 23 | dslfile: 24 | refreshInterval: -1 # dsl配置文件热加载扫描时间间隔,毫秒为单位,默认5秒扫描一次,<= 0时关闭扫描机制 25 | rest: 26 | uris: localhost:9200 27 | 28 | datasource: 29 | type: com.alibaba.druid.pool.DruidDataSource 30 | username: root 31 | password: root 32 | driver-class-name: com.mysql.cj.jdbc.Driver 33 | url: jdbc:mysql://localhost:3306/deploy?characterEncoding=utf8&useUnicode=true&useSSL=false&useTimezone=true&serverTimezone=GMT%2B8 34 | druid: 35 | initial-size: 5 # 初始化时建立物理连接的个数。初始化发生在显示调用init方法,或者第一次getConnection时 36 | max-active: 10 # 连接池中最多支持多少个活动会话 37 | min-idle: 1 # 最小空闲连接,回收空闲连接时,将保证至少有min-idle个连接 38 | max-wait: 60000 # 程序向连接池中请求连接超时,超过max-wait的值后,认为本次请求失败,即连接池没有可用连接,单位毫秒,设置-1时表示无限等待 39 | # 获取连接时最大等待时间,单位毫秒。配置max-wait之后,默认启用公平锁,并发效率会有所下降,如果需要可以通过配置useUnfairLock属性为true使用费公平锁 40 | pool-prepared-statements: true # 是否缓存preparedStatement,也就是PSCache。PSCache对支持游标的数据库性能提升巨大,比如说oracle。在mysql下建议关闭 41 | validation-query: SELECT 1 FROM DUAL # 检查池中的连接是否仍可用的SQL语句,druid会连接到数据库执行该SQL,如果正常返回,则表示连接可用,否则表示连接不可用 42 | validation-query-timeout: 10000 # 单位:秒,检测连接是否有效的超时时间。底层调用jdbdStatement对象的void setQueryTimeout(int seconds)方法 43 | test-on-borrow: true # 程序 申请 连接时,进行连接有效性检查(低效,影响性能) 44 | test-on-return: false # 程序 返还 连接时,进行连接有效性检查(低效,影响性能) 45 | test-while-idle: true # 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于time-between-eviction-runs-millis,执行validation-query检测连接是否有效 46 | time-between-eviction-runs-millis: 60000 # 有两个含义: 47 | # Destroy现场会检测连接的间隔时间,如果连接空闲时间大于等于min-evictable-idle-time-millis则关闭物理连接 48 | # test-while-idle的判断依据 49 | min-evictable-idle-time-millis: 30000 # 池中某个连接的空闲时长达到N毫秒后,连接池在下次检查空闲连接时,将回收该连接,要小于防火墙超时设置 50 | filters: stat # stat:监控统计 log4j/slf4j:日志监控 wall:防御SQL注入 51 | 52 | mybatis-plus: 53 | mapper-locations: classpath:/mapper/*Mapper.xml 54 | type-aliases-package: com.ktz.deploy.elasticsearch.entity 55 | global-config: 56 | db-config: 57 | id-type: AUTO 58 | logic-delete-value: 1 59 | logic-not-delete-value: 0 60 | configuration: 61 | map-underscore-to-camel-case: true 62 | cache-enabled: false 63 | -------------------------------------------------------------------------------- /elasticsearch-environment/src/main/resources/esmapper/GoodsInfo.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 36 | 37 | 38 | 39 | 40 | 41 | 73 | 74 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /elasticsearch-environment/src/main/resources/mapper/GoodsInfoMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /feign-environment/feign-caller-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | feign-environment 7 | com.ktz.deploy 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | feign-caller-service 13 | 14 | 15 | -------------------------------------------------------------------------------- /feign-environment/feign-caller-service/src/main/java/com/ktz/deploy/feign/service/feign/MessageFeignService.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.feign.service.feign; 2 | 3 | import com.ktz.deploy.feign.service.feign.fallback.MessageFeignFallback; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | 8 | /** 9 | * ClassName: MessageFeignService 10 | * Description: 11 | * date: 2020/3/8 21:52 12 | * 13 | * @author kaituozhe_sh 14 | */ 15 | @FeignClient(value = "localhost:8888/feign/provider", fallback = MessageFeignFallback.class) 16 | public interface MessageFeignService { 17 | 18 | @GetMapping("/service/member/info") 19 | String showMemberInfo(@RequestParam("memberId") String memberId); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /feign-environment/feign-caller-service/src/main/java/com/ktz/deploy/feign/service/feign/fallback/MessageFeignFallback.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.feign.service.feign.fallback; 2 | 3 | import com.ktz.deploy.feign.service.feign.MessageFeignService; 4 | import org.springframework.stereotype.Component; 5 | 6 | /** 7 | * ClassName: MessageFeignFallback 8 | * Description: 9 | * date: 2020/3/8 21:52 10 | * 11 | * @author kaituozhe_sh 12 | */ 13 | @Component 14 | public class MessageFeignFallback implements MessageFeignService { 15 | @Override 16 | public String showMemberInfo(String memberId) { 17 | return null; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /feign-environment/feign-caller/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | feign-environment 7 | com.ktz.deploy 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | feign-caller 13 | 14 | 15 | 16 | 17 | com.ktz.deploy 18 | feign-caller-service 19 | 1.0-SNAPSHOT 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-web 24 | 25 | 26 | -------------------------------------------------------------------------------- /feign-environment/feign-caller/src/main/java/com/ktz/deploy/feign/FeignCallerApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.feign; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | /** 8 | * ClassName: FeignApplication 9 | * Description: 10 | * date: 2020/3/8 21:55 11 | * 12 | * @author kaituozhe_sh 13 | */ 14 | @EnableFeignClients(basePackages = {"com.ktz.deploy.feign.service.feign"}) 15 | @SpringBootApplication 16 | public class FeignCallerApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(FeignCallerApplication.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /feign-environment/feign-caller/src/main/java/com/ktz/deploy/feign/controller/MemberController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.feign.controller; 2 | 3 | import com.ktz.deploy.feign.service.feign.MessageFeignService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * ClassName: MemberController 11 | * Description: 12 | * date: 2020/3/8 21:57 13 | * 14 | * @author kaituozhe_sh 15 | */ 16 | @RestController 17 | public class MemberController { 18 | 19 | @Autowired 20 | private MessageFeignService messageFeignService; 21 | 22 | @GetMapping("/show/info") 23 | public String showMember(@RequestParam String memberId) { 24 | return messageFeignService.showMemberInfo(memberId); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /feign-environment/feign-caller/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | feign: 2 | httpclient: 3 | enabled: true 4 | connection-timeout: 20000 5 | max-connections: 200 6 | max-connections-per-route: 100 7 | time-to-live-unit: seconds 8 | time-to-live: 20 9 | server: 10 | port: 7777 -------------------------------------------------------------------------------- /feign-environment/feign-provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | feign-environment 7 | com.ktz.deploy 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | feign-provider 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-web 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /feign-environment/feign-provider/src/main/java/com/ktz/deploy/feign/FeignProviderApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.feign; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * ClassName: FeignApplication 8 | * Description: 9 | * date: 2020/3/8 21:48 10 | * 11 | * @author kaituozhe_sh 12 | */ 13 | @SpringBootApplication 14 | public class FeignProviderApplication { 15 | public static void main(String[] args) { 16 | SpringApplication.run(FeignProviderApplication.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /feign-environment/feign-provider/src/main/java/com/ktz/deploy/feign/api/MemberApi.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.feign.api; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * ClassName: MemberApi 10 | * Description: 11 | * date: 2020/3/8 21:49 12 | * 13 | * @author kaituozhe_sh 14 | */ 15 | @RestController 16 | @RequestMapping("/service") 17 | public class MemberApi { 18 | 19 | @GetMapping("/member/info") 20 | public String showMemberInfo(@RequestParam("memberId") String memberId) { 21 | switch (memberId) { 22 | case "1": 23 | System.out.println("获取1号用户信息"); 24 | break; 25 | case "2": 26 | System.out.println("获取2号用户信息"); 27 | break; 28 | default: 29 | return "error"; 30 | } 31 | return "success"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /feign-environment/feign-provider/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8888 3 | servlet: 4 | context-path: /feign/provider -------------------------------------------------------------------------------- /feign-environment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | feign-provider 8 | feign-caller-service 9 | feign-caller 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 2.2.5.RELEASE 15 | 16 | 17 | com.ktz.deploy 18 | feign-environment 19 | pom 20 | 1.0-SNAPSHOT 21 | 22 | 23 | 24 | 25 | org.springframework.cloud 26 | spring-cloud-starter-openfeign 27 | 2.1.0.RELEASE 28 | 29 | 30 | io.github.openfeign 31 | feign-httpclient 32 | 10.6.0 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-maven-plugin 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /global-exception-environment/src/main/java/com/ktz/deploy/controller/TestController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.controller; 2 | 3 | import com.ktz.deploy.exception.GlobalException; 4 | import com.ktz.deploy.response.ResponseData; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * @ClassName TestController 11 | * @Description 12 | * @Author 开拓者-骚豪 13 | * @Date 2020/8/11 10:00 14 | * @Version V1.0.0 15 | **/ 16 | @RestController 17 | public class TestController { 18 | 19 | @RequestMapping("/test1/{id}") 20 | public ResponseData test1(@PathVariable Integer id) { 21 | if (id == 1) { 22 | throw new GlobalException("test1"); 23 | } 24 | return ResponseData.ok(); 25 | } 26 | 27 | @RequestMapping("/test2") 28 | public ResponseData test2() { 29 | 30 | Integer.parseInt("abc123"); 31 | 32 | return ResponseData.ok(); 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /global-exception-environment/src/main/java/com/ktz/deploy/exception/GlobalException.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.exception; 2 | 3 | /** 4 | * @ClassName GlobalException 5 | * @Description 自定义全局异常 6 | * @Author 开拓者-骚豪 7 | * @Date 2020/8/11 9:44 8 | * @Version V1.0.0 9 | **/ 10 | public class GlobalException extends RuntimeException { 11 | 12 | 13 | private static final long serialVersionUID = -5022432367686363731L; 14 | 15 | private int code; 16 | 17 | public int getCode() { 18 | return code; 19 | } 20 | 21 | public void setCode(int code) { 22 | this.code = code; 23 | } 24 | 25 | public GlobalException(GlobalException e) { 26 | super(e.getMessage()); 27 | this.code = e.getCode(); 28 | } 29 | 30 | public GlobalException(String message) { 31 | super(message); 32 | } 33 | 34 | public GlobalException(String message, int code) { 35 | super(message); 36 | this.code = code; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /global-exception-environment/src/main/java/com/ktz/deploy/exception/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.exception; 2 | 3 | import com.ktz.deploy.response.ResponseCode; 4 | import com.ktz.deploy.response.ResponseData; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.web.bind.annotation.ControllerAdvice; 7 | import org.springframework.web.bind.annotation.ExceptionHandler; 8 | import org.springframework.web.bind.annotation.ResponseBody; 9 | 10 | import javax.servlet.http.HttpServletRequest; 11 | 12 | /** 13 | * @ClassName GlobalExceptionHandler 14 | * @Description 15 | * @Author kaituozhesh 16 | * @Date 2020/8/11 9:49 17 | * @Version V1.0.0 18 | **/ 19 | @Slf4j 20 | @ControllerAdvice 21 | public class GlobalExceptionHandler { 22 | 23 | @ExceptionHandler(value = GlobalException.class) 24 | @ResponseBody 25 | public ResponseData jsonErrorHandler(HttpServletRequest request, GlobalException e) throws Exception { 26 | log.error("", e); 27 | ResponseData response = new ResponseData(); 28 | response.setMessage(e.getMessage()); 29 | response.setCode(e.getCode()); 30 | response.setData(null); 31 | return response; 32 | } 33 | 34 | 35 | @ExceptionHandler(value = Exception.class) 36 | @ResponseBody 37 | public ResponseData defaultErrorHandler(HttpServletRequest request, Exception e) { 38 | log.error("", e); 39 | ResponseData response = new ResponseData(); 40 | if (e instanceof org.springframework.web.servlet.NoHandlerFoundException) { 41 | response.setCode(ResponseCode.NOT_FOUND.getCode()); 42 | response.setMessage(e.getMessage()); 43 | } else { 44 | response.setCode(ResponseCode.SERVER_ERROR.getCode()); 45 | response.setMessage(ResponseCode.SERVER_ERROR.getMsg()); 46 | } 47 | response.setData(null); 48 | return response; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /global-exception-environment/src/main/java/com/ktz/deploy/response/ResponseCode.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.response; 2 | 3 | public enum ResponseCode { 4 | 5 | /** 正确 **/ 6 | SUCCESS(200, "SUCCESS"), 7 | /** 参数错误 **/ 8 | PARAM_ERROR(400, "PARAMS ERROR"), 9 | /** 限制调用 **/ 10 | LIMIT_ERROR(401, "RESOURCE LIMITED"), 11 | /** Token过期 **/ 12 | TOKEN_TIMEOUT(402, "TOKEN INVALID"), 13 | /** 禁止访问 **/ 14 | NO_AUTH(403, "RESOURCE FORBIDDEN"), 15 | /** 资源没找到 **/ 16 | NOT_FOUND(404, "RESOURCE NOT FOUND"), 17 | /** 服务器错误 **/ 18 | SERVER_ERROR(500, "SERVER ERROR"), 19 | /** 服务降级中 **/ 20 | DOWNGRADE(406, "SERVICE DOWNGRADE"), 21 | /** 自定义错误 **/ 22 | CUSTOM_ERROR(999, "CUSTOM ERROR"), 23 | /** 刷新Token **/ 24 | TOKEN_REFRESH(888, "TOKEN REFRESH"); 25 | 26 | private int code; 27 | 28 | private String msg; 29 | 30 | public String getMsg() { 31 | return msg; 32 | } 33 | 34 | public int getCode() { 35 | return code; 36 | } 37 | 38 | private ResponseCode(int code, String msg) { 39 | this.msg = msg; 40 | this.code = code; 41 | } 42 | 43 | public void setMsg(String msg) { 44 | this.msg = msg; 45 | } 46 | 47 | public void setCode(int code) { 48 | this.code = code; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /global-exception-environment/src/main/java/com/ktz/deploy/response/ResponseData.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.response; 2 | 3 | public class ResponseData { 4 | 5 | private int code; 6 | 7 | private String message; 8 | 9 | private Object data; 10 | 11 | public static ResponseData ok() { 12 | return new ResponseData(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMsg()); 13 | } 14 | 15 | public static ResponseData ok(String message) { 16 | return new ResponseData(ResponseCode.SUCCESS.getCode(), message); 17 | } 18 | 19 | public static ResponseData ok(Object data) { 20 | return new ResponseData(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMsg(), data); 21 | } 22 | 23 | public static ResponseData fail(ResponseCode responseCode) { 24 | return new ResponseData(responseCode.getCode(), responseCode.getMsg()); 25 | } 26 | 27 | public static ResponseData fail(ResponseCode responseCode, String message) { 28 | return new ResponseData(responseCode.getCode(), message); 29 | } 30 | 31 | public static ResponseData fail(ResponseCode responseCode, Object data) { 32 | return new ResponseData(responseCode.getCode(), responseCode.getMsg(), data); 33 | } 34 | 35 | public ResponseData(int code, String message) { 36 | this.message = message; 37 | this.code = code; 38 | this.data = null; 39 | } 40 | 41 | public ResponseData(int code, String message, Object data) { 42 | this.message = message; 43 | this.code = code; 44 | this.data = data; 45 | } 46 | 47 | public ResponseData() { 48 | } 49 | 50 | public int getCode() { 51 | return code; 52 | } 53 | public void setCode(int code) { 54 | this.code = code; 55 | } 56 | public String getMessage() { 57 | return message; 58 | } 59 | public void setMessage(String message) { 60 | this.message = message; 61 | } 62 | public Object getData() { 63 | return data; 64 | } 65 | public void setData(Object data) { 66 | this.data = data; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /hikaricp-environment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.5.RELEASE 9 | 10 | 11 | com.ktz.deploy 12 | hikaricp-environment 13 | 0.0.1-SNAPSHOT 14 | hikaricp-environment 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | 24 | com.zaxxer 25 | HikariCP 26 | ${hikaricp.version} 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-jdbc 31 | 32 | 33 | 34 | org.apache.tomcat 35 | tomcat-jdbc 36 | 37 | 38 | 39 | 40 | 41 | mysql 42 | mysql-connector-java 43 | ${mysql.version} 44 | 45 | 46 | 47 | com.baomidou 48 | mybatis-plus-boot-starter 49 | 3.1.2 50 | 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-starter-web 56 | 57 | 58 | 59 | 60 | 61 | 62 | org.springframework.boot 63 | spring-boot-maven-plugin 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /hikaricp-environment/src/main/java/com/ktz/deploy/hikaricp/HikaricpEnvironmentApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.hikaricp; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * Description: 8 | * 9 | * @author kaituozhe_sh 10 | */ 11 | @SpringBootApplication 12 | public class HikaricpEnvironmentApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(HikaricpEnvironmentApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /hikaricp-environment/src/main/java/com/ktz/deploy/hikaricp/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.hikaricp.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * ClassName: User 7 | * Description: 8 | * date: 2020/3/8 10:44 9 | * 10 | * @author kaituozhe_sh 11 | */ 12 | public class User implements Serializable { 13 | } 14 | -------------------------------------------------------------------------------- /hikaricp-environment/src/main/java/com/ktz/deploy/hikaricp/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.hikaricp.mapper; 2 | 3 | /** 4 | * Description: 5 | * date: 2020/3/8 10:45 6 | * 7 | * @author kaituozhe_sh 8 | */ 9 | public interface UserMapper { 10 | } 11 | -------------------------------------------------------------------------------- /hikaricp-environment/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | type: com.zaxxer.hikari.HikariDataSource 4 | driver-class-name: com.mysql.cj.jdbc.Driver 5 | url: jdbc:mysql://localhost:3306/problem?characterEncoding=utf8&useUnicode=true&useSSL=false&useTimezone=true&serverTimezone=GMT%2B8 6 | username: root 7 | password: root 8 | hikari: 9 | minimum-idle: 5 # 最小空闲连接数 10 | idle-timeout: 600000 # 空闲连接存货最大时间,默认600000(10分钟) 11 | maximum-pool-size: 10 # 连接池最大连接数 12 | auto-commit: true # 控制从池返回的连接的默认自动提交行为,默认值:tree 13 | pool-name: MyHikariCP # 连接池名字 14 | max-lifetime: 1800000 # 控制池中连接的最长生命周期,值0表示无线生命周期,默认1800000即30分钟 15 | connection-timeout: 30000 # 数据库连接超时时间,默认30秒 30000,如果在没有可用连接的情况下超过此时间,则会抛出SQLException。最低可接收的连接超时时间为250ms 16 | connection-test-query: SELECT 1 17 | mybatis-plus: 18 | mapper-locations: classpath:/mapper/*Mapper.xml 19 | type-aliases-package: com.ktz.deploy.hikaricp.entity 20 | global-config: 21 | db-config: 22 | id-type: AUTO 23 | logic-delete-value: 1 24 | logic-not-delete-value: 0 25 | configuration: 26 | map-underscore-to-camel-case: true 27 | cache-enabled: false 28 | -------------------------------------------------------------------------------- /hikaricp-environment/src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /jdbc-environment/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | .mvn/wrapper/ 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea/ 18 | *.iws 19 | *.iml 20 | *.ipr 21 | /target 22 | 23 | ### NetBeans ### 24 | /nbproject/private/ 25 | /nbbuild/ 26 | /dist/ 27 | /nbdist/ 28 | /.nb-gradle/ 29 | build/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | -------------------------------------------------------------------------------- /jdbc-environment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.5.RELEASE 9 | 10 | 11 | com.ktz.deploy 12 | jdbc-environment 13 | 0.0.1-SNAPSHOT 14 | jdbc-environment 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-data-jdbc 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | 32 | mysql 33 | mysql-connector-java 34 | runtime 35 | 36 | 37 | com.alibaba 38 | druid-spring-boot-starter 39 | 1.1.21 40 | 41 | 42 | com.baomidou 43 | mybatis-plus-boot-starter 44 | 3.1.2 45 | 46 | 47 | org.projectlombok 48 | lombok 49 | true 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /jdbc-environment/src/main/java/com/ktz/deploy/jdbc/JdbcEnvironmentApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.jdbc; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class JdbcEnvironmentApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(JdbcEnvironmentApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /jdbc-environment/src/main/java/com/ktz/deploy/jdbc/config/DataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.jdbc.config; 2 | 3 | import org.apache.ibatis.session.SqlSessionFactory; 4 | import org.mybatis.spring.SqlSessionFactoryBean; 5 | import org.springframework.beans.factory.annotation.Qualifier; 6 | import org.springframework.boot.context.properties.ConfigurationProperties; 7 | import org.springframework.boot.jdbc.DataSourceBuilder; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.context.annotation.Primary; 11 | import org.springframework.jdbc.core.JdbcTemplate; 12 | 13 | import javax.sql.DataSource; 14 | 15 | /** 16 | * @ClassName JdbcConfig 17 | * @Description 18 | * @Author kaituozhesh 19 | * @Date 2020/3/26 16:56 20 | * @Version V1.0 21 | **/ 22 | @Configuration 23 | public class DataSourceConfig { 24 | @Bean(name = "primaryDataSource") 25 | @Qualifier("primaryDataSource") 26 | @Primary 27 | @ConfigurationProperties(prefix = "spring.datasource.primary") 28 | public DataSource primaryDataSource() { 29 | return DataSourceBuilder.create().build(); 30 | } 31 | 32 | @Bean(name = "secondaryDataSource") 33 | @Qualifier("secondaryDataSource") 34 | @ConfigurationProperties(prefix = "spring.datasource.secondary") 35 | public DataSource secondaryDataSource() { 36 | return DataSourceBuilder.create().build(); 37 | } 38 | 39 | @Bean(name = "primaryJdbcTemplate") 40 | public JdbcTemplate primaryJdbcTemplate( 41 | @Qualifier("primaryDataSource") DataSource dataSource) { 42 | return new JdbcTemplate(dataSource); 43 | } 44 | 45 | @Bean(name = "secondaryJdbcTemplate") 46 | public JdbcTemplate secondaryJdbcTemplate( 47 | @Qualifier("secondaryDataSource") DataSource dataSource) { 48 | return new JdbcTemplate(dataSource); 49 | } 50 | 51 | 52 | @Bean 53 | public SqlSessionFactory sqlSessionFactory(@Qualifier("primaryDataSource") DataSource dataSource) throws Exception { 54 | SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean(); 55 | sessionFactoryBean.setDataSource(dataSource); 56 | 57 | return sessionFactoryBean.getObject(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /jdbc-environment/src/main/java/com/ktz/deploy/jdbc/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.jdbc.controller; 2 | 3 | import com.ktz.deploy.jdbc.entity.dto.DepartDataDto; 4 | import com.ktz.deploy.jdbc.service.IndexService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * @ClassName IndexController 15 | * @Description 部门数据 首页表格块统计信息 16 | * @Author kaituozhesh 17 | * @Date 2020/3/26 9:47 18 | * @Version V1.0 19 | **/ 20 | @RestController 21 | @RequestMapping("/department_data") 22 | public class IndexController { 23 | 24 | @Autowired 25 | private IndexService indexService; 26 | 27 | /** 28 | * 部门数据表格块统计数据 29 | * 30 | * @return 31 | */ 32 | @PostMapping("/index_block_list") 33 | public List blockList() { 34 | return indexService.collectData(); 35 | } 36 | 37 | /** 38 | * 查询市场监管局下的菜单列表 39 | * 40 | * @return 41 | */ 42 | @PostMapping("/menu_list/{id}") 43 | public List menuList(@PathVariable("id") String id) { 44 | return indexService.tableList(id); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /jdbc-environment/src/main/java/com/ktz/deploy/jdbc/controller/MarketSuperviseController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.jdbc.controller; 2 | 3 | import com.ktz.deploy.jdbc.entity.dto.MarketSuperviseParam; 4 | import com.ktz.deploy.jdbc.entity.dto.ProvTable; 5 | import com.ktz.deploy.jdbc.service.DepartmentDataService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | /** 13 | * @ClassName MarketSuperviseController 14 | * @Description 市市场监管局 15 | * @Author kaituozhesh 16 | * @Date 2020/3/26 8:51 17 | * @Version V1.0 18 | **/ 19 | @RestController 20 | @RequestMapping("/market_supervise") 21 | public class MarketSuperviseController { 22 | 23 | @Autowired 24 | private DepartmentDataService departmentDataService; 25 | 26 | /** 27 | * 查询列表信息 統一接口 28 | * 根据table 列 ID来决定查询的表 29 | * 30 | * @param marketSuperviseParam 31 | * @return 32 | */ 33 | @PostMapping("/find_market_list") 34 | public ProvTable findMarketSuperviseList(@RequestBody MarketSuperviseParam marketSuperviseParam) { 35 | return departmentDataService.getList(marketSuperviseParam); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /jdbc-environment/src/main/java/com/ktz/deploy/jdbc/entity/dto/AbsDepartmetData.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.jdbc.entity.dto; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @ClassName AbsDepartmetData 7 | * @Description 8 | * @Author kaituozhesh 9 | * @Date 2020/3/26 14:22 10 | * @Version V1.0 11 | **/ 12 | @Data 13 | public abstract class AbsDepartmetData { 14 | /** 15 | * 分页的起始位置 16 | */ 17 | private int startRow = 0; 18 | /** 19 | * 起始页 默认配置是合理化的。pageNum -1,0,1其实都指向第一页。从2开始指向对应页 20 | */ 21 | private int pageNum = 0; 22 | /** 23 | * 单页上限,如果为0,则查询全部 24 | */ 25 | private int pageSize = 0; 26 | /** 27 | * 列对应ID 28 | */ 29 | private String marketId; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /jdbc-environment/src/main/java/com/ktz/deploy/jdbc/entity/dto/DepartDataDto.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.jdbc.entity.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.io.Serializable; 8 | 9 | /** 10 | * @ClassName DepartDataDto 11 | * @Description 部门首页数据统计DTO 12 | * @Author kaituozhesh 13 | * @Date 2020/3/26 13:05 14 | * @Version V1.0 15 | **/ 16 | @Data 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | public class DepartDataDto implements Serializable { 20 | 21 | /** 22 | * 首页块对应ID 23 | */ 24 | private String id; 25 | 26 | /** 27 | * 块列表对应ID 的对应请求列表url 28 | */ 29 | private String url; 30 | 31 | /** 32 | * 首页块对应的名称 33 | */ 34 | private String name; 35 | 36 | /** 37 | * 首页块对应的数据总量 38 | */ 39 | private Long totalCount; 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /jdbc-environment/src/main/java/com/ktz/deploy/jdbc/entity/dto/MarketSuperviseParam.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.jdbc.entity.dto; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @ClassName MarketSuperviseParam 7 | * @Description 8 | * @Author kaituozhesh 9 | * @Date 2020/3/26 14:46 10 | * @Version V1.0 11 | **/ 12 | public class MarketSuperviseParam extends AbsDepartmetData implements Serializable { 13 | /** 14 | * 机构名称 15 | */ 16 | private String company_name; 17 | 18 | /** 19 | * 统一信用编码 20 | */ 21 | private String credit_code; 22 | } 23 | -------------------------------------------------------------------------------- /jdbc-environment/src/main/java/com/ktz/deploy/jdbc/entity/dto/Page.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.jdbc.entity.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | import java.util.List; 7 | 8 | @Data 9 | public class Page implements Serializable { 10 | 11 | private List list; 12 | private long total; 13 | private int pageNum; 14 | private int pageSize; 15 | 16 | } -------------------------------------------------------------------------------- /jdbc-environment/src/main/java/com/ktz/deploy/jdbc/entity/dto/ProvBase.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.jdbc.entity.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | 7 | @Data 8 | public class ProvBase { 9 | 10 | private Integer id; 11 | 12 | private String tableName; 13 | 14 | private String tableChnname; 15 | 16 | private String fieldName; 17 | 18 | private String fieldChnname; 19 | 20 | private Integer type; 21 | 22 | private Date createTime; 23 | 24 | private Date modifyTime; 25 | 26 | 27 | } -------------------------------------------------------------------------------- /jdbc-environment/src/main/java/com/ktz/deploy/jdbc/entity/dto/ProvTable.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.jdbc.entity.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @ClassName ProvTable 9 | * @Description 10 | * @Author kaituozhesh 11 | * @Date 2020/3/26 14:21 12 | * @Version V1.0 13 | **/ 14 | @Data 15 | public class ProvTable { 16 | private List provBaseList; 17 | private Page page; 18 | 19 | public ProvTable(){ 20 | 21 | } 22 | 23 | public ProvTable( List provBaseList, Page page){ 24 | this.provBaseList = provBaseList; 25 | this.page = page; 26 | } 27 | } -------------------------------------------------------------------------------- /jdbc-environment/src/main/java/com/ktz/deploy/jdbc/enums/DepartEnum.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.jdbc.enums; 2 | 3 | import com.alibaba.druid.util.StringUtils; 4 | 5 | 6 | /** 7 | * @Description 部门数据 首页列表块 8 | * @Author kaituozhesh 9 | * @Date 2020/3/26 13:24 10 | */ 11 | public enum DepartEnum { 12 | ECOLOG_SUPERVISE("1", "市生态环境局", ""), 13 | NATURAL_RESOURCES("2", "市自然资源规划局", ""), 14 | BANK_SUPERVISE("3", "宁波银保监局", ""), 15 | CIVIL_AFFAIRS_BUREAU("4", "市民政局", ""), 16 | CUSTOMS_SUPERVISE("5", "宁波海关", ""), 17 | POLICE_SUPERVISE("6", "市公安局", ""), 18 | COURT_SUPERVISE("7", "市中级法院", ""), 19 | PEOPLE_BANK_SUPERVISE("8", "人行市中心支行", ""), 20 | PEOPLE_SOCIAL_SUPERVISE("9", "市人力社保局", ""), 21 | REVENUE("10", "宁波市税务局", ""), 22 | WEALTH_TAX("11", "市财税局", ""), 23 | EMERGENCY_MANAGEMENT("12", "市应急管理局", ""), 24 | FUEL_GAS("13", "市兴光燃气集团", ""), 25 | ABNORMAL_BANK_ACCOUNT("14", "银行账户异动信息", ""), 26 | BUREAU_OF_COMMERCE("15", "市商务局", ""), 27 | TAP_WATER_COMPANY("16", "市自来水公司", ""), 28 | BY_THE_LETTER("17", "市经信局", ""), 29 | ENFORCEMENT("18", "市综合执法局", ""), 30 | PETITION_LETTER("19", "市信访局", ""), 31 | MARKET_SUPERVISE("20", "市市场监管局", "/market_supervise/find_list"), 32 | BUREAU_OF_LAND_RESOURCES("21", "宁波市国土资源局", ""), 33 | HOUSING_CONSTRUCTION_BUREAU("22", "市住建局", ""), 34 | POWER_SUPPLY("23", "国网宁波供电公司", ""), 35 | SECURITIES_REGULATORY("24", "宁波证监局", ""), 36 | ; 37 | 38 | private String id; 39 | private String value; 40 | private String url; 41 | 42 | DepartEnum(String id, String value, String url) { 43 | this.id = id; 44 | this.value = value; 45 | this.url = url; 46 | } 47 | 48 | public String getValue() { 49 | return value; 50 | } 51 | 52 | public String getId() { 53 | return id; 54 | } 55 | 56 | public String getUrl() { 57 | return url; 58 | } 59 | 60 | public static DepartEnum getValue(String value) { 61 | for (DepartEnum departEnum : DepartEnum.values()) { 62 | if (StringUtils.equals(value, departEnum.getValue())) { 63 | return departEnum; 64 | } 65 | } 66 | return null; 67 | } 68 | 69 | public static String getUrl(String id) { 70 | for (DepartEnum departEnum : DepartEnum.values()) { 71 | if (StringUtils.equals(id, departEnum.getId())) { 72 | return departEnum.getUrl(); 73 | } 74 | } 75 | return null; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jdbc-environment/src/main/java/com/ktz/deploy/jdbc/enums/DepartTableEnum.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.jdbc.enums; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * @Description 部门数据 对应表名 8 | * @Author kaituozhesh 9 | * @Date 2020/3/26 9:51 10 | **/ 11 | public enum DepartTableEnum { 12 | 13 | B_AJ_COMPANY("12_01","b_aj_company","市安检局安全生产警示机构信息"), 14 | B_AJ_COMPANY_EVENT("12_02","b_aj_company_event","市安检局重大案件事故信息"), 15 | BB_13("13","","市兴光燃气集团"), 16 | B_R_COMPANY_ACCOUNT("14_01","b_rh_company_account","机构账号异动信息"), 17 | B_R_PEOPLE_ACCOUNT("14_02","b_rh_people_account","个人账号信息异动"), 18 | B_SW_COMPANY_DECISION("15_01","b_sw_company_decision","机构处罚信息"), 19 | B_JG_COMPANY_DECISION("20_01", "b_jg_company_decision", "机构处罚信息"), 20 | B_JG_COMPANY_SHAREHOLDER("20_02", "b_jg_company_shareholder", "企业股东信息"), 21 | B_03("20_03", "", "主要经营者管理信息"), 22 | B_JG_COMPANY_STAFF("20_04", "b_jg_company_staff", "企业经营失信名录信息"), 23 | B_JG_COMPANY_ABNORMAL("20_05", "b_jg_company_abnormal", "严重违法失信企业名录"), 24 | B_JG_COMPANY_LOSECREDIT("20_06", "b_jg_company_losecredit", "企业登记信息"), 25 | B_JG_COMPANY("20_07", "b_jg_company", "企业变更登记信息"), 26 | B_JG_COMPANY_CHANGE("20_08", "b_jg_company_change", "工商-股权变更信息"), 27 | GATEWAY_STOCK_CHANGGE("20_09", "gateway_stock_changge", "法人地址标准化信息"), 28 | ; 29 | 30 | /** 31 | * 交互ID 32 | */ 33 | private String id; 34 | /** 35 | * 数据库对应表名 36 | */ 37 | private String tableName; 38 | /** 39 | * 前端页面显示name 40 | */ 41 | private String name; 42 | 43 | DepartTableEnum(String id, String tableName, String name) { 44 | this.id = id; 45 | this.tableName = tableName; 46 | this.name = name; 47 | } 48 | 49 | 50 | public String getTableName() { 51 | return tableName; 52 | } 53 | 54 | public String getId() { 55 | return id; 56 | } 57 | 58 | public String getName() { 59 | return name; 60 | } 61 | 62 | public static String getTableName(String id) { 63 | DepartTableEnum[] values = DepartTableEnum.values(); 64 | for (DepartTableEnum table : values) { 65 | if (table.getId().equals(id)) { 66 | return table.getTableName(); 67 | } 68 | } 69 | return null; 70 | } 71 | 72 | /** 73 | * 根据块ID匹配 块对应的所有表名 74 | * 75 | * @param id 76 | * @return 77 | */ 78 | public static List getTableNameList(String id) { 79 | List tableNameList = new ArrayList<>(); 80 | DepartTableEnum[] values = DepartTableEnum.values(); 81 | for (DepartTableEnum tableId : values) { 82 | if (tableId.getId().indexOf(id + "_") == 0) { 83 | tableNameList.add(tableId.getTableName()); 84 | } 85 | } 86 | return tableNameList; 87 | } 88 | 89 | /** 90 | * 根据块ID获取所有的列表集合 91 | * 92 | * @param id 93 | * @return 94 | */ 95 | public static List getTableList(String id) { 96 | List tableList = new ArrayList<>(); 97 | DepartTableEnum[] values = DepartTableEnum.values(); 98 | for (DepartTableEnum tableEnum : values) { 99 | if (tableEnum.getId().indexOf(id + "_") == 0) { 100 | tableList.add(tableEnum); 101 | } 102 | } 103 | return tableList; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /jdbc-environment/src/main/java/com/ktz/deploy/jdbc/service/DepartmentDataService.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.jdbc.service; 2 | 3 | import com.ktz.deploy.jdbc.entity.dto.AbsDepartmetData; 4 | import com.ktz.deploy.jdbc.entity.dto.ProvTable; 5 | 6 | 7 | public interface DepartmentDataService { 8 | 9 | ProvTable getList(AbsDepartmetData t); 10 | 11 | long findCount(String talbeName); 12 | } 13 | -------------------------------------------------------------------------------- /jdbc-environment/src/main/java/com/ktz/deploy/jdbc/service/IndexService.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.jdbc.service; 2 | 3 | import com.ktz.deploy.jdbc.entity.dto.DepartDataDto; 4 | 5 | import java.util.List; 6 | 7 | public interface IndexService { 8 | 9 | List collectData(); 10 | 11 | List tableList(String id); 12 | } 13 | -------------------------------------------------------------------------------- /jdbc-environment/src/main/java/com/ktz/deploy/jdbc/service/impl/IndexServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.jdbc.service.impl; 2 | 3 | import com.ktz.deploy.jdbc.entity.dto.DepartDataDto; 4 | import com.ktz.deploy.jdbc.enums.DepartEnum; 5 | import com.ktz.deploy.jdbc.enums.DepartTableEnum; 6 | import com.ktz.deploy.jdbc.service.DepartmentDataService; 7 | import com.ktz.deploy.jdbc.service.IndexService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | /** 15 | * @ClassName IndexServiceImpl 16 | * @Description 首页数据统计 17 | * @Author kaituozhesh 18 | * @Date 2020/3/26 13:18 19 | * @Version V1.0 20 | **/ 21 | @Service 22 | public class IndexServiceImpl implements IndexService { 23 | 24 | 25 | @Autowired 26 | private DepartmentDataService departmentDataService; 27 | 28 | /** 29 | * 部门数据 表格块统计信息 30 | * 31 | * @return 32 | */ 33 | @Override 34 | public List collectData() { 35 | List list = new ArrayList<>(); 36 | DepartEnum[] values = DepartEnum.values(); 37 | for (int i = 0; i < values.length; i++) { 38 | list.add(new DepartDataDto(values[i].getId(), values[i].getUrl(), values[i].getValue(), getTotalCount(values[i]))); 39 | } 40 | return list; 41 | } 42 | 43 | /** 44 | * 根据块枚举 ID 计算块中所有table的总数量 45 | * 46 | * @param departEnum 47 | * @return 48 | */ 49 | private long getTotalCount(DepartEnum departEnum) { 50 | List tableNameList = DepartTableEnum.getTableNameList(departEnum.getId()); 51 | return tableNameList.size() > 0 ? tableNameList.stream().mapToLong(tableName -> departmentDataService.findCount(tableName)).sum() : 0; 52 | } 53 | 54 | /** 55 | * 查询块ID对应的 查询列表 56 | * 57 | * @param id 58 | * @return 59 | */ 60 | @Override 61 | public List tableList(String id) { 62 | return getTableList(id); 63 | } 64 | 65 | /** 66 | * 获取块对应列表 67 | * 68 | * @param id 69 | * @return 70 | */ 71 | private List getTableList(String id) { 72 | List tableNameList = DepartTableEnum.getTableList(id); 73 | List list = new ArrayList<>(); 74 | tableNameList.forEach(tableEnum -> list.add(new DepartDataDto(tableEnum.getId(), DepartEnum.getUrl(id), tableEnum.getName(), null))); 75 | return list; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jdbc-environment/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | type: com.alibaba.druid.pool.DruidDataSource 4 | username: root 5 | password: root 6 | driver-class-name: com.mysql.cj.jdbc.Driver 7 | url: jdbc:mysql://localhost:3306/problem?characterEncoding=utf8&useUnicode=true&useSSL=false&useTimezone=true&serverTimezone=GMT%2B8 8 | druid: 9 | initial-size: 5 # \u521D\u59CB\u5316\u65F6\u5EFA\u7ACB\u7269\u7406\u8FDE\u63A5\u7684\u4E2A\u6570\u3002\u521D\u59CB\u5316\u53D1\u751F\u5728\u663E\u793A\u8C03\u7528init\u65B9\u6CD5\uFF0C\u6216\u8005\u7B2C\u4E00\u6B21getConnection\u65F6 10 | max-active: 10 # \u8FDE\u63A5\u6C60\u4E2D\u6700\u591A\u652F\u6301\u591A\u5C11\u4E2A\u6D3B\u52A8\u4F1A\u8BDD 11 | min-idle: 1 # \u6700\u5C0F\u7A7A\u95F2\u8FDE\u63A5\uFF0C\u56DE\u6536\u7A7A\u95F2\u8FDE\u63A5\u65F6\uFF0C\u5C06\u4FDD\u8BC1\u81F3\u5C11\u6709min-idle\u4E2A\u8FDE\u63A5 12 | max-wait: 60000 # \u7A0B\u5E8F\u5411\u8FDE\u63A5\u6C60\u4E2D\u8BF7\u6C42\u8FDE\u63A5\u8D85\u65F6\uFF0C\u8D85\u8FC7max-wait\u7684\u503C\u540E\uFF0C\u8BA4\u4E3A\u672C\u6B21\u8BF7\u6C42\u5931\u8D25\uFF0C\u5373\u8FDE\u63A5\u6C60\u6CA1\u6709\u53EF\u7528\u8FDE\u63A5\uFF0C\u5355\u4F4D\u6BEB\u79D2\uFF0C\u8BBE\u7F6E-1\u65F6\u8868\u793A\u65E0\u9650\u7B49\u5F85 13 | # \u83B7\u53D6\u8FDE\u63A5\u65F6\u6700\u5927\u7B49\u5F85\u65F6\u95F4\uFF0C\u5355\u4F4D\u6BEB\u79D2\u3002\u914D\u7F6Emax-wait\u4E4B\u540E\uFF0C\u9ED8\u8BA4\u542F\u7528\u516C\u5E73\u9501\uFF0C\u5E76\u53D1\u6548\u7387\u4F1A\u6709\u6240\u4E0B\u964D\uFF0C\u5982\u679C\u9700\u8981\u53EF\u4EE5\u901A\u8FC7\u914D\u7F6EuseUnfairLock\u5C5E\u6027\u4E3Atrue\u4F7F\u7528\u8D39\u516C\u5E73\u9501 14 | pool-prepared-statements: true # \u662F\u5426\u7F13\u5B58preparedStatement\uFF0C\u4E5F\u5C31\u662FPSCache\u3002PSCache\u5BF9\u652F\u6301\u6E38\u6807\u7684\u6570\u636E\u5E93\u6027\u80FD\u63D0\u5347\u5DE8\u5927\uFF0C\u6BD4\u5982\u8BF4oracle\u3002\u5728mysql\u4E0B\u5EFA\u8BAE\u5173\u95ED 15 | validation-query: SELECT 1 FROM DUAL # \u68C0\u67E5\u6C60\u4E2D\u7684\u8FDE\u63A5\u662F\u5426\u4ECD\u53EF\u7528\u7684SQL\u8BED\u53E5\uFF0Cdruid\u4F1A\u8FDE\u63A5\u5230\u6570\u636E\u5E93\u6267\u884C\u8BE5SQL\uFF0C\u5982\u679C\u6B63\u5E38\u8FD4\u56DE\uFF0C\u5219\u8868\u793A\u8FDE\u63A5\u53EF\u7528\uFF0C\u5426\u5219\u8868\u793A\u8FDE\u63A5\u4E0D\u53EF\u7528 16 | validation-query-timeout: 10000 # \u5355\u4F4D\uFF1A\u79D2\uFF0C\u68C0\u6D4B\u8FDE\u63A5\u662F\u5426\u6709\u6548\u7684\u8D85\u65F6\u65F6\u95F4\u3002\u5E95\u5C42\u8C03\u7528jdbdStatement\u5BF9\u8C61\u7684void setQueryTimeout(int seconds)\u65B9\u6CD5 17 | test-on-borrow: true # \u7A0B\u5E8F \u7533\u8BF7 \u8FDE\u63A5\u65F6\uFF0C\u8FDB\u884C\u8FDE\u63A5\u6709\u6548\u6027\u68C0\u67E5\uFF08\u4F4E\u6548\uFF0C\u5F71\u54CD\u6027\u80FD\uFF09 18 | test-on-return: false # \u7A0B\u5E8F \u8FD4\u8FD8 \u8FDE\u63A5\u65F6\uFF0C\u8FDB\u884C\u8FDE\u63A5\u6709\u6548\u6027\u68C0\u67E5\uFF08\u4F4E\u6548\uFF0C\u5F71\u54CD\u6027\u80FD\uFF09 19 | test-while-idle: true # \u5EFA\u8BAE\u914D\u7F6E\u4E3Atrue\uFF0C\u4E0D\u5F71\u54CD\u6027\u80FD\uFF0C\u5E76\u4E14\u4FDD\u8BC1\u5B89\u5168\u6027\u3002\u7533\u8BF7\u8FDE\u63A5\u7684\u65F6\u5019\u68C0\u6D4B\uFF0C\u5982\u679C\u7A7A\u95F2\u65F6\u95F4\u5927\u4E8Etime-between-eviction-runs-millis\uFF0C\u6267\u884Cvalidation-query\u68C0\u6D4B\u8FDE\u63A5\u662F\u5426\u6709\u6548 20 | time-between-eviction-runs-millis: 60000 # \u6709\u4E24\u4E2A\u542B\u4E49\uFF1A 21 | # Destroy\u73B0\u573A\u4F1A\u68C0\u6D4B\u8FDE\u63A5\u7684\u95F4\u9694\u65F6\u95F4\uFF0C\u5982\u679C\u8FDE\u63A5\u7A7A\u95F2\u65F6\u95F4\u5927\u4E8E\u7B49\u4E8Emin-evictable-idle-time-millis\u5219\u5173\u95ED\u7269\u7406\u8FDE\u63A5 22 | # test-while-idle\u7684\u5224\u65AD\u4F9D\u636E 23 | min-evictable-idle-time-millis: 30000 # \u6C60\u4E2D\u67D0\u4E2A\u8FDE\u63A5\u7684\u7A7A\u95F2\u65F6\u957F\u8FBE\u5230N\u6BEB\u79D2\u540E\uFF0C\u8FDE\u63A5\u6C60\u5728\u4E0B\u6B21\u68C0\u67E5\u7A7A\u95F2\u8FDE\u63A5\u65F6\uFF0C\u5C06\u56DE\u6536\u8BE5\u8FDE\u63A5\uFF0C\u8981\u5C0F\u4E8E\u9632\u706B\u5899\u8D85\u65F6\u8BBE\u7F6E 24 | filters: stat # stat\uFF1A\u76D1\u63A7\u7EDF\u8BA1 log4j/slf4j\uFF1A\u65E5\u5FD7\u76D1\u63A7 wall\uFF1A\u9632\u5FA1SQL\u6CE8\u5165 -------------------------------------------------------------------------------- /kafka-environment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.5.RELEASE 9 | 10 | 11 | com.ktz.deploy 12 | kafka-environment 13 | 0.0.1-SNAPSHOT 14 | kafka-environment 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | 28 | org.springframework.kafka 29 | spring-kafka 30 | 31 | 32 | 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-maven-plugin 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /kafka-environment/src/main/java/com/ktz/deploy/kafka/KafkaEnvironmentApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.kafka; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class KafkaEnvironmentApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(KafkaEnvironmentApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /kafka-environment/src/main/java/com/ktz/deploy/kafka/config/KafkaConfig.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.kafka.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; 6 | import org.springframework.kafka.config.KafkaListenerContainerFactory; 7 | import org.springframework.kafka.core.ConsumerFactory; 8 | 9 | /** 10 | * ClassName: KafkaConfig 11 | * Description: 12 | * date: 2020/3/8 17:47 13 | * 14 | * @author kaituozhe_sh 15 | */ 16 | @Configuration 17 | public class KafkaConfig { 18 | 19 | /** 20 | * ConcurrentKafkaListenerContainerFactory为创建Kafka监听器的工厂类 21 | * 22 | * @param consumerFactory 23 | * @return 24 | */ 25 | @Bean 26 | public KafkaListenerContainerFactory batchFactory(ConsumerFactory consumerFactory) { 27 | ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>(); 28 | factory.setConsumerFactory(consumerFactory); 29 | factory.setConcurrency(10); 30 | factory.getContainerProperties().setPollTimeout(1500); 31 | factory.setBatchListener(true); 32 | return factory; 33 | } 34 | 35 | 36 | /** 37 | * 消息过滤 38 | * 39 | * @return 40 | */ 41 | @Bean 42 | public KafkaListenerContainerFactory filterContainerFactory( 43 | ConsumerFactory consumerFactory) { 44 | ConcurrentKafkaListenerContainerFactory factory = 45 | new ConcurrentKafkaListenerContainerFactory(); 46 | factory.setConsumerFactory(consumerFactory); 47 | //配合RecordFilterStrategy使用,被过滤的信息将被丢弃 48 | factory.setAckDiscarded(true); 49 | factory.setRecordFilterStrategy(consumerRecord -> { 50 | String msg = (String) consumerRecord.value(); 51 | if (msg.contains("abc")) { 52 | return false; 53 | } 54 | System.out.println("filterContainerFactory filter : " + msg); 55 | //返回true将会被丢弃 56 | return true; 57 | }); 58 | return factory; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /kafka-environment/src/main/java/com/ktz/deploy/kafka/consumer/ConsumerController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.kafka.consumer; 2 | 3 | import org.apache.kafka.clients.consumer.ConsumerRecord; 4 | import org.springframework.kafka.annotation.KafkaListener; 5 | import org.springframework.kafka.annotation.TopicPartition; 6 | import org.springframework.kafka.support.KafkaHeaders; 7 | import org.springframework.messaging.handler.annotation.Header; 8 | import org.springframework.messaging.handler.annotation.Payload; 9 | import org.springframework.stereotype.Component; 10 | 11 | /** 12 | * ClassName: ConsumerController 13 | * Description: 14 | * date: 2020/3/8 17:43 15 | * 16 | * @author kaituozhe_sh 17 | */ 18 | @Component 19 | public class ConsumerController { 20 | /** 21 | * Description: 22 | * @KafkaListener:在注解内指定topic名称,当对应的topic内有新消息时,listen方法会被调用,参数就是topic内新的消息,这个过程是异步进行的 23 | * 工作流程 24 | * 1、解析:解析@KafkaListener注解 25 | * 2、注册:解析后的数据注册到spring-kafka 26 | * 3、监听:开始监听topic变更 27 | * 4、调用:调用注解标识的方法,将监听的数据作为参数传入 28 | * 详解: 29 | * 1、解析:@KafkaListener注解由KafkaListenerAnnotationBeanPostProcessor类解析,后者实现了BeanPostProcessor接口,这个接口内部有两个方法,分别在初始化前后被调用 30 | * KafkaListenerAnnotationBeanPostProcessor内会在postProcessAfterInitialization方法内解析@KafkaListener注解 31 | * 2、注册:解析步骤里,我们可以获取到所有含有@KafkaListener注解的类,之后这些类的相关信息会被注册到KafkaListenerEndpointRegistry内,包括注解所在的方法,当前bean等 32 | * KafkaListenerEndpointRegistry这个类内部会维护多个Listener Container每个@KafkaListener都会对应一个Listener Container。并且每个Container对应一个线程 33 | * 3、监听:注册完成之后,每个Listener Container会开始工作,会新启一个新的线程,初始化KafkaConsumer,监听topic变更等 34 | * 4、调用:监听到数据之后,container会组织消息的格式,随后调用解析得到的@KafkaListener注解标识的方法,将组织后的消息作为参数传入方法,执行用户逻辑 35 | * 36 | * @KafkaListener参数属性 37 | * id:消费者的id,当GroupId没有被配置的时候,默认id为GroupId 38 | * containerFactory:上面提到了@KafkaListener区分单数据还是多数据消费只需要配置一下注解的containerFactory属性就可以了,这里面配置的是监听容器工厂,也就是ConcurrentKafkaListenerContainerFactory,配置BeanName 39 | * topics:需要监听的Topic,可监听多个 40 | * topicPartitions:可配置更多详细的监听信息,必须监听某个Topic中的指定分区,或者从offset为200的偏移量开始监听 41 | * errorHandler:监听异常处理器,配置BeanName 42 | * groupId:消费组ID 43 | * idIsGroup:id是否为GroupId 44 | * clientIdPrefix:消费者Id前缀 45 | * beanRef:真是监听容器的BeanName,需要在BeanName前加“_” 46 | * 47 | * 48 | * ConsumerRecord:包含分区信息、消息头、消息体等内容 49 | * @author kaituozhesh_sh 50 | */ 51 | /* @KafkaListener(topics = "demo") 52 | public void listen(ConsumerRecord record) { 53 | System.out.printf("topic is %s, offset is %d, value is %s \n", record.topic(), record.offset(), record.value()); 54 | }*/ 55 | 56 | /** 57 | * 基于注解的方式获取消息及消息头 58 | * 监听Topic中指定的分区 59 | * @param data 60 | */ 61 | @KafkaListener(id = "id0", containerFactory = "filterContainerFactory", 62 | topicPartitions = {@TopicPartition(topic = "demo", partitions = {"0"})}) 63 | public void annoListener(@Payload String data, 64 | @Header(KafkaHeaders.RECEIVED_PARTITION_ID) String partition, 65 | @Header(KafkaHeaders.RECEIVED_TOPIC) String topic, 66 | @Header(KafkaHeaders.RECEIVED_TIMESTAMP) String timestamp) { 67 | System.out.println(data); 68 | System.out.println(partition); 69 | System.out.println(topic); 70 | System.out.println(timestamp); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /kafka-environment/src/main/java/com/ktz/deploy/kafka/producer/ProducerController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.kafka.producer; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.kafka.core.KafkaTemplate; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * ClassName: ProducerController 10 | * Description: 11 | * date: 2020/3/8 17:44 12 | * 13 | * @author kaituozhe_sh 14 | */ 15 | @RestController 16 | @RequestMapping("/send") 17 | public class ProducerController { 18 | 19 | @Autowired 20 | private KafkaTemplate kafkaTemplate; 21 | 22 | @RequestMapping("/message") 23 | public String send(String msg) { 24 | kafkaTemplate.send("demo", msg); 25 | return "success"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /kafka-environment/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | kafka: 3 | bootstrap-servers: 192.168.181.136:9092 # 指定Kafka Server的地址,集群配多个,中间逗号隔开 4 | producer: 5 | retries: 0 # 写入失败时,重试次数。当leader节点失效,一个repli节点会替代成为leader节点,此时可能出现写入失败,当retries为0时,producer不会重复 6 | batch-size: 16384 # 每次批量发送消息的数量,producer积累到一定数量,一次发送 7 | buffer-memory: 33554432 # producer积累数据一次发送,缓存大小达到buffer money就发送数据 8 | acks: 1 # producer要求leader在考虑完成请求之前收到的确认数,用于控制发送记录在服务端的持久化,其值可以为如下 9 | # acks: 0 producer 不会等待服务器的反馈。该消息会被立刻添加到 socket buffer 中并认为已经发送完成。在这种情况下,服务器是否收到请求是没法保证的,并且参数retries也不会生效(因为客户端无法获得失败信息)。每个记录返回的 offset 总是被设置为-1。 10 | # acks: 1 leader节点会将记录写入本地日志,但无需等待所有follower节点反馈确认成功即可做出回应。在这种情况下,如果 leader 节点在接收记录之后,并且在 follower 节点复制数据完成之前产生错误,则这条记录会丢失 11 | # acks: all leader 节点会等待所有同步中的副本确认之后再确认这条记录是否发送完成。只要至少有一个同步副本存在,记录就不会丢失。这种方式是对请求传递的最有效保证。acks=-1与acks=all是等效的。 12 | # 指定消息key和消息体的编解码方式 13 | key-serializer: org.apache.kafka.common.serialization.StringSerializer 14 | value-serializer: org.apache.kafka.common.serialization.StringSerializer 15 | 16 | 17 | consumer: 18 | group-id: default_consumer_group # 群组ID 19 | enable-auto-commit: true # 是否自动提交offset 20 | auto-commit-interval: 1000 # 自动提交时间间隔 单位:毫秒 默认:5000 21 | # 指定消息key和消息体的编解码方式 22 | key-deserializer: org.apache.kafka.common.serialization.StringDeserializer 23 | value-deserializer: org.apache.kafka.common.serialization.StringDeserializer -------------------------------------------------------------------------------- /log-environment/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | .mvn/wrapper/ 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea/ 18 | *.iws 19 | *.iml 20 | *.ipr 21 | /target 22 | 23 | ### NetBeans ### 24 | /nbproject/private/ 25 | /nbbuild/ 26 | /dist/ 27 | /nbdist/ 28 | /.nb-gradle/ 29 | build/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | -------------------------------------------------------------------------------- /log-environment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.10.RELEASE 9 | 10 | 11 | com.ktz.deploy 12 | log-environment 13 | 0.0.1-SNAPSHOT 14 | log-environment 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-aop 30 | 31 | 32 | 33 | org.projectlombok 34 | lombok 35 | true 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-maven-plugin 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /log-environment/src/main/java/com/ktz/deploy/log/LogEnvironmentApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.log; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 6 | 7 | @EnableAspectJAutoProxy 8 | @SpringBootApplication 9 | public class LogEnvironmentApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(LogEnvironmentApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /log-environment/src/main/java/com/ktz/deploy/log/annotation/LogAnnotation.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.log.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * @Author kaituozhesh 7 | * @Description 8 | * @Date 9:59 2020/3/16 9 | */ 10 | @Documented 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target(ElementType.METHOD) 13 | public @interface LogAnnotation { 14 | String moduleCode() default ""; 15 | } 16 | -------------------------------------------------------------------------------- /log-environment/src/main/java/com/ktz/deploy/log/aspect/LogAspect.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.log.aspect; 2 | 3 | import com.ktz.deploy.log.annotation.LogAnnotation; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.aspectj.lang.JoinPoint; 6 | import org.aspectj.lang.annotation.AfterReturning; 7 | import org.aspectj.lang.annotation.Aspect; 8 | import org.aspectj.lang.annotation.Pointcut; 9 | import org.aspectj.lang.reflect.MethodSignature; 10 | import org.springframework.stereotype.Component; 11 | 12 | import java.lang.reflect.Method; 13 | 14 | /** 15 | * @ClassNameLogAspect 16 | * @Description 17 | * @Author kaituozhesh 18 | * @Date2020/3/16 10:00 19 | * @Version V1.0 20 | **/ 21 | @Slf4j 22 | @Aspect 23 | @Component 24 | public class LogAspect { 25 | 26 | 27 | @Pointcut("@annotation(com.ktz.deploy.log.annotation.LogAnnotation)") 28 | public void logPointcut() { 29 | 30 | } 31 | 32 | @AfterReturning(value = "logPointcut()") 33 | public void doAfterReturning(JoinPoint point) { 34 | Object[] args = point.getArgs(); 35 | MethodSignature sign = (MethodSignature) point.getSignature(); 36 | Method method = sign.getMethod(); 37 | LogAnnotation annotation = method.getAnnotation(LogAnnotation.class); 38 | String moduleCode = annotation.moduleCode(); 39 | String param = (String) args[0]; 40 | log.info("操作模块{} 参数为{}", moduleCode, param); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /log-environment/src/main/java/com/ktz/deploy/log/controller/LogController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.log.controller; 2 | 3 | import com.ktz.deploy.log.annotation.LogAnnotation; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @ClassNameLogController 10 | * @Description 11 | * @Author kaituozhesh 12 | * @Date2020/3/16 10:04 13 | * @Version V1.0 14 | **/ 15 | @Slf4j 16 | @RestController 17 | public class LogController { 18 | 19 | @LogAnnotation(moduleCode = "1001") 20 | @GetMapping("/test") 21 | public Object test(String param) { 22 | return "success"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /log-environment/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | logging: 2 | config: classpath:logback-spring.xml 3 | path: D:/log 4 | 5 | spring: 6 | profiles: 7 | active: dev -------------------------------------------------------------------------------- /mongodb-environment/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | .mvn/wrapper/ 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea/ 18 | *.iws 19 | *.iml 20 | *.ipr 21 | /target 22 | 23 | ### NetBeans ### 24 | /nbproject/private/ 25 | /nbbuild/ 26 | /dist/ 27 | /nbdist/ 28 | /.nb-gradle/ 29 | build/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | -------------------------------------------------------------------------------- /mongodb-environment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.5.RELEASE 9 | 10 | 11 | com.ktz.deploy 12 | mongodb-environment 13 | 0.0.1-SNAPSHOT 14 | mongodb-environment 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-data-mongodb 30 | 31 | 32 | org.projectlombok 33 | lombok 34 | true 35 | 36 | 37 | com.alibaba 38 | fastjson 39 | 1.2.62 40 | 41 | 42 | 43 | 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-maven-plugin 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /mongodb-environment/src/main/java/com/ktz/deploy/mongodb/MongodbEnvironmentApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.mongodb; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class MongodbEnvironmentApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(MongodbEnvironmentApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /mongodb-environment/src/main/java/com/ktz/deploy/mongodb/controller/MongoController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.mongodb.controller; 2 | 3 | import com.ktz.deploy.mongodb.entity.User; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.data.mongodb.core.MongoTemplate; 6 | import org.springframework.data.mongodb.core.query.Criteria; 7 | import org.springframework.data.mongodb.core.query.Query; 8 | import org.springframework.data.mongodb.core.query.Update; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | 12 | /** 13 | * ClassName: MongoController 14 | * Description: 15 | * date: 2020/3/15 19:56 16 | * 17 | * @author kaituozhe_sh 18 | */ 19 | @RestController 20 | public class MongoController { 21 | 22 | @Autowired 23 | private MongoTemplate mongoTemplate; 24 | 25 | @GetMapping("/get_all") 26 | public Object getAll() { 27 | return mongoTemplate.findAll(User.class); 28 | } 29 | 30 | @PostMapping("/add") 31 | public Object add(@RequestBody User user) { 32 | if (user.getId() == null) { 33 | return mongoTemplate.insert(user, "user"); 34 | } else { 35 | Query query = new Query(); 36 | query.addCriteria(Criteria.where("_id").is(user.getId())); 37 | 38 | Update update = new Update(); 39 | update.set("name", user.getName()); 40 | update.set("age", user.getAge()); 41 | 42 | return mongoTemplate.updateFirst(query, update, "user"); 43 | } 44 | } 45 | 46 | @PostMapping("/delete/{id}") 47 | public Object delete(@PathVariable String id){ 48 | Query query = new Query(); 49 | query.addCriteria(Criteria.where("_id").is(id)); 50 | 51 | return mongoTemplate.remove(query, User.class, "user"); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /mongodb-environment/src/main/java/com/ktz/deploy/mongodb/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.mongodb.entity; 2 | 3 | import lombok.Data; 4 | import lombok.ToString; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * ClassName: User 10 | * Description: 11 | * date: 2020/3/15 19:52 12 | * 13 | * @author kaituozhe_sh 14 | */ 15 | @ToString 16 | @Data 17 | public class User implements Serializable { 18 | 19 | private String id; 20 | private String name; 21 | private Integer age; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /mongodb-environment/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | data: 3 | mongodb: 4 | uri: "mongodb://localhost:27017/test" -------------------------------------------------------------------------------- /nacos-environment/nacos-consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | nacos-environment 7 | com.ktz.deploy 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | nacos-consumer 13 | 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-web 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-actuator 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-test 27 | test 28 | 29 | 30 | 31 | 32 | org.springframework.cloud 33 | spring-cloud-starter-alibaba-nacos-discovery 34 | 35 | 36 | org.springframework.cloud 37 | spring-cloud-starter-openfeign 38 | 39 | 40 | org.springframework.cloud 41 | spring-cloud-starter-alibaba-nacos-config 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | com.ktz.deploy.nacos.consumer.NacosConsumerApplication 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /nacos-environment/nacos-consumer/src/main/java/com/ktz/deploy/nacos/consumer/NacosConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.nacos.consumer; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.openfeign.EnableFeignClients; 7 | 8 | 9 | /** 10 | * @ClassName NacosConsumerApplication 11 | * @Description 12 | * @Author kaituozhesh 13 | * @Date 2020/3/19 15:02 14 | * @Version V1.0 15 | **/ 16 | @EnableDiscoveryClient 17 | @EnableFeignClients 18 | @SpringBootApplication 19 | public class NacosConsumerApplication { 20 | 21 | public static void main(String[] args) { 22 | SpringApplication.run(NacosConsumerApplication.class, args); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /nacos-environment/nacos-consumer/src/main/java/com/ktz/deploy/nacos/consumer/config/ConsumerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.nacos.consumer.config; 2 | 3 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.client.RestTemplate; 7 | 8 | /** 9 | * @ClassName ConsumerConfiguration 10 | * @Description 配置 11 | * @Author kaituozhesh 12 | * @Date 2020/3/19 15:03 13 | * @Version V1.0 14 | **/ 15 | @Configuration 16 | public class ConsumerConfiguration { 17 | 18 | @Bean 19 | @LoadBalanced 20 | public RestTemplate restTemplate() { 21 | return new RestTemplate(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /nacos-environment/nacos-consumer/src/main/java/com/ktz/deploy/nacos/consumer/controller/FeignController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.nacos.consumer.controller; 2 | 3 | import com.ktz.deploy.nacos.consumer.service.EchoService; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.cloud.context.config.annotation.RefreshScope; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import javax.annotation.Resource; 12 | 13 | /** 14 | * @ClassName FeignController 15 | * @Description 16 | * @Author kaituozhesh 17 | * @Date 2020/3/19 15:15 18 | * @Version V1.0 19 | **/ 20 | @RefreshScope 21 | @RestController 22 | @RequestMapping("/feign") 23 | public class FeignController { 24 | 25 | @Resource 26 | private EchoService echoService; 27 | 28 | @Value("${user.name}") 29 | private String username; 30 | 31 | @GetMapping("/echo/{str}") 32 | public String feignEcho(@PathVariable String str) { 33 | return echoService.echo(str); 34 | } 35 | 36 | @GetMapping("/lb") 37 | public String feignlb() { 38 | return echoService.lb(); 39 | } 40 | 41 | @GetMapping("/echo_name") 42 | public String feignEchoName() { 43 | return echoService.echoName(username); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /nacos-environment/nacos-consumer/src/main/java/com/ktz/deploy/nacos/consumer/controller/TestController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.nacos.consumer.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RestController; 7 | import org.springframework.web.client.RestTemplate; 8 | 9 | @RestController 10 | public class TestController { 11 | private final RestTemplate restTemplate; 12 | 13 | @Autowired 14 | public TestController(RestTemplate restTemplate) { 15 | this.restTemplate = restTemplate; 16 | } 17 | 18 | @GetMapping(value = "/echo/{str}") 19 | public String echo(@PathVariable String str) { 20 | // 使用服务名请求服务提供者 21 | return restTemplate.getForObject("http://service-provider/echo/" + str, String.class); 22 | } 23 | } -------------------------------------------------------------------------------- /nacos-environment/nacos-consumer/src/main/java/com/ktz/deploy/nacos/consumer/service/EchoService.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.nacos.consumer.service; 2 | 3 | import com.ktz.deploy.nacos.consumer.service.fallback.EchoServiceFallback; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | 8 | @FeignClient(name = "service-provider", fallback = EchoServiceFallback.class) 9 | public interface EchoService { 10 | 11 | @GetMapping("/echo/{string}") 12 | String echo(@PathVariable String string); 13 | 14 | @GetMapping(value = "/lb") 15 | String lb(); 16 | 17 | @GetMapping("/show/{name}") 18 | String echoName(@PathVariable String name); 19 | } 20 | -------------------------------------------------------------------------------- /nacos-environment/nacos-consumer/src/main/java/com/ktz/deploy/nacos/consumer/service/fallback/EchoServiceFallback.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.nacos.consumer.service.fallback; 2 | 3 | import com.ktz.deploy.nacos.consumer.service.EchoService; 4 | import org.springframework.stereotype.Component; 5 | 6 | /** 7 | * @ClassName EchoServiceImpl 8 | * @Description 9 | * @Author kaituozhesh 10 | * @Date 2020/3/19 15:13 11 | * @Version V1.0 12 | **/ 13 | @Component 14 | public class EchoServiceFallback implements EchoService { 15 | @Override 16 | public String echo(String string) { 17 | return "echo fail"; 18 | } 19 | 20 | @Override 21 | public String lb() { 22 | return "lb fail"; 23 | } 24 | 25 | @Override 26 | public String echoName(String name) { 27 | return "echoName fail"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /nacos-environment/nacos-consumer/src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaituozhesh/deploy-environ/bcad33f5493e39e627e775adad70a965bbb3be76/nacos-environment/nacos-consumer/src/main/resources/application-dev.yml -------------------------------------------------------------------------------- /nacos-environment/nacos-consumer/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: service-consumer 4 | profiles: 5 | active: dev 6 | cloud: 7 | nacos: 8 | discovery: 9 | server-addr: 192.168.41.129:8848 10 | config: 11 | server-addr: 192.168.41.129:8848 12 | file-extension: yaml 13 | 14 | 15 | management: 16 | endpoints: 17 | web: 18 | exposure: 19 | include: '*' 20 | endpoint: 21 | health: 22 | show-details: ALWAYS -------------------------------------------------------------------------------- /nacos-environment/nacos-provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | nacos-environment 7 | com.ktz.deploy 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | nacos-provider 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-web 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-actuator 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-test 26 | test 27 | 28 | 29 | 30 | 31 | 32 | org.springframework.cloud 33 | spring-cloud-starter-alibaba-nacos-discovery 34 | 35 | 36 | org.springframework.cloud 37 | spring-cloud-starter-alibaba-nacos-config 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-maven-plugin 46 | 47 | com.ktz.deploy.nacos.provider.NacosProviderApplication 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /nacos-environment/nacos-provider/src/main/java/com/ktz/deploy/nacos/provider/NacosProviderApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.nacos.provider; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | /** 8 | * @ClassName NacosProviderApplication 9 | * @Description 服务提供者 10 | * @Author kaituozhesh 11 | * @Date 2020/3/19 14:39 12 | * @Version V1.0 13 | **/ 14 | @SpringBootApplication 15 | @EnableDiscoveryClient 16 | public class NacosProviderApplication { 17 | public static void main(String[] args) { 18 | SpringApplication.run(NacosProviderApplication.class, args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /nacos-environment/nacos-provider/src/main/java/com/ktz/deploy/nacos/provider/controller/EchoController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.nacos.provider.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @ClassName EchoController 10 | * @Description 11 | * @Author kaituozhesh 12 | * @Date 2020/3/19 14:53 13 | * @Version V1.0 14 | **/ 15 | @RestController 16 | public class EchoController { 17 | 18 | @Value("${server.port}") 19 | private String port; 20 | 21 | @GetMapping("/echo/{string}") 22 | public String echo(@PathVariable String string) { 23 | return "Hello Nacos Provider " + string; 24 | } 25 | 26 | @GetMapping(value = "/lb") 27 | public String lb() { 28 | return "Hello Naocs Provider i am from port:" + port; 29 | } 30 | 31 | @GetMapping("/show/{name}") 32 | public String echoName(@PathVariable String name) { 33 | return "= " + name + " ="; 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /nacos-environment/nacos-provider/src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaituozhesh/deploy-environ/bcad33f5493e39e627e775adad70a965bbb3be76/nacos-environment/nacos-provider/src/main/resources/application-dev.yml -------------------------------------------------------------------------------- /nacos-environment/nacos-provider/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | # 服务名 4 | name: service-provider 5 | profiles: 6 | active: dev 7 | cloud: 8 | nacos: 9 | discovery: 10 | # 服务注册中心 11 | server-addr: 192.168.41.129:8848 12 | config: 13 | server-addr: 192.168.41.129:8848 14 | file-extension: yaml 15 | server: 16 | # 服务端口 17 | port: 8070 18 | management: 19 | # 端点检查(健康检查) 20 | endpoints: 21 | web: 22 | exposure: 23 | include: "*" -------------------------------------------------------------------------------- /nacos-environment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 2.1.6.RELEASE 10 | 11 | 12 | com.ktz.deploy 13 | nacos-environment 14 | pom 15 | 1.0-SNAPSHOT 16 | 17 | nacos-provider 18 | nacos-consumer 19 | 20 | 21 | Greenwich.RELEASE 22 | 0.9.0.RELEASE 23 | 24 | 25 | 26 | 27 | 28 | 29 | org.springframework.cloud 30 | spring-cloud-dependencies 31 | ${spring-cloud.version} 32 | pom 33 | import 34 | 35 | 36 | org.springframework.cloud 37 | spring-cloud-alibaba-dependencies 38 | ${spring-cloud-alibaba.version} 39 | pom 40 | import 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-resource/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | oauth2-environment 7 | com.ktz.deploy 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | oauth2-resource 13 | 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-web 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-test 23 | 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-security 29 | 30 | 31 | 32 | org.springframework.security.oauth.boot 33 | spring-security-oauth2-autoconfigure 34 | 2.0.0.RELEASE 35 | 36 | 37 | 38 | 39 | com.zaxxer 40 | HikariCP 41 | ${hikaricp.version} 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-jdbc 46 | 47 | 48 | 49 | org.apache.tomcat 50 | tomcat-jdbc 51 | 52 | 53 | 54 | 55 | mysql 56 | mysql-connector-java 57 | ${mysql.version} 58 | 59 | 60 | 61 | tk.mybatis 62 | mapper-spring-boot-starter 63 | 2.1.5 64 | 65 | 66 | org.projectlombok 67 | lombok 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | org.springframework.boot 76 | spring-boot-maven-plugin 77 | 78 | com.ktz.deploy.oauth2.resource.OAuth2ResourceApplication 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-resource/src/main/java/com/ktz/deploy/oauth2/resource/OAuth2ResourceApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.resource; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import tk.mybatis.spring.annotation.MapperScan; 6 | 7 | /** 8 | * @ClassName OAuth2ResourceApplication 9 | * @Description 10 | * @Author kaituozhesh 11 | * @Date 2020/3/18 10:43 12 | * @Version V1.0 13 | **/ 14 | @SpringBootApplication 15 | @MapperScan(basePackages = "com.ktz.deploy.oauth2.resource.mapper") 16 | public class OAuth2ResourceApplication { 17 | public static void main(String[] args) { 18 | SpringApplication.run(OAuth2ResourceApplication.class, args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-resource/src/main/java/com/ktz/deploy/oauth2/resource/config/ResourceServerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.resource.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.http.SessionCreationPolicy; 7 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 8 | import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; 9 | /** 10 | * @Author kaituozhesh 11 | * @Description 12 | * @Date 11:33 2020/3/18 13 | */ 14 | @Configuration 15 | @EnableResourceServer 16 | @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true) 17 | public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter { 18 | @Override 19 | public void configure(HttpSecurity http) throws Exception { 20 | http 21 | .exceptionHandling() 22 | .and() 23 | // Session 创建策略 24 | // ALWAYS 总是创建 HttpSession 25 | // IF_REQUIRED Spring Security 只会在需要时创建一个 HttpSession 26 | // NEVER Spring Security 不会创建 HttpSession,但如果它已经存在,将可以使用 HttpSession 27 | // STATELESS Spring Security 永远不会创建 HttpSession,它不会使用 HttpSession 来获取 SecurityContext 28 | .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) 29 | .and() 30 | .authorizeRequests() 31 | // 以下为配置所需保护的资源路径及权限,需要与认证服务器配置的授权部分对应 32 | .antMatchers("/contents/").hasAuthority("SystemContent") 33 | .antMatchers("/contents/view/**").hasAuthority("SystemContentView") 34 | .antMatchers("/contents/insert/**").hasAuthority("SystemContentInsert") 35 | .antMatchers("/contents/update/**").hasAuthority("SystemContentUpdate") 36 | .antMatchers("/contents/delete/**").hasAuthority("SystemContentDelete"); 37 | } 38 | } -------------------------------------------------------------------------------- /oauth2-environment/oauth2-resource/src/main/java/com/ktz/deploy/oauth2/resource/controller/TbContentController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.resource.controller; 2 | 3 | import com.ktz.deploy.oauth2.resource.domain.TbContent; 4 | import com.ktz.deploy.oauth2.resource.dto.ResponseResult; 5 | import com.ktz.deploy.oauth2.resource.service.TbContentService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | import java.util.List; 11 | 12 | @RestController 13 | public class TbContentController { 14 | 15 | @Autowired 16 | private TbContentService tbContentService; 17 | 18 | /** 19 | * 获取全部资源 20 | * 21 | * @return 22 | */ 23 | @GetMapping("/") 24 | public ResponseResult> selectAll() { 25 | return new ResponseResult<>(Integer.valueOf(HttpStatus.OK.value()), HttpStatus.OK.toString(), tbContentService.selectAll()); 26 | } 27 | 28 | /** 29 | * 获取资源详情 30 | * 31 | * @param id 32 | * @return 33 | */ 34 | @GetMapping("/view/{id}") 35 | public ResponseResult getById(@PathVariable Long id) { 36 | return new ResponseResult<>(Integer.valueOf(HttpStatus.OK.value()), HttpStatus.OK.toString(), tbContentService.getById(id)); 37 | } 38 | 39 | /** 40 | * 新增资源 41 | * 42 | * @param tbContent 43 | * @return 44 | */ 45 | @PostMapping("/insert") 46 | public ResponseResult insert(@RequestBody TbContent tbContent) { 47 | int count = tbContentService.insert(tbContent); 48 | 49 | if (count > 0) { 50 | return new ResponseResult<>(Integer.valueOf(HttpStatus.OK.value()), HttpStatus.OK.toString(), count); 51 | } else { 52 | return new ResponseResult<>(Integer.valueOf(HttpStatus.BAD_REQUEST.value()), HttpStatus.BAD_REQUEST.toString()); 53 | } 54 | } 55 | 56 | /** 57 | * 更新资源 58 | * 59 | * @param tbContent 60 | * @return 61 | */ 62 | @PutMapping("/update") 63 | public ResponseResult update(@RequestBody TbContent tbContent) { 64 | int count = tbContentService.update(tbContent); 65 | 66 | if (count > 0) { 67 | return new ResponseResult<>(Integer.valueOf(HttpStatus.OK.value()), HttpStatus.OK.toString(), count); 68 | } else { 69 | return new ResponseResult<>(Integer.valueOf(HttpStatus.BAD_REQUEST.value()), HttpStatus.BAD_REQUEST.toString()); 70 | } 71 | } 72 | 73 | /** 74 | * 删除资源 75 | * 76 | * @param id 77 | * @return 78 | */ 79 | @DeleteMapping("/delete/{id}") 80 | public ResponseResult delete(@PathVariable Long id) { 81 | int count = tbContentService.delete(id); 82 | 83 | if (count > 0) { 84 | return new ResponseResult<>(Integer.valueOf(HttpStatus.OK.value()), HttpStatus.OK.toString(), count); 85 | } else { 86 | return new ResponseResult<>(Integer.valueOf(HttpStatus.BAD_REQUEST.value()), HttpStatus.BAD_REQUEST.toString()); 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /oauth2-environment/oauth2-resource/src/main/java/com/ktz/deploy/oauth2/resource/domain/TbContent.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.resource.domain; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | import java.io.Serializable; 10 | import java.util.Date; 11 | 12 | @Data 13 | 14 | @Table(name = "tb_content") 15 | public class TbContent implements Serializable { 16 | @Id 17 | @Column(name = "id") 18 | @GeneratedValue(generator = "JDBC") 19 | private Long id; 20 | 21 | /** 22 | * 内容类目ID 23 | */ 24 | @Column(name = "category_id") 25 | private Long categoryId; 26 | 27 | /** 28 | * 内容标题 29 | */ 30 | @Column(name = "title") 31 | private String title; 32 | 33 | /** 34 | * 子标题 35 | */ 36 | @Column(name = "sub_title") 37 | private String subTitle; 38 | 39 | /** 40 | * 标题描述 41 | */ 42 | @Column(name = "title_desc") 43 | private String titleDesc; 44 | 45 | /** 46 | * 链接 47 | */ 48 | @Column(name = "url") 49 | private String url; 50 | 51 | /** 52 | * 图片绝对路径 53 | */ 54 | @Column(name = "pic") 55 | private String pic; 56 | 57 | /** 58 | * 图片2 59 | */ 60 | @Column(name = "pic2") 61 | private String pic2; 62 | 63 | /** 64 | * 内容 65 | */ 66 | @Column(name = "content") 67 | private String content; 68 | 69 | @Column(name = "created") 70 | private Date created; 71 | 72 | @Column(name = "updated") 73 | private Date updated; 74 | 75 | private static final long serialVersionUID = 1L; 76 | } -------------------------------------------------------------------------------- /oauth2-environment/oauth2-resource/src/main/java/com/ktz/deploy/oauth2/resource/domain/TbContentCategory.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.resource.domain; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | import java.io.Serializable; 10 | import java.util.Date; 11 | 12 | @Data 13 | @Table(name = "tb_content_category") 14 | public class TbContentCategory implements Serializable { 15 | /** 16 | * 类目ID 17 | */ 18 | @Id 19 | @Column(name = "id") 20 | @GeneratedValue(generator = "JDBC") 21 | private Long id; 22 | 23 | /** 24 | * 父类目ID=0时,代表的是一级的类目 25 | */ 26 | @Column(name = "parent_id") 27 | private Long parentId; 28 | 29 | /** 30 | * 分类名称 31 | */ 32 | @Column(name = "`name`") 33 | private String name; 34 | 35 | /** 36 | * 状态。可选值:1(正常),2(删除) 37 | */ 38 | @Column(name = "`status`") 39 | private Integer status; 40 | 41 | /** 42 | * 排列序号,表示同级类目的展现次序,如数值相等则按名称次序排列。取值范围:大于零的整数 43 | */ 44 | @Column(name = "sort_order") 45 | private Integer sortOrder; 46 | 47 | /** 48 | * 该类目是否为父类目,1为true,0为false 49 | */ 50 | @Column(name = "is_parent") 51 | private Boolean isParent; 52 | 53 | /** 54 | * 创建时间 55 | */ 56 | @Column(name = "created") 57 | private Date created; 58 | 59 | /** 60 | * 创建时间 61 | */ 62 | @Column(name = "updated") 63 | private Date updated; 64 | 65 | private static final long serialVersionUID = 1L; 66 | } -------------------------------------------------------------------------------- /oauth2-environment/oauth2-resource/src/main/java/com/ktz/deploy/oauth2/resource/dto/ResponseResult.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.resource.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class ResponseResult implements Serializable { 9 | private static final long serialVersionUID = 3468352004150968551L; 10 | /** 11 | * 状态码 12 | */ 13 | private Integer state; 14 | /** 15 | * 消息 16 | */ 17 | private String message; 18 | /** 19 | * 返回对象 20 | */ 21 | private T data; 22 | public ResponseResult() { 23 | super(); 24 | } 25 | public ResponseResult(Integer state) { 26 | super(); 27 | this.state = state; 28 | } 29 | public ResponseResult(Integer state, String message) { 30 | super(); 31 | this.state = state; 32 | this.message = message; 33 | } 34 | public ResponseResult(Integer state, Throwable throwable) { 35 | super(); 36 | this.state = state; 37 | this.message = throwable.getMessage(); 38 | } 39 | public ResponseResult(Integer state, T data) { 40 | super(); 41 | this.state = state; 42 | this.data = data; 43 | } 44 | public ResponseResult(Integer state, String message, T data) { 45 | super(); 46 | this.state = state; 47 | this.message = message; 48 | this.data = data; 49 | } 50 | public Integer getState() { 51 | return state; 52 | } 53 | public void setState(Integer state) { 54 | this.state = state; 55 | } 56 | public String getMessage() { 57 | return message; 58 | } 59 | public void setMessage(String message) { 60 | this.message = message; 61 | } 62 | public T getData() { 63 | return data; 64 | } 65 | public void setData(T data) { 66 | this.data = data; 67 | } 68 | @Override 69 | public int hashCode() { 70 | final int prime = 31; 71 | int result = 1; 72 | result = prime * result + ((data == null) ? 0 : data.hashCode()); 73 | result = prime * result + ((message == null) ? 0 : message.hashCode()); 74 | result = prime * result + ((state == null) ? 0 : state.hashCode()); 75 | return result; 76 | } 77 | @Override 78 | public boolean equals(Object obj) { 79 | if (this == obj) { 80 | return true; 81 | } 82 | if (obj == null) { 83 | return false; 84 | } 85 | if (getClass() != obj.getClass()) { 86 | return false; 87 | } 88 | ResponseResult other = (ResponseResult) obj; 89 | if (data == null) { 90 | if (other.data != null) { 91 | return false; 92 | } 93 | } else if (!data.equals(other.data)) { 94 | return false; 95 | } 96 | if (message == null) { 97 | if (other.message != null) { 98 | return false; 99 | } 100 | } else if (!message.equals(other.message)) { 101 | return false; 102 | } 103 | if (state == null) { 104 | if (other.state != null) { 105 | return false; 106 | } 107 | } else if (!state.equals(other.state)) { 108 | return false; 109 | } 110 | return true; 111 | } 112 | } -------------------------------------------------------------------------------- /oauth2-environment/oauth2-resource/src/main/java/com/ktz/deploy/oauth2/resource/mapper/TbContentCategoryMapper.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.resource.mapper; 2 | 3 | import com.ktz.deploy.oauth2.resource.domain.TbContentCategory; 4 | import tk.mybatis.mapper.MyMapper; 5 | 6 | public interface TbContentCategoryMapper extends MyMapper { 7 | } -------------------------------------------------------------------------------- /oauth2-environment/oauth2-resource/src/main/java/com/ktz/deploy/oauth2/resource/mapper/TbContentMapper.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.resource.mapper; 2 | 3 | import com.ktz.deploy.oauth2.resource.domain.TbContent; 4 | import tk.mybatis.mapper.MyMapper; 5 | 6 | public interface TbContentMapper extends MyMapper { 7 | } -------------------------------------------------------------------------------- /oauth2-environment/oauth2-resource/src/main/java/com/ktz/deploy/oauth2/resource/service/TbContentCategoryService.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.resource.service; 2 | 3 | public interface TbContentCategoryService{ 4 | 5 | } -------------------------------------------------------------------------------- /oauth2-environment/oauth2-resource/src/main/java/com/ktz/deploy/oauth2/resource/service/TbContentService.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.resource.service; 2 | 3 | import com.ktz.deploy.oauth2.resource.domain.TbContent; 4 | 5 | import java.util.List; 6 | 7 | public interface TbContentService { 8 | 9 | /** 10 | * 根据 ID 获取 11 | * 12 | * @param id ID 13 | * @return {@link TbContent} 14 | */ 15 | default TbContent getById(Long id) { 16 | return null; 17 | } 18 | 19 | /** 20 | * 获取全部数据 21 | * 22 | * @return {@link List} 23 | */ 24 | default List selectAll() { 25 | return null; 26 | } 27 | 28 | /** 29 | * 新增 30 | * 31 | * @param tbContent {@link TbContent} 32 | * @return int 数据库受影响行数 33 | */ 34 | default int insert(TbContent tbContent) { 35 | return 0; 36 | } 37 | 38 | /** 39 | * 编辑 40 | * 41 | * @param tbContent {@link TbContent} 42 | * @return int 数据库受影响行数 43 | */ 44 | default int update(TbContent tbContent) { 45 | return 0; 46 | } 47 | 48 | /** 49 | * 删除 50 | * 51 | * @param id ID 52 | * @return int 数据库受影响行数 53 | */ 54 | default int delete(Long id) { 55 | return 0; 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /oauth2-environment/oauth2-resource/src/main/java/com/ktz/deploy/oauth2/resource/service/impl/TbContentCategoryServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.resource.service.impl; 2 | 3 | import com.ktz.deploy.oauth2.resource.mapper.TbContentCategoryMapper; 4 | import com.ktz.deploy.oauth2.resource.service.TbContentCategoryService; 5 | import org.springframework.stereotype.Service; 6 | 7 | import javax.annotation.Resource; 8 | 9 | @Service 10 | public class TbContentCategoryServiceImpl implements TbContentCategoryService { 11 | 12 | @Resource 13 | private TbContentCategoryMapper tbContentCategoryMapper; 14 | 15 | } -------------------------------------------------------------------------------- /oauth2-environment/oauth2-resource/src/main/java/com/ktz/deploy/oauth2/resource/service/impl/TbContentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.resource.service.impl; 2 | 3 | import com.ktz.deploy.oauth2.resource.domain.TbContent; 4 | import com.ktz.deploy.oauth2.resource.mapper.TbContentMapper; 5 | import com.ktz.deploy.oauth2.resource.service.TbContentService; 6 | import org.springframework.stereotype.Service; 7 | 8 | import javax.annotation.Resource; 9 | import java.util.List; 10 | 11 | @Service 12 | public class TbContentServiceImpl implements TbContentService { 13 | 14 | @Resource 15 | private TbContentMapper tbContentMapper; 16 | 17 | @Override 18 | public TbContent getById(Long id) { 19 | return tbContentMapper.selectByPrimaryKey(id); 20 | } 21 | 22 | @Override 23 | public List selectAll() { 24 | return tbContentMapper.selectAll(); 25 | } 26 | 27 | @Override 28 | public int insert(TbContent tbContent) { 29 | return tbContentMapper.insert(tbContent); 30 | } 31 | 32 | @Override 33 | public int update(TbContent tbContent) { 34 | return tbContentMapper.updateByPrimaryKey(tbContent); 35 | } 36 | 37 | @Override 38 | public int delete(Long id) { 39 | return tbContentMapper.deleteByPrimaryKey(id); 40 | } 41 | } -------------------------------------------------------------------------------- /oauth2-environment/oauth2-resource/src/main/java/tk/mybatis/mapper/MyMapper.java: -------------------------------------------------------------------------------- 1 | package tk.mybatis.mapper; 2 | 3 | import tk.mybatis.mapper.common.Mapper; 4 | import tk.mybatis.mapper.common.MySqlMapper; 5 | 6 | public interface MyMapper extends Mapper, MySqlMapper { 7 | } 8 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-resource/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: oauth2-resource 4 | datasource: 5 | type: com.zaxxer.hikari.HikariDataSource 6 | driver-class-name: com.mysql.cj.jdbc.Driver 7 | url: jdbc:mysql://127.0.0.1:3306/oauth-resource?characterEncoding=utf8&useUnicode=true&useSSL=false&useTimezone=true&serverTimezone=GMT%2B8 8 | username: root 9 | password: root 10 | hikari: 11 | minimum-idle: 5 12 | idle-timeout: 600000 13 | maximum-pool-size: 10 14 | auto-commit: true 15 | pool-name: MyHikariCP 16 | max-lifetime: 1800000 17 | connection-timeout: 30000 18 | connection-test-query: SELECT 1 19 | security: 20 | oauth2: 21 | client: 22 | client-id: client 23 | client-secret: secret 24 | access-token-uri: http://localhost:8080/oauth/token 25 | user-authorization-uri: http://localhost:8080/oauth/authorize 26 | resource: 27 | token-info-uri: http://localhost:8080/oauth/check_token 28 | server: 29 | port: 8081 30 | servlet: 31 | context-path: /contents 32 | mybatis: 33 | type-aliases-package: com.ktz.deploy.oauth2.resource.domain 34 | mapper-locations: classpath:mapper/*.xml 35 | logging: 36 | level: 37 | root: INFO 38 | org.springframework.web: INFO 39 | org.springframework.security: INFO 40 | org.springframework.security.oauth2: INFO -------------------------------------------------------------------------------- /oauth2-environment/oauth2-resource/src/main/resources/mapper/TbContentCategoryMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | id, parent_id, `name`, `status`, sort_order, is_parent, created, updated 18 | 19 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-resource/src/main/resources/mapper/TbContentMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | id, category_id, title, sub_title, title_desc, url, pic, pic2, content, created, 21 | updated 22 | 23 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | oauth2-environment 7 | com.ktz.deploy 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | oauth2-server 13 | 14 | 15 | Apache 2.0 16 | https://www.apache.org/licenses/LICENSE-2.0.txt 17 | 18 | 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-test 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-security 34 | 35 | 36 | 37 | org.springframework.security.oauth.boot 38 | spring-security-oauth2-autoconfigure 39 | 2.0.0.RELEASE 40 | 41 | 42 | 43 | com.zaxxer 44 | HikariCP 45 | ${hikaricp.version} 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-starter-jdbc 50 | 51 | 52 | 53 | org.apache.tomcat 54 | tomcat-jdbc 55 | 56 | 57 | 58 | 59 | 60 | mysql 61 | mysql-connector-java 62 | ${mysql.version} 63 | 64 | 65 | 66 | tk.mybatis 67 | mapper-spring-boot-starter 68 | 2.1.5 69 | 70 | 71 | org.projectlombok 72 | lombok 73 | true 74 | 75 | 76 | 77 | 78 | 79 | 80 | org.springframework.boot 81 | spring-boot-maven-plugin 82 | 83 | com.ktz.deploy.oauth2.server.OAuth2ServerApplication 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-server/src/main/java/com/ktz/deploy/oauth2/server/OAuth2ServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.server; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import tk.mybatis.spring.annotation.MapperScan; 6 | 7 | /** 8 | * @ClassName OAuth2ServerApplication 9 | * @Description 10 | * @Author kaituozhesh 11 | * @Date 2020/3/16 14:15 12 | * @Version V1.0 13 | **/ 14 | @SpringBootApplication 15 | @MapperScan(basePackages = "com.ktz.deploy.oauth2.server.mapper") 16 | public class OAuth2ServerApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(OAuth2ServerApplication.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-server/src/main/java/com/ktz/deploy/oauth2/server/configure/AuthorizationServerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.server.configure; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.boot.jdbc.DataSourceBuilder; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.context.annotation.Primary; 9 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 10 | import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; 11 | import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; 12 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; 13 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; 14 | import org.springframework.security.oauth2.provider.ClientDetailsService; 15 | import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService; 16 | import org.springframework.security.oauth2.provider.token.TokenStore; 17 | import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore; 18 | 19 | import javax.sql.DataSource; 20 | 21 | /** 22 | * @ClassName AuthorizationServerConfiguration 23 | * @Description 24 | * @Author kaituozhesh 25 | * @Date 2020/3/16 14:27 26 | * @Version V1.0 27 | **/ 28 | @Configuration 29 | @EnableAuthorizationServer 30 | public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter { 31 | 32 | @Autowired 33 | private BCryptPasswordEncoder passwordEncoder; 34 | @Bean 35 | @Primary 36 | @ConfigurationProperties(prefix = "spring.datasource") 37 | public DataSource dataSource() { 38 | // 配置数据源(注意,我使用的是 HikariCP 连接池),以上注解是指定数据源,否则会有冲突 39 | return DataSourceBuilder.create().build(); 40 | } 41 | @Bean 42 | public TokenStore tokenStore() { 43 | // 基于 JDBC 实现,令牌保存到数据库 44 | return new JdbcTokenStore(dataSource()); 45 | } 46 | @Bean 47 | public ClientDetailsService jdbcClientDetailsService() { 48 | // 基于 JDBC 实现,需要事先在数据库配置客户端信息 49 | return new JdbcClientDetailsService(dataSource()); 50 | } 51 | @Override 52 | public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { 53 | // 设置令牌存储模式 54 | endpoints.tokenStore(tokenStore()); 55 | } 56 | @Override 57 | public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 58 | // 客户端配置 59 | clients.withClientDetails(jdbcClientDetailsService()); 60 | } 61 | 62 | 63 | /*@Override 64 | public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 65 | // 配置客户端 66 | clients 67 | // 使用内存设置 68 | .inMemory() 69 | // client_id http://client:secret@localhost:8080/oauth/token 70 | .withClient("client") 71 | // client_secret http://client:secret@localhost:8080/oauth/token 72 | .secret(passwordEncoder.encode("secret")) 73 | // 授权类型 74 | .authorizedGrantTypes("authorization_code") 75 | // 授权范围 76 | .scopes("app") 77 | // 注册回调地址 78 | .redirectUris("https://www.baidu.com"); 79 | }*/ 80 | } 81 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-server/src/main/java/com/ktz/deploy/oauth2/server/configure/Secret.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.server.configure; 2 | 3 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 4 | 5 | /** 6 | * @ClassName Secret 7 | * @Description 8 | * @Author kaituozhesh 9 | * @Date 2020/3/16 15:20 10 | * @Version V1.0 11 | **/ 12 | public class Secret { 13 | public static void main(String[] args) { 14 | System.out.println(new BCryptPasswordEncoder().encode("secret")); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-server/src/main/java/com/ktz/deploy/oauth2/server/configure/UserDetailsServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.server.configure; 2 | 3 | import com.ktz.deploy.oauth2.server.domain.TbPermission; 4 | import com.ktz.deploy.oauth2.server.domain.TbUser; 5 | import com.ktz.deploy.oauth2.server.service.TbPermissionService; 6 | import com.ktz.deploy.oauth2.server.service.TbUserService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.security.core.GrantedAuthority; 9 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 10 | import org.springframework.security.core.userdetails.User; 11 | import org.springframework.security.core.userdetails.UserDetails; 12 | import org.springframework.security.core.userdetails.UserDetailsService; 13 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 14 | import org.springframework.stereotype.Service; 15 | import org.assertj.core.util.Lists; 16 | import java.util.List; 17 | 18 | /** 19 | * @Author kaituozhesh 20 | * @Description 自定义认证授权 21 | * @Date 10:26 2020/3/18 22 | */ 23 | @Service 24 | public class UserDetailsServiceImpl implements UserDetailsService { 25 | 26 | @Autowired 27 | private TbUserService tbUserService; 28 | @Autowired 29 | private TbPermissionService tbPermissionService; 30 | 31 | @Override 32 | public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException { 33 | TbUser tbUser = tbUserService.getByUsername(s); 34 | // 需要依赖test 35 | List grantedAuthorities = Lists.newArrayList(); 36 | if (tbUser != null) { 37 | List tbPermissions = tbPermissionService.selectByUserId(tbUser.getId()); 38 | tbPermissions.forEach(tbPermission -> { 39 | GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(tbPermission.getEnname()); 40 | grantedAuthorities.add(grantedAuthority); 41 | }); 42 | return new User(tbUser.getUsername(), tbUser.getPassword(), grantedAuthorities); 43 | } 44 | return null; 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-server/src/main/java/com/ktz/deploy/oauth2/server/configure/WebSecurityConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.server.configure; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 6 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 7 | import org.springframework.security.config.annotation.web.builders.WebSecurity; 8 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 9 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 10 | import org.springframework.security.core.userdetails.UserDetailsService; 11 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 12 | 13 | /** 14 | * @ClassName WebSecurityConfiguration 15 | * @Description 服务器安全配置 16 | * @Author kaituozhesh 17 | * @Date 2020/3/16 14:20 18 | * @Version V1.0 19 | **/ 20 | @Configuration 21 | @EnableWebSecurity 22 | // 全局方法拦截 23 | @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true) 24 | public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { 25 | 26 | /** 27 | * 配置默认加密方式 28 | * 通过浏览器访问 29 | * http://localhost:8080/oauth/authorize?client_id=client&response_type=code 30 | * 31 | * @return 32 | */ 33 | @Bean 34 | public BCryptPasswordEncoder passwordEncoder() { 35 | return new BCryptPasswordEncoder(); 36 | } 37 | 38 | @Bean 39 | @Override 40 | protected UserDetailsService userDetailsService() { 41 | return new UserDetailsServiceImpl(); 42 | } 43 | 44 | @Override 45 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 46 | // 使用自定义认证与授权 47 | auth.userDetailsService(userDetailsService()); 48 | } 49 | 50 | @Override 51 | public void configure(WebSecurity web) throws Exception { 52 | // 将 check_token 暴露出去,否则资源服务器访问时报 403 错误 53 | web.ignoring().antMatchers("/oauth/check_token"); 54 | } 55 | 56 | /*@Override 57 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 58 | // 在内存中创建用户 59 | auth.inMemoryAuthentication() 60 | .withUser("user").password(passwordEncoder().encode("123456")).roles("USER") 61 | .and() 62 | .withUser("admin").password(passwordEncoder().encode("admin888")).roles("ADMIN"); 63 | }*/ 64 | } 65 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-server/src/main/java/com/ktz/deploy/oauth2/server/domain/TbPermission.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.server.domain; 2 | 3 | 4 | import lombok.Data; 5 | 6 | import javax.persistence.Column; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.Id; 9 | import javax.persistence.Table; 10 | import java.io.Serializable; 11 | import java.util.Date; 12 | 13 | @Data 14 | @Table(name = "tb_permission") 15 | public class TbPermission implements Serializable { 16 | @Id 17 | @Column(name = "id") 18 | @GeneratedValue(generator = "JDBC") 19 | private Long id; 20 | 21 | /** 22 | * 父权限 23 | */ 24 | @Column(name = "parent_id") 25 | private Long parentId; 26 | 27 | /** 28 | * 权限名称 29 | */ 30 | @Column(name = "`name`") 31 | private String name; 32 | 33 | /** 34 | * 权限英文名称 35 | */ 36 | @Column(name = "enname") 37 | private String enname; 38 | 39 | /** 40 | * 授权路径 41 | */ 42 | @Column(name = "url") 43 | private String url; 44 | 45 | /** 46 | * 备注 47 | */ 48 | @Column(name = "description") 49 | private String description; 50 | 51 | @Column(name = "created") 52 | private Date created; 53 | 54 | @Column(name = "updated") 55 | private Date updated; 56 | 57 | private static final long serialVersionUID = 1L; 58 | } -------------------------------------------------------------------------------- /oauth2-environment/oauth2-server/src/main/java/com/ktz/deploy/oauth2/server/domain/TbUser.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.server.domain; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | import java.io.Serializable; 10 | import java.util.Date; 11 | 12 | @Data 13 | @Table(name = "tb_user") 14 | public class TbUser implements Serializable { 15 | @Id 16 | @Column(name = "id") 17 | @GeneratedValue(generator = "JDBC") 18 | private Long id; 19 | 20 | /** 21 | * 用户名 22 | */ 23 | @Column(name = "username") 24 | private String username; 25 | 26 | /** 27 | * 密码,加密存储 28 | */ 29 | @Column(name = "`password`") 30 | private String password; 31 | 32 | /** 33 | * 注册手机号 34 | */ 35 | @Column(name = "phone") 36 | private String phone; 37 | 38 | /** 39 | * 注册邮箱 40 | */ 41 | @Column(name = "email") 42 | private String email; 43 | 44 | @Column(name = "created") 45 | private Date created; 46 | 47 | @Column(name = "updated") 48 | private Date updated; 49 | 50 | private static final long serialVersionUID = 1L; 51 | } -------------------------------------------------------------------------------- /oauth2-environment/oauth2-server/src/main/java/com/ktz/deploy/oauth2/server/mapper/TbPermissionMapper.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.server.mapper; 2 | 3 | import com.ktz.deploy.oauth2.server.domain.TbPermission; 4 | import org.apache.ibatis.annotations.Param; 5 | import tk.mybatis.mapper.MyMapper; 6 | 7 | import java.util.List; 8 | 9 | public interface TbPermissionMapper extends MyMapper { 10 | List selectByUserId(@Param("id") Long id); 11 | } 12 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-server/src/main/java/com/ktz/deploy/oauth2/server/mapper/TbUserMapper.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.server.mapper; 2 | 3 | 4 | import com.ktz.deploy.oauth2.server.domain.TbUser; 5 | import tk.mybatis.mapper.MyMapper; 6 | 7 | public interface TbUserMapper extends MyMapper { 8 | } -------------------------------------------------------------------------------- /oauth2-environment/oauth2-server/src/main/java/com/ktz/deploy/oauth2/server/service/TbPermissionService.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.server.service; 2 | 3 | import com.ktz.deploy.oauth2.server.domain.TbPermission; 4 | 5 | import java.util.List; 6 | 7 | public interface TbPermissionService{ 8 | 9 | List selectByUserId(Long id); 10 | } 11 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-server/src/main/java/com/ktz/deploy/oauth2/server/service/TbUserService.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.server.service; 2 | 3 | 4 | import com.ktz.deploy.oauth2.server.domain.TbUser; 5 | 6 | public interface TbUserService{ 7 | 8 | TbUser getByUsername(String username); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-server/src/main/java/com/ktz/deploy/oauth2/server/service/impl/TbPermissionServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.server.service.impl; 2 | 3 | import com.ktz.deploy.oauth2.server.domain.TbPermission; 4 | import com.ktz.deploy.oauth2.server.mapper.TbPermissionMapper; 5 | import com.ktz.deploy.oauth2.server.service.TbPermissionService; 6 | import org.springframework.stereotype.Service; 7 | 8 | import javax.annotation.Resource; 9 | import java.util.List; 10 | 11 | @Service 12 | public class TbPermissionServiceImpl implements TbPermissionService { 13 | 14 | @Resource 15 | private TbPermissionMapper tbPermissionMapper; 16 | 17 | @Override 18 | public List selectByUserId(Long id) { 19 | return tbPermissionMapper.selectByUserId(id); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-server/src/main/java/com/ktz/deploy/oauth2/server/service/impl/TbUserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.oauth2.server.service.impl; 2 | 3 | import com.ktz.deploy.oauth2.server.domain.TbUser; 4 | import com.ktz.deploy.oauth2.server.mapper.TbUserMapper; 5 | import com.ktz.deploy.oauth2.server.service.TbUserService; 6 | import org.springframework.stereotype.Service; 7 | import tk.mybatis.mapper.entity.Example; 8 | 9 | import javax.annotation.Resource; 10 | 11 | @Service 12 | public class TbUserServiceImpl implements TbUserService { 13 | 14 | @Resource 15 | private TbUserMapper tbUserMapper; 16 | 17 | @Override 18 | public TbUser getByUsername(String username) { 19 | Example example = new Example(TbUser.class); 20 | example.createCriteria().andEqualTo("username",username); 21 | return tbUserMapper.selectOneByExample(example); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-server/src/main/java/tk/mybatis/mapper/MyMapper.java: -------------------------------------------------------------------------------- 1 | package tk.mybatis.mapper; 2 | 3 | import tk.mybatis.mapper.common.Mapper; 4 | import tk.mybatis.mapper.common.MySqlMapper; 5 | 6 | public interface MyMapper extends Mapper, MySqlMapper { 7 | } 8 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | type: com.zaxxer.hikari.HikariDataSource 4 | driver-class-name: com.mysql.cj.jdbc.Driver 5 | jdbcUrl: jdbc:mysql://localhost:3306/oauth?characterEncoding=utf8&useUnicode=true&useSSL=false&useTimezone=true&serverTimezone=GMT%2B8 6 | username: root 7 | password: root 8 | hikari: 9 | minimum-idle: 5 10 | idle-timeout: 600000 11 | maximum-pool-size: 10 12 | auto-commit: true 13 | pool-name: MyHikariCP 14 | max-lifetime: 1800000 15 | connection-timeout: 30000 16 | connection-test-query: SELECT 1 17 | server: 18 | port: 8080 19 | 20 | mybatis: 21 | type-aliases-package: com.ktz.deploy.oauth2.server.domain 22 | mapper-locations: classpath:mapper/*.xml 23 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-server/src/main/resources/mapper/TbPermissionMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | id, parent_id, `name`, enname, url, description, created, updated 19 | 20 | 31 | -------------------------------------------------------------------------------- /oauth2-environment/oauth2-server/src/main/resources/mapper/TbUserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | id, username, `password`, phone, email, created, updated 18 | 19 | -------------------------------------------------------------------------------- /oauth2-environment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 2.1.6.RELEASE 10 | 11 | 12 | com.ktz.deploy 13 | oauth2-environment 14 | 1.0-SNAPSHOT 15 | pom 16 | 17 | oauth2-server 18 | oauth2-resource 19 | 20 | 21 | Greenwich.RELEASE 22 | ${java.version} 23 | ${java.version} 24 | UTF-8 25 | UTF-8 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.cloud 32 | spring-cloud-dependencies 33 | ${spring-cloud.version} 34 | pom 35 | import 36 | 37 | 38 | 39 | 40 | 41 | 42 | spring-milestone 43 | Spring Milestone 44 | https://repo.spring.io/milestone 45 | 46 | false 47 | 48 | 49 | 50 | spring-snapshot 51 | Spring Snapshot 52 | https://repo.spring.io/snapshot 53 | 54 | true 55 | 56 | 57 | 58 | 59 | 60 | spring-milestone 61 | Spring Milestone 62 | https://repo.spring.io/milestone 63 | 64 | false 65 | 66 | 67 | 68 | spring-snapshot 69 | Spring Snapshot 70 | https://repo.spring.io/snapshot 71 | 72 | true 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /redis-environment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.5.RELEASE 9 | 10 | 11 | com.ktz.deploy 12 | redis-environment 13 | 0.0.1-SNAPSHOT 14 | redis-environment 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-data-redis 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | 32 | org.apache.commons 33 | commons-pool2 34 | 35 | 36 | 37 | com.alibaba 38 | fastjson 39 | 1.2.62 40 | 41 | 42 | org.projectlombok 43 | lombok 44 | true 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-maven-plugin 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /redis-environment/src/main/java/com/ktz/deploy/redis/RedisEnvironmentApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.redis; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * Description: 8 | * 9 | * @author kaituozhe_sh 10 | */ 11 | @SpringBootApplication 12 | public class RedisEnvironmentApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(RedisEnvironmentApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /redis-environment/src/main/java/com/ktz/deploy/redis/config/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.redis.config; 2 | 3 | import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.data.redis.connection.RedisConnectionFactory; 8 | import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; 9 | import org.springframework.data.redis.core.RedisTemplate; 10 | import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; 11 | import org.springframework.data.redis.serializer.StringRedisSerializer; 12 | 13 | import javax.annotation.PostConstruct; 14 | import java.io.Serializable; 15 | 16 | /** 17 | * ClassName: RedisConfig 18 | * Description: 19 | * date: 2020/3/8 11:07 20 | * 21 | * @author kaituozhe_sh 22 | */ 23 | @Configuration 24 | public class RedisConfig { 25 | /** 26 | * 方式一: 27 | * 默认情况下RedisTemplate模板只能支持字符串,我们自定义一个RedisTemplate,设置序列化器,这样我们可以很方便的操作实例对象 28 | * 29 | * @param connectionFactory 30 | * @return 31 | */ 32 | @Bean 33 | public RedisTemplate redisTemplate(LettuceConnectionFactory connectionFactory) { 34 | RedisTemplate redisTemplate = new RedisTemplate<>(); 35 | redisTemplate.setKeySerializer(new StringRedisSerializer()); 36 | redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); 37 | redisTemplate.setConnectionFactory(connectionFactory); 38 | return redisTemplate; 39 | } 40 | 41 | 42 | @Autowired 43 | protected RedisTemplate redisTemplate; 44 | @Autowired 45 | protected RedisConnectionFactory factory; 46 | 47 | /** 48 | * 方式二: 49 | * 50 | * @PostConstruct:用来修饰非静态void()方法。被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器执行一次。PostConstruct在构造函数之后执行,init()方法之前执行 通常我们会是在Spring框架中使用到@PostConstruct注解,该注解的方法在整个Bean初始化中的执行顺序 51 | * Constructor(构造方法) -> @Autowired(依赖注入) -> @PostConstruct(注解的方法) 52 | */ 53 | @PostConstruct 54 | public void init() { 55 | redisTemplate.setKeySerializer(new StringRedisSerializer()); 56 | redisTemplate.setHashKeySerializer(new StringRedisSerializer()); 57 | redisTemplate.setValueSerializer(new FastJsonRedisSerializer<>(Object.class)); 58 | redisTemplate.setHashKeySerializer(new FastJsonRedisSerializer<>(Object.class)); 59 | redisTemplate.setConnectionFactory(factory); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /redis-environment/src/main/java/com/ktz/deploy/redis/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.redis.entity; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 4 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 5 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; 6 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; 7 | import lombok.AllArgsConstructor; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | import lombok.ToString; 11 | 12 | import java.time.LocalDateTime; 13 | 14 | /** 15 | * ClassName: User 16 | * Description: 17 | * date: 2020/3/8 11:07 18 | * 19 | * @author kaituozhe_sh 20 | */ 21 | @Data 22 | @ToString 23 | @AllArgsConstructor 24 | @NoArgsConstructor 25 | public class User { 26 | private Long id; 27 | private String name; 28 | /** 29 | * 存储到redis数据中如果包括日期(LocalDateTime),则从redis读取解析数据时可能存在报错,无法实现LocalDateTime日期的反序列化操作,需要添加上两个注解 30 | */ 31 | @JsonDeserialize(using = LocalDateTimeDeserializer.class) 32 | @JsonSerialize(using = LocalDateTimeSerializer.class) 33 | private LocalDateTime time; 34 | } 35 | -------------------------------------------------------------------------------- /redis-environment/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | redis: 3 | host: # Redis服务器地址 4 | port: 6379 # Redis服务器端口 5 | database: 0 # 数据库索引 6 | password: ktz_sh # Redis服务器连接密码 7 | timeout: 3000 # Redis连接超时时间 8 | # jedis是直连模式,在多个线程间共享一个Jedis实例是线程不安全的,每个线程都去拿自己的Jedis实例,当连接数量增多时,物理连接成本就较高了 9 | # lettuce的连接是基于Netty的,连接实例可以在多个线程间共享,大致意思就是一个多线程的应用可以使用同一个连接实例,而不用担心并发线程的数量。通过异步的方式可以让我们更好地利用系统资源 10 | lettuce: 11 | pool: 12 | max-idle: 300 # 连接池中的最大空闲连接 默认 8 13 | min-idle: 5 # 连接池中的最小空闲连接 默认 0 14 | max-active: 600 # 连接池最大连接数(使用负值表示没有限制)默认 8 15 | max-wait: 10000 # 连接池最大阻塞等待时间(使用负值表示没有限制) 默认 -1 16 | -------------------------------------------------------------------------------- /redisson-environment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.5.RELEASE 9 | 10 | 11 | com.ktz.deploy 12 | redisson-environment 13 | 0.0.1-SNAPSHOT 14 | redisson-environment 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | 24 | org.redisson 25 | redisson 26 | 3.6.5 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-data-redis 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-web 37 | 38 | 39 | 40 | 41 | 42 | org.apache.commons 43 | commons-pool2 44 | 45 | 46 | 47 | com.alibaba 48 | fastjson 49 | 1.2.62 50 | 51 | 52 | org.projectlombok 53 | lombok 54 | true 55 | 56 | 57 | 58 | 59 | 60 | 61 | org.springframework.boot 62 | spring-boot-maven-plugin 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /redisson-environment/src/main/java/com/ktz/deploy/redisson/RedissonEnvironmentApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.redisson; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class RedissonEnvironmentApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(RedissonEnvironmentApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /redisson-environment/src/main/java/com/ktz/deploy/redisson/config/RedissonConfig.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.redisson.config; 2 | 3 | import org.redisson.Redisson; 4 | import org.redisson.api.RedissonClient; 5 | import org.redisson.config.Config; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.boot.autoconfigure.data.redis.RedisProperties; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * ClassName: RedissonConfig 16 | * Description: 17 | * date: 2020/3/9 10:31 18 | * 19 | * @author kaituozhe_sh 20 | */ 21 | @Configuration 22 | public class RedissonConfig { 23 | 24 | @Autowired 25 | private RedisProperties redisProperties; 26 | 27 | @Value("${spring.redis.pattern}") 28 | private String pattern; 29 | 30 | @Bean 31 | public RedissonClient getRedisson() { 32 | Config config = new Config(); 33 | if ("single".equals(pattern)) { 34 | StringBuilder builder = new StringBuilder("redis://"); 35 | builder.append(redisProperties.getHost()) 36 | .append(":") 37 | .append(redisProperties.getPort()); 38 | config.useSingleServer() 39 | .setAddress(builder.toString()) 40 | .setPassword(redisProperties.getPassword()) 41 | .setDatabase(redisProperties.getDatabase()); 42 | } else if ("cluster".equals(pattern)) { 43 | RedisProperties.Cluster cluster = redisProperties.getCluster(); 44 | List nodes = cluster.getNodes(); 45 | String[] strings = listToArray(nodes); 46 | config.useClusterServers() 47 | .setScanInterval(2000) 48 | .addNodeAddress(strings) 49 | .setPassword(redisProperties.getPassword()); 50 | } 51 | return Redisson.create(config); 52 | } 53 | 54 | private String[] listToArray(List list) { 55 | if (null == list || list.size() <= 0) { 56 | return new String[0]; 57 | } 58 | String[] r = new String[list.size()]; 59 | for (int i = 0; i < list.size(); i++) { 60 | r[i] = "redis://" + list.get(i); 61 | } 62 | return r; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /redisson-environment/src/main/java/com/ktz/deploy/redisson/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.redisson.controller; 2 | 3 | import com.ktz.deploy.redisson.service.OrderService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * ClassName: OrderController 10 | * Description: 11 | * date: 2020/3/9 10:55 12 | * 13 | * @author kaituozhe_sh 14 | */ 15 | @RestController 16 | public class OrderController { 17 | 18 | 19 | @Autowired 20 | private OrderService orderService; 21 | 22 | @GetMapping("/order_lock") 23 | public String orderLock() { 24 | return this.orderService.order(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /redisson-environment/src/main/java/com/ktz/deploy/redisson/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.redisson.service; 2 | 3 | /** 4 | * ClassName: OrderService 5 | * Description: 6 | * date: 2020/3/9 10:42 7 | * 8 | * @author kaituozhe_sh 9 | */ 10 | public interface OrderService { 11 | 12 | String order(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /redisson-environment/src/main/java/com/ktz/deploy/redisson/service/impl/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.redisson.service.impl; 2 | 3 | import com.ktz.deploy.redisson.config.RedissonConfig; 4 | import com.ktz.deploy.redisson.service.OrderService; 5 | import org.redisson.api.RLock; 6 | import org.redisson.api.RedissonClient; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.data.redis.core.StringRedisTemplate; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.concurrent.TimeUnit; 12 | 13 | /** 14 | * ClassName: OrderServiceImpl 15 | * Description: 16 | * date: 2020/3/9 10:48 17 | * 18 | * @author kaituozhe_sh 19 | */ 20 | @Service 21 | public class OrderServiceImpl implements OrderService { 22 | 23 | @Autowired 24 | private RedissonClient redissonClient; 25 | @Autowired 26 | private StringRedisTemplate stringRedisTemplate; 27 | 28 | @Override 29 | public String order() { 30 | RLock lock = redissonClient.getLock("lock"); 31 | try { 32 | if (lock.tryLock(5, 2 * 60, TimeUnit.SECONDS)) { 33 | return this.decrementOrder(); 34 | } else { 35 | System.out.println("锁获取超时(5s)"); 36 | return "timeout"; 37 | } 38 | } catch (Exception e) { 39 | e.printStackTrace(); 40 | return "error"; 41 | } finally { 42 | if (null != lock) { 43 | lock.unlock(); 44 | } 45 | } 46 | } 47 | 48 | private String decrementOrder() { 49 | Long count = Long.valueOf(stringRedisTemplate.opsForValue().get("count")); 50 | if (count <= 0) { 51 | return "库存不足"; 52 | } else { 53 | count = this.stringRedisTemplate.opsForValue().decrement("count"); 54 | } 55 | System.out.println("==================库存还剩{" + count + "}个================"); 56 | return String.valueOf(count); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /redisson-environment/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | redis: 3 | pattern: single 4 | host: 127.0.0.1 # Redis\u670D\u52A1\u5668\u5730\u5740 5 | port: 6379 # Redis\u670D\u52A1\u5668\u7AEF\u53E3 6 | database: 0 # \u6570\u636E\u5E93\u7D22\u5F15 7 | password: ktz_sh # Redis\u670D\u52A1\u5668\u8FDE\u63A5\u5BC6\u7801 8 | timeout: 3000 # Redis\u8FDE\u63A5\u8D85\u65F6\u65F6\u95F4 9 | # jedis\u662F\u76F4\u8FDE\u6A21\u5F0F\uFF0C\u5728\u591A\u4E2A\u7EBF\u7A0B\u95F4\u5171\u4EAB\u4E00\u4E2AJedis\u5B9E\u4F8B\u662F\u7EBF\u7A0B\u4E0D\u5B89\u5168\u7684\uFF0C\u6BCF\u4E2A\u7EBF\u7A0B\u90FD\u53BB\u62FF\u81EA\u5DF1\u7684Jedis\u5B9E\u4F8B\uFF0C\u5F53\u8FDE\u63A5\u6570\u91CF\u589E\u591A\u65F6\uFF0C\u7269\u7406\u8FDE\u63A5\u6210\u672C\u5C31\u8F83\u9AD8\u4E86 10 | # lettuce\u7684\u8FDE\u63A5\u662F\u57FA\u4E8ENetty\u7684\uFF0C\u8FDE\u63A5\u5B9E\u4F8B\u53EF\u4EE5\u5728\u591A\u4E2A\u7EBF\u7A0B\u95F4\u5171\u4EAB\uFF0C\u5927\u81F4\u610F\u601D\u5C31\u662F\u4E00\u4E2A\u591A\u7EBF\u7A0B\u7684\u5E94\u7528\u53EF\u4EE5\u4F7F\u7528\u540C\u4E00\u4E2A\u8FDE\u63A5\u5B9E\u4F8B\uFF0C\u800C\u4E0D\u7528\u62C5\u5FC3\u5E76\u53D1\u7EBF\u7A0B\u7684\u6570\u91CF\u3002\u901A\u8FC7\u5F02\u6B65\u7684\u65B9\u5F0F\u53EF\u4EE5\u8BA9\u6211\u4EEC\u66F4\u597D\u5730\u5229\u7528\u7CFB\u7EDF\u8D44\u6E90 11 | lettuce: 12 | pool: 13 | max-idle: 300 # \u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5927\u7A7A\u95F2\u8FDE\u63A5 \u9ED8\u8BA4 8 14 | min-idle: 5 # \u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5C0F\u7A7A\u95F2\u8FDE\u63A5 \u9ED8\u8BA4 0 15 | max-active: 600 # \u8FDE\u63A5\u6C60\u6700\u5927\u8FDE\u63A5\u6570\uFF08\u4F7F\u7528\u8D1F\u503C\u8868\u793A\u6CA1\u6709\u9650\u5236\uFF09\u9ED8\u8BA4 8 16 | max-wait: 10000 # \u8FDE\u63A5\u6C60\u6700\u5927\u963B\u585E\u7B49\u5F85\u65F6\u95F4\uFF08\u4F7F\u7528\u8D1F\u503C\u8868\u793A\u6CA1\u6709\u9650\u5236\uFF09 \u9ED8\u8BA4 -1 17 | -------------------------------------------------------------------------------- /swagger-environment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.5.RELEASE 9 | 10 | 11 | com.ktz.deploy 12 | swagger-environment 13 | 0.0.1-SNAPSHOT 14 | swagger-environment 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | 28 | 29 | io.springfox 30 | springfox-swagger2 31 | 2.4.0 32 | 33 | 34 | io.springfox 35 | springfox-swagger-ui 36 | 2.4.0 37 | 38 | 39 | com.github.xiaoymin 40 | swagger-bootstrap-ui 41 | 1.6 42 | 43 | 44 | 45 | org.projectlombok 46 | lombok 47 | true 48 | 49 | 50 | 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-maven-plugin 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /swagger-environment/src/main/java/com/ktz/deploy/swagger/SwaggerEnvironmentApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.swagger; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SwaggerEnvironmentApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SwaggerEnvironmentApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /swagger-environment/src/main/java/com/ktz/deploy/swagger/config/Swagger2.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.swagger.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.ApiInfoBuilder; 6 | import springfox.documentation.builders.PathSelectors; 7 | import springfox.documentation.builders.RequestHandlerSelectors; 8 | import springfox.documentation.service.ApiInfo; 9 | import springfox.documentation.service.Contact; 10 | import springfox.documentation.spi.DocumentationType; 11 | import springfox.documentation.spring.web.plugins.Docket; 12 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 13 | 14 | /** 15 | * ClassName: Swagger2 16 | * Description: 17 | * date: 2020/3/9 8:52 18 | * 19 | * @author kaituozhe_sh 20 | */ 21 | @Configuration 22 | @EnableSwagger2 23 | public class Swagger2 { 24 | 25 | @Bean 26 | public Docket createRestApi() { 27 | return new Docket(DocumentationType.SWAGGER_2) 28 | .apiInfo(apiInfo()) 29 | .select() 30 | .apis(RequestHandlerSelectors.basePackage("com.ktz.deploy.swagger.controller")) 31 | .paths(PathSelectors.any()) 32 | .build(); 33 | } 34 | 35 | private ApiInfo apiInfo() { 36 | return new ApiInfoBuilder() 37 | .title("文档页标题") 38 | .contact(new Contact("a", "b", "c")) 39 | .description("详细信息") 40 | .version("1.0.1") 41 | .termsOfServiceUrl("网站地址") 42 | .build(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /swagger-environment/src/main/java/com/ktz/deploy/swagger/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.swagger.controller; 2 | 3 | import com.ktz.deploy.swagger.entity.User; 4 | import io.swagger.annotations.Api; 5 | import io.swagger.annotations.ApiImplicitParam; 6 | import io.swagger.annotations.ApiImplicitParams; 7 | import io.swagger.annotations.ApiOperation; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | /** 11 | * @Api():注解类 12 | * tags:描述Controller的作用 13 | * @ApiOperation():注解方法 14 | * value:具体说明接口的作用 15 | * notes:接口方法备注 16 | * @ApiImplicitParams():注解接口方法,描述一组请求参数,可以包含多个@ApiImplicitParam() 17 | * @ApiImplicitParam():注解接口方法,描述一个具体的请求参数 18 | * name:请求参数名 19 | * value:请求参数描述 20 | * required:是否必传 21 | * paramType:参数放在哪个地方 22 | * header:请求参数的获取:@RequestHeader 23 | * query:请求参数的获取:@RequestParam 24 | * path(用于restful接口):请求参数的获取:@PathVariable 25 | * dataType:参数类型,默认String,其他值dataType="Integer" 26 | * defaultValue:默认值 27 | * @ApiResponses():注释接口方法,描述一组HTTP返回值,可以包含多个ApiResponse() 28 | * @ApiResponse():注释接口方法,描述一个HTTP响应信息 29 | * code:HTTP返回值 30 | * message:返回信息 31 | * response:抛出异常的类 32 | * @ApiModel():注解Model,描述响应数据Model类 33 | * @ApiModelProperty():注解属性,描述响应Model类的属性 34 | * @ApiIgnore():注解类,表示忽略这个Api 35 | */ 36 | @RestController 37 | @Api(tags = "用户管理相关接口") 38 | @RequestMapping("/user") 39 | public class UserController { 40 | 41 | @PostMapping("/add_user") 42 | @ApiOperation(value = "添加用户的接口", notes = "添加用户的接口") 43 | @ApiImplicitParams({ 44 | @ApiImplicitParam(name = "username", value = "用户名", defaultValue = "李四"), 45 | @ApiImplicitParam(name = "address", value = "用户地址", defaultValue = "深圳", required = true) 46 | } 47 | ) 48 | public String addUser(String username, String address) { 49 | return username + " " + address; 50 | } 51 | 52 | @GetMapping("/find_user") 53 | @ApiOperation("根据id查询用户的接口") 54 | @ApiImplicitParam(name = "id", value = "用户id", defaultValue = "99", required = true) 55 | public User getUserById(@PathVariable Integer id) { 56 | User user = new User(); 57 | user.setId(id); 58 | return user; 59 | } 60 | 61 | @PutMapping("/{id}") 62 | @ApiOperation("根据id更新用户的接口") 63 | public User updateUserById(@RequestBody User user) { 64 | return user; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /swagger-environment/src/main/java/com/ktz/deploy/swagger/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.swagger.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | /** 8 | * ClassName: User 9 | * Description: 10 | * date: 2020/3/9 9:06 11 | * 12 | * @author kaituozhe_sh 13 | */ 14 | @Data 15 | @ApiModel(value = "用户模型") 16 | public class User { 17 | @ApiModelProperty("用户ID") 18 | private Integer id; 19 | } 20 | -------------------------------------------------------------------------------- /swagger-environment/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /undertow-environment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.5.RELEASE 9 | 10 | 11 | com.ktz.deploy 12 | undertow-environment 13 | 0.0.1-SNAPSHOT 14 | undertow-environment 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-tomcat 29 | 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-undertow 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-maven-plugin 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /undertow-environment/src/main/java/com/ktz/deploy/undertow/UndertowEnvironmentApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.undertow; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * Description: 8 | * 9 | * @author kaituozhe_sh 10 | */ 11 | @SpringBootApplication 12 | public class UndertowEnvironmentApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(UndertowEnvironmentApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /undertow-environment/src/main/java/com/ktz/deploy/undertow/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.undertow.controller; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * ClassName: HelloController 9 | * Description: 10 | * date: 2020/3/8 10:18 11 | * 12 | * @author kaituozhe_sh 13 | */ 14 | @RestController 15 | @RequestMapping("/index") 16 | public class HelloController { 17 | 18 | @GetMapping("/hello") 19 | public String hello() { 20 | return "Hello Undertow"; 21 | } 22 | 23 | } 24 | 25 | -------------------------------------------------------------------------------- /undertow-environment/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | undertow: 3 | accesslog: 4 | dir: logs # 日志存放目录 5 | enabled: false # 是否启动日志 6 | pattern: common # 日志格式 7 | prefix: access_log # 日志文件名前缀 8 | suffix: log # 日志文件名后缀 9 | io-threads: 16 # 设置IO线程数,它主要执行非阻塞任务,它们会负责多个连接,默认设置每个CPU核心一个线程,不要设置过大 10 | worker-threads: 256 # 阻塞任务线程池,当执行类似servlet请求阻塞IO操作,undertow会从这个线程池中取得线程,它的值设置取决于系统线程执行任务的阻塞系数,默认值是IO线程数* 8 11 | buffer-size: 1024 # 这个配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似Netty的池化内存管理,每块buffer的空间大小,越小的空间被利用越充分,不要设置太大,以免影响其他应用 12 | direct-buffers: true # 是否分配直接内存(NIO直接分配堆外内存) 13 | max-http-post-size: 0 # HTTP POST 请求最大的大小 14 | -------------------------------------------------------------------------------- /websocket-environment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 2.2.6.RELEASE 10 | 11 | 12 | org.example 13 | websocket-environment 14 | 1.0-SNAPSHOT 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter-web 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-websocket 24 | 25 | 26 | org.projectlombok 27 | lombok 28 | true 29 | 30 | 31 | com.alibaba 32 | fastjson 33 | 1.2.44 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /websocket-environment/src/main/java/com/ktz/deploy/websocket/WebsocketApplication.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.websocket; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @ClassName : WebsocketApplication 8 | * @Description : 9 | * @Author : kaituozhesh 10 | * @Date: 2020-06-26 12:13 11 | * @Version: 1.0.0 12 | */ 13 | @SpringBootApplication 14 | public class WebsocketApplication { 15 | public static void main(String[] args) { 16 | SpringApplication.run(WebsocketApplication.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /websocket-environment/src/main/java/com/ktz/deploy/websocket/config/WebsocketConfig.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.websocket.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.socket.server.standard.ServerEndpointExporter; 6 | 7 | /** 8 | * @ClassName : WebsocketConfig 9 | * @Description : 10 | * @Author : kaituozhesh 11 | * @Date: 2020-06-26 12:17 12 | * @Version: 1.0.0 13 | */ 14 | @Configuration 15 | public class WebsocketConfig { 16 | /** 17 | * 用于扫描带有@ServerEndpoint的注解成为websocket 18 | * 19 | * @return 20 | */ 21 | @Bean 22 | public ServerEndpointExporter serverEndpointExporter() { 23 | return new ServerEndpointExporter(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /websocket-environment/src/main/java/com/ktz/deploy/websocket/controller/WsController.java: -------------------------------------------------------------------------------- 1 | package com.ktz.deploy.websocket.controller; 2 | 3 | import com.ktz.deploy.websocket.config.WebsocketServer; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PostMapping; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | import org.springframework.web.bind.annotation.RestController; 8 | import org.springframework.web.socket.client.WebSocketClient; 9 | 10 | import java.io.IOException; 11 | import java.net.Socket; 12 | 13 | 14 | /** 15 | * @ClassName : WsController 16 | * @Description : 17 | * @Author : kaituozhesh 18 | * @Date: 2020-06-26 14:44 19 | * @Version: 1.0.0 20 | */ 21 | @RestController 22 | public class WsController { 23 | @PostMapping("/push") 24 | public String push(@RequestParam String message, @RequestParam String userId) { 25 | try { 26 | WebsocketServer.sendInfo(message, userId); 27 | return "Message send success!"; 28 | } catch (IOException e) { 29 | return "Message send fail"; 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /websocket-environment/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9001 --------------------------------------------------------------------------------