Skip to content

Repository files navigation

common

pom

<dependencies>
<dependency>
<groupId>com.github.yaoguoh</groupId>
<artifactId>common</artifactId>
<version>3.4.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>

common-util

pom

<dependency>
<groupId>com.github.yaoguoh</groupId>
<artifactId>common-util</artifactId>
</dependency>
  • Result 返回对象
  • ResultGenerator 返回对象构造器

example

publicclassExampleController {
/** * 查询用户角色列表 * * @param realm the realm * @param userId the user id * @return the result */@Operation(summary = "查询用户角色列表")
@GetMapping(value = "/{userId}/roles")
publicResult<List<IdNameVO>> findUserRoles(@RequestHeader("realm") Stringrealm, @Parameter(name = "userId", description = "用户ID(唯一标识)", required = true) @PathVariable("userId") StringuserId) {
log.debug("findUserRoles - 查询用户角色列表. realm = [{}] username = [{}]", realm, userId);
returnResultGenerator.ok(userService.findUserRoles(realm, userId));
}
}

common-elasticsearch

pom

<dependency>
<groupId>com.github.yaoguoh</groupId>
<artifactId>common-elasticsearch</artifactId>
</dependency>
  • ElasticsearchPropertiesRestHighLevelClient 客户端连接信息
  • RestHighLevelClientConfiguration 注册 restHighLevelClientBean处理elasticsearch server访问协议为https

Spring Boot Application @Configuration配置类 引入 RestHighLevelClientConfiguration.class

/** * 应用配置置类 */@Configuration@Import(RestHighLevelClientConfiguration.class)
publicclassProviderConfiguration {
}

yaml中添加配置信息

elasticsearch:
xpack-username: 'elastic'xpack-password: password'keystore: example.elasticsearch.com.jkskeystore-password: passwordhost: example.elasticsearch.comport: 443scheme: https

common-jpa

pom

<dependency>
<groupId>com.github.yaoguoh</groupId>
<artifactId>common-jpa</artifactId>
</dependency>
  • IService 通用接口
  • BaseService 通用接口实现

example

/** * User repository */publicinterfaceUserRepositoryextendsJpaRepository<User, Long>, JpaSpecificationExecutor<User> {
}
/** * The interface User service. */publicinterfaceUserServiceextendsIService<User, Long> {
}
/** * User service impl. */@Slf4j@ServicepublicclassUserServiceImplextendsBaseService<User, Long> implementsUserService {
}

common-redis

pom

<dependency>
<groupId>com.github.yaoguoh</groupId>
<artifactId>common-redis</artifactId>
</dependency>

common-spring-cloud

pom

<dependency>
<groupId>com.github.yaoguoh</groupId>
<artifactId>common-spring-cloud</artifactId>
</dependency>

Spring Cloud服务基础依赖pom包含内容如下

<dependencies>
<!-- Consul -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-config</artifactId>
</dependency>
<!-- Bootstrap -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<!-- Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>

common-exception

pom

<dependency>
<groupId>com.github.yaoguoh</groupId>
<artifactId>common-exception</artifactId>
</dependency>

common-doc

pom

<dependency>
<groupId>com.github.yaoguoh</groupId>
<artifactId>common-doc</artifactId>
</dependency>

Configuration

@Configuration@Import({DocConfiguration.class})
publicclassProviderConfiguration {
}

example yaml

doc:
info:
title: '应用服务'description: '应用服务 RESTFUL API'serverUrl: gateway.example.com

common-job

pom

<dependency>
<groupId>com.github.yaoguoh</groupId>
<artifactId>common-job</artifactId>
</dependency>

Configuration

@Configuration@Import({JobConfiguration.class})
publicclassProviderConfiguration {
}

example yaml

job:
admin-addresses: http://127.0.0.1:8080access-token:
executor:
app-name: example-executoraddress:
ip:
port: 0auditLog-path: /tmp/dataauditLog-retention-days: 30

common-log

pom

<dependency>
<groupId>com.github.yaoguoh</groupId>
<artifactId>common-log</artifactId>
</dependency>

example @Log

publicclassExampleController {
/** * 用户创建 * * @param realm the realm * @param userDTO the user dto * @return the result */@Log(module = "用户管理", businessType = BusinessType.INSERT)
@Operation(summary = "用户创建")
@PostMapping("/create")
publicResult<Object> create(@RequestHeader("realm") Stringrealm, @RequestBodyUserDTOuserDTO) {
log.debug("create - 用户创建. realm=[{}] UserDTO=[{}]", realm, userDTO);
userService.create(realm, userDTO);
returnResultGenerator.ok();
}
}

About

Spring Boot project common

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages