Spring Java deploys NewRelic probe record for Boot

I. demand

  • Add NewRelic’s Java probe to the Spring Boot project
  • Setting: Mac OS
  • IDE:IDEA
  • Build tools: maven

Two, pom.xml

The POM file is modified as follows:

  1. Increase NewRelic Agent dependency
  2. Mark “main class” in spring-boot-maven-plugin
  3. Pack the NewRelic Agent jar into the final jar
  4. Increase Premain-Class and other attributes in manifest
< XML? Version= "1" encoding= "UTF-8" > < project? Xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://maven.apache.org/POM/4.0.0 http:// maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion> 4.0.0< /modelVersion> < dependencies>... < dependency> < groupId> com.newrelic.agent.java< /groupId> < artifactId> newrelic-agent& lt; /artifactId> < version> 3.41.0< /version> < scope> provided< /scope> < /dependency> < /dependencies>... < build> < plugins> < plugin> < groupId> org.springframework.boot< /groupId> < artifactId> spring-boot-maven-plugin< /artifactId> < configuration> < mainClass> com.xxx.SpringBootNewRelicApplication< /mainClass> < /configuration> < /plugin> < plugin> < groupId> org.apache.maven.plugins< /groupId> < artifactId> maven-dependency-plugin< /artifactId> < version> 2.10< /version> < executions> < execution> < phase> prepare-package< < goals> phase> < goal> unpack-dependencies< /goal> < /goals> < configurat Ion> < includeArtifactIds> newrelic-agent< /includeArtifactIds> < outputDirectory> ${project.build.outputDirectory}< /outputDirectory> < /configuration> < /execution> < /executions> < < plugin> plugin> < groupId> org.apache.maven.plugins< /groupId> < artifactId> maven-jar-plugin< /artifactId> < configuration> < archive> < manifestEntries> < Premain-Class> com.newrelic.bootstrap.BootstrapAgent< /Premain-Class> < Can-Redefi Ne-Classes> true< /Can-Redefine-Classes> < Can-Retransform-Classes> true< /Can-Retransform-Classes> < /manifestEntries> < /archive> < /configuration> < /plugin> < /plugins> < build> < /project>..;

Three, start

MVN package / / Java / / package to start -javaagent:/path/to/newrelic/newrelic.jar -jar target/YourApp.jar