spring boot deploy with javaagent

spring boot 通常会打成一个fatjar的方式启动,如果我们本地启动(增加agent)则是这样子:

java -javaagent:/path/myAgent.jar -jar myFat.jar

但是部署到生产环境,绝对路径是会变的,所以两种方案:

和fatjar放在同一目录下,/target

<plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.demo.Application</mainClass>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.demo</groupId>
                                    <artifactId>myAgent</artifactId>
                                    <version>x.x.x</version>
                                    <type>jar</type>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
  1. 指定spring boot maven plugin的mainClass属性
  2. 使用maven copy 插件,将 myAgent.jar 复制到target目录
  3. docker脚本
COPY ./ztarget/springBootApp.jar /path/
COPY ./target/myAgent.jar /path/
  1. 服务器上可执行脚本 java -javaagent:myAgent.jar -jar myFat.jar

将agent打包至fatJar中

参考: Including Java Agent in Standalone Spring Boot Application

效果:java -javaagent:myFat.jar -jar myFat.jar

转载于:https://my.oschina.net/tigerlene/blog/3045085

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Great! Building a logistics management system with Spring Boot is a good choice. Spring Boot is a popular Java framework that can help you quickly build web applications. Here are some steps you can follow: 1. Define the requirements: Before starting the development process, you should define the requirements for the logistics management system. This will help you understand what features are needed and what data needs to be stored. 2. Choose a database: You need to choose a database to store the data for your logistics management system. You can use a SQL database like MySQL or PostgreSQL, or a NoSQL database like MongoDB. 3. Set up the development environment: You need to set up the development environment to start building the logistics management system. You can use an IDE like Eclipse or IntelliJ IDEA, and install the necessary dependencies like Spring Boot and the database driver. 4. Design the database schema: You need to design the database schema to define the tables and relationships between them. This will help you to store and retrieve data efficiently. 5. Create the entities and repositories: You need to create the Java entities that represent the database tables, and the repositories that handle the database operations like insert, update, delete, and select. 6. Implement the business logic: You need to implement the business logic for the logistics management system, like creating orders, managing inventory, and tracking shipments. 7. Implement the REST endpoints: You need to implement the REST endpoints that allow clients to interact with the logistics management system. This includes creating endpoints for creating orders, managing inventory, and tracking shipments. 8. Test the system: You need to test the logistics management system to ensure that it works as expected. You can use tools like JUnit and Mockito to write unit tests for the individual components, and use tools like Postman or Swagger to test the REST endpoints. 9. Deploy the system: You need to deploy the logistics management system to a production environment. You can use tools like Docker and Kubernetes to containerize and orchestrate the application. By following these steps, you can build a robust logistics management system with Spring Boot. Good luck with your project!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值