newrelic 与 springboot 整合 保姆级

Springboot 与 newrelic 配置流程

1. 在newrelic官网注册账号(免费期为15-30天):

https://newrelic.com,注册登录

api key 快捷链接

https://one.newrelic.com/admin-portal/api-keys/home

2. 左侧点击菜单 APM & Services

选择 add data 后面就是选择 可参考下面的步骤
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述在这里插入图片描述

3. 配置pom

会自动跳到官方文档
或者直接使用 https://docs.newrelic.com/install/java/
相当于根据2的步骤 推荐了官方配置步骤
在这里插入图片描述
在这里插入图片描述
pom.xml文件的配置
配置扩展项
在这里插入图片描述

<dependency>
    <groupId>com.newrelic.agent.java</groupId>
    <artifactId>newrelic-java</artifactId>
    <version>JAVA_AGENT_VERSION</version>
    <scope>provided</scope>
    <type>zip</type>
</dependency>

这个步骤 是下载newrelic的jar包的zip文件
JAVA_AGENT_VERSION  这个地方需要我们更改对应的版本 可参考下面链接 选择版本
https://docs.newrelic.com/docs/release-notes/agent-release-notes/java-release-notes/

配置 plugin(解压zip文件 mvn clean package 时才会操作)
在这里插入图片描述

<!-- Unzip New Relic Java agent into target/ -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
    <execution>
    <id>unpack-newrelic</id>
    <phase>package</phase>
    <goals>
        <goal>unpack-dependencies</goal>
    </goals>
    <configuration>
        <includeGroupIds>com.newrelic.agent.java</includeGroupIds>
        <includeArtifactIds>newrelic-java</includeArtifactIds>
        <!-- you can optionally exclude files -->
        <!-- <excludes>**/newrelic.yml</excludes> -->
        <overWriteReleases>false</overWriteReleases>
        <overWriteSnapshots>false</overWriteSnapshots>
        <overWriteIfNewer>true</overWriteIfNewer>
        <outputDirectory>${project.build.directory}</outputDirectory>
    </configuration>
    </execution>
</executions>
</plugin>
4. 配置秘钥并下载配置文件

https://one.newrelic.com/admin-portal/api-keys/home 秘钥地址
然后填写第5步
App name 后期可修改
然后点击 下载
将下载的newrelic.yml 文件复制到springboot下 项目 /src/main/resources目录下
在这里插入图片描述

5. 官方的6-7-8比较鸡肋 项目不方便做手动移动文件 我们直接忽略 下面会用编程实现
6. 终端运行
mvn clean package 

打开项目 target 目录已经可以看到 newrelice目录
然后我们打开newrelic.yml 文件 发现还是sample(未配置的)文件 并没有将我们的newrelic.yml文件同步过去

7. 修改pom 以编程的方式将 newrelic.yml文件

请确保
第4步 已经将 newrelic.yml 放到 src/main/resources/
第6步 已经存在newrelice目录

将代码copy到springboot pom.xml 然后再运行第6步 命令 可以看到newrelic.yml 已经是我们配置的文件了

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <!-- 资源文件输出目录 -->
                <outputDirectory>${project.build.directory}/newrelic</outputDirectory>
                <resources>
                    <resource>
                        <directory>src/main/resources/</directory>
                        <includes>
                            <include>newrelic.yml</include>
                        </includes>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>
8. 运行生成的jar包

修改xxx 为自己项目的jar包

java -javaagent:target/newrelic/newrelic.jar -jar target/xxx.jar
9. 查看是否同步成功

大功告成!
登录newrelic 后台 APM & Services 查找您的应用程序名称(这可能需要几分钟时间)。
在这里插入图片描述

10. 链路追踪

上面只是追踪到了 接口函数部分
接口后面的方法运行并没有追踪
这一块 newrelic 并没有自动追踪 需要我们使用 newrelic的 agent api扩展
Pom.xml 引入 版本号 和 上面的一致

<dependency>
    <groupId>com.newrelic.agent.java</groupId>
    <artifactId>newrelic-api</artifactId>
    <version>8.0.0</version>
    <scope>provided</scope>
</dependency>

在我们想要埋点的方法添加注解 示例

@Trace(dispatcher = true)
public Optional<xxxx> xxxx(xxxx){
    xxxxxx
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot集成MyBatis可以帮助我们更便捷地进行数据库操作和管理。下面是一个保姆的步骤来帮助你完成Spring Boot集成MyBatis的过程: 1. 首先,需要在pom.xml文件中添加MyBatis和数据库驱动的依赖。你可以通过Maven或Gradle来管理项目的依赖。 2. 接下来,在application.properties或application.yml文件中配置数据库连接信息,包括数据库URL、用户名、密码等。 3. 创建一个实体类,用来映射数据库表的结构。可以使用注解来标识该类与数据库表的对应关系。 4. 创建一个Mapper接口,用来定义数据库操作的方法。可以使用注解或XML文件来编写SQL语句。 5. 创建一个Mapper接口对应的Mapper.xml文件,将SQL语句与Mapper接口中的方法进行映射。 6. 在Spring Boot的启动类上添加@MapperScan注解,指定Mapper接口所在的包路径,以便让Spring Boot能够扫描并加载这些Mapper接口。 7. 在需要使用数据库操作的地方,可以通过自动注入Mapper接口来调用数据库操作的方法。 通过以上步骤,你就完成了Spring Boot集成MyBatis的配置和使用。你可以根据需要进一步扩展和优化你的项目,例如添加事务管理、缓存等。 请注意,这只是一个简单的保姆的步骤,实际的配置和使用可能会因项目的需求而有所差异。如果有具体的问题或疑惑,可以参考上面提到的引用和引用中的教程内容,或者查阅Spring Boot和MyBatis的官方文档来获取更详细的信息和指导。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Spring Boot整合MyBatis(保姆教程)](https://blog.csdn.net/astonishqft/article/details/128495928)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [SpringBoot集成Mybatis保姆教程(完整版)](https://blog.csdn.net/xqnode/article/details/113079010)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值