org.apache.shenyu.plugin.mock.generator.Generator
.${name|param1|param2|...}
<dependencies> <dependency> <groupId>org.apache.shenyu</groupId> <artifactId>shenyu-plugin-mock</artifactId> <version>${project.version}</version> </dependency> </dependencies>
CustomerGenerator
,implements org.apache.shenyu.plugin.mock.generator.Generator
。@Join public class CustomGenerator implements Generator<String> { @Override public String getName() { // The name of the generator, i.e. the content before the first | of the expression } @Override public String generate() { // Implement the logic of data generation } @Override public int getParamSize() { // The number of required parameters of the expression } @Override public void initParam(List params, String rule) { // params is the contents except the name after the expression is split according to | // rule is the content of the original expression , if there is a custom parameter processing logic, you can use this parameter } @Override public boolean match(String rule) { // Check if the current expression is valid } @Override public String[] getPrefixAndSuffix() { // Return the prefix and suffix added after the generated content, please return a string array with two elements // 0th element is the prefix, 1st element is the suffix } }
resources
directory,Create a new META-INF/shenyu
directory, and the new file name is : org.apache.shenyu.plugin.mock.generator.Generator
. add ${you spi name}
= ${you class path}
:${spi name}=${custom class path}
${spi name}
represents the name of spi
, ${spi name }
needs to be consistent with the definition of the getName() method in the Generator implementation class, ${custom class path}
represents the fully qualified name of the class. for example:
custom=xxx.xxx.xxx.CustomGenerator
lib
or ext-lib
directory of the gateway (bootstrap-bin).