添加maven依赖
在pom.xml里添加:
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-spring-boot-starter</artifactId>
<version>4.0.0</version>
</dependency>
<!--此时添加是为了防止后边报错-->
<dependency>
<groupId>org.aspectj</groupId >
<artifactId>aspectjweaver</artifactId >
<version>1.8.9</version>
</dependency>
添加sentry的dsn地址
在src/main/application.properties
:
sentry.dsn=http://143f0c822e844bd7815273caa25446ab@ip:port/4
或者在src/main/application.yml
:
sentry:
dsn:http://143f0c822e844bd7815273caa25446ab@ip:port/4
测试效果
package com.x.xx.xxx;
import io.sentry.Sentry;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class Hello {
@RequestMapping("/index")
public String index(){
try {
throw new Exception("This is a test.");
} catch (Exception e) {
Sentry.captureException(e);
}
return "Test";
}
}