Skip to content

Commit e6ae632

Browse files
committed
✅ 创建grace测试示例项目
1 parent 5152fd4 commit e6ae632

File tree

7 files changed

+134
-0
lines changed

7 files changed

+134
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>api-boot-samples</artifactId>
7+
<groupId>org.minbox.framework</groupId>
8+
<version>${revision}</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>api-boot-sample-grace</artifactId>
13+
14+
<properties>
15+
<maven.compiler.source>8</maven.compiler.source>
16+
<maven.compiler.target>8</maven.compiler.target>
17+
</properties>
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter-web</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.minbox.framework</groupId>
25+
<artifactId>api-boot-starter-grace</artifactId>
26+
</dependency>
27+
</dependencies>
28+
<dependencyManagement>
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.minbox.framework</groupId>
32+
<artifactId>api-boot-dependencies</artifactId>
33+
<version>${api-boot.version}</version>
34+
<type>pom</type>
35+
<scope>import</scope>
36+
</dependency>
37+
</dependencies>
38+
</dependencyManagement>
39+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.minbox.framework.sample.grace;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.boot.SpringApplication;
6+
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
8+
/**
9+
* @author 恒宇少年
10+
*/
11+
@SpringBootApplication
12+
public class ApiBootSampleGraceApplication {
13+
/**
14+
* logger instance
15+
*/
16+
static Logger logger = LoggerFactory.getLogger(ApiBootSampleGraceApplication.class);
17+
18+
public static void main(String[] args) {
19+
SpringApplication.run(ApiBootSampleGraceApplication.class, args);
20+
logger.info("Grace测试服务启动成功.");
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.minbox.framework.sample.grace;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.minbox.framework.grace.processor.GraceLogObject;
5+
import org.minbox.framework.grace.processor.GraceLogStorageProcessor;
6+
import org.springframework.stereotype.Service;
7+
8+
/**
9+
* 日志持久化处理类
10+
*
11+
* @author 恒宇少年
12+
*/
13+
@Service
14+
@Slf4j
15+
public class ApiBootSampleGraceLogStorageProcessor implements GraceLogStorageProcessor {
16+
@Override
17+
public void storage(GraceLogObject graceLogObject) {
18+
log.info("位置:{},日志内容:{}.", graceLogObject.getGeneratedLocation(), graceLogObject.getContent());
19+
// 更多字段参考GraceLogObject
20+
}
21+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.minbox.framework.sample.grace;
2+
3+
import org.minbox.framework.grace.expression.annotation.GraceRecorder;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
import org.springframework.web.bind.annotation.RestController;
6+
7+
/**
8+
* @author 恒宇少年
9+
*/
10+
@RestController
11+
public class IndexController {
12+
/**
13+
* 测试记录日志
14+
* 注意:jdk1.8及之前的版本使用"#p?"的方式来获取值,?为参数索引,从0开始,jdk1.8以上版本可以使用"#参数名"获取值
15+
* <p>
16+
* "#reverseString()"方法定义在{@link StringUtils#reverseString}
17+
*
18+
* @param name
19+
* @return
20+
*/
21+
@GetMapping
22+
@GraceRecorder(category = "测试分组", success = "名称:{#p0},返回值:{#result},反转后:{#reverseString(#p0)}")
23+
public String index(String name) {
24+
return "Hello," + name;
25+
}
26+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.minbox.framework.sample.grace;
2+
3+
import org.minbox.framework.grace.expression.annotation.GraceFunction;
4+
import org.minbox.framework.grace.expression.annotation.GraceFunctionDefiner;
5+
6+
/**
7+
* @author 恒宇少年
8+
*/
9+
@GraceFunctionDefiner
10+
public class StringUtils {
11+
@GraceFunction
12+
public static String reverseString(String input) {
13+
StringBuilder backwards = new StringBuilder();
14+
for (int i = 0; i < input.length(); i++) {
15+
backwards.append(input.charAt(input.length() - 1 - i));
16+
}
17+
return backwards.toString();
18+
}
19+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
api:
2+
boot:
3+
grace:
4+
# 如果不配置则使用SpringBoot项目默认package
5+
function-scan-base-packages:
6+
- org.minbox.framework.sample.grace

api-boot-samples/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@
4646
<module>api-boot-sample-message-pipe-client</module>
4747
<module>api-boot-sample-message-pipe-server</module>
4848
<module>api-boot-sample-ssh-agent</module>
49+
<module>api-boot-sample-grace</module>
4950
</modules>
5051
</project>

0 commit comments

Comments
 (0)