springboot项目
pom.xml文件
新增跳过单元测试plugin配置
<?xml version="1.0" 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.lagou</groupId>
<artifactId>skywalkingdemo1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>skywalkingdemo1</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<finalName>skywalkingdemo1</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!--跳过单元测试-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
application.yml文件
为防止与其他项目端口号冲突,将项目端口号更改为8081
server:
port: 8081
HelloController
@RestController
public class HelloController {
//正常访问接口
@RequestMapping("/sayBoot")
public String sayBoot(){
return "Hello Boot!";
}
//异常访问接口
@RequestMapping("/exception")
public String exception(){
int i = 1/0;
return "Hello Boot!";
}
}
本地测试项目
idea开发工具中启动项目,进行测试
http://localhost:8081/sayBoot
打包项目
mvn clean package
配置agent
首先我们复制一份agent,防止与其他应用程序使用的agent冲突
cd /opt/skywalking
cp -r agent agent_springbootdemo1
cd agent_springbootdemo1/config
vi agent.config
agent.service_name=${SW_AGENT_NAME:skywalking_springboodedemo1}
启动服务
将skywalkingdemo1.jar上传到154节点的/data目录
cd /data
java -javaagent:/opt/skywalking/agent_springbootdemo1/skywalking-agent.jar -
Dskywalking.collector.backend_service=192.168.198.141:11800 -jar
skywalkingspringbootdemo1.jar
测试项目
http://192.168.198.154:8081/sayBoot
网友评论