Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

简介

该模块主要是通过javaagent在程序启动时给java类动态添加注解

功能介绍

1、读取给定的配置文件,解析注解并添加到指定的类和方法上

2、在指定的目录中生成处理后的class文件

如何使用

在java启动时添加javaagent参数,指定本程序编译的jar包,并传递参数,如下所示:

java -javaagent:E:/javaagent.jar=-f=E:/annos.json,-d=E:/test -jar xxx.jar

命令说明:

-javaagent参数后的jar的路径必须是绝对路径,否则可能找不到

-f 和-d是javaagent.jar的参数

​ -f:注解文件绝对路径

​ -d:保存处理后的class文件的绝对路径

​ -h:查看参数说明

annos.json文件格式如下:

{
    "test": {
        "fullClassName": "io.github.ronghuaxueleng.test.Test",
        "annotations": [{
            "name": "io.swagger.annotations.Api",
            "attrs": [{ "attrValue": ["专病应用"], "attrName": "tags" }]
        }],
        "list": [{
            "method": "update",
            "annotations": [{
                "name": "io.swagger.annotations.ApiOperation",
                "attrs": [{ "attrValue": "更新", "attrName": "value" }]
            }]
        }]
    }
}

其他请参考test下实例

Comments ( 0 )

Sign in for post a comment

About

给java代码添加注解的javaagent spread retract
Cancel

Releases

No release

Contributors

All

Activities

load more
can not load any more