Reputation: 99
I am experimenting with Spring Boot 2 and AspectJ Load Time Weaving. I am able to run both tests and application from Eclipse (add two agents: aspectjweaver and spring-instrument to the VM), surefire from Maven also runs fine, however I am unable to add two agents to spring-boot-maven-plugin.
Here is my pom.xml snippet
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
-javaagent:"${settings.localRepository}/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar"
-Dspring.profiles.active=test</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<agent>
${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
</agent>
<agent>
${settings.localRepository}/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar
</agent>
</configuration>
</plugin>
Looks like spring-boot-maven-plugin only attaches spring-instrument to the VM. (Actually, always the last 'agent' entry of the pom.
Anyone got an idea, how to get this to work?
I am using Java 8, Spring Boot 2.1.0.RELEASE (AspectJ 1.9.2 and Spring 5.1.2.RELEASE).
Upvotes: 0
Views: 952
Reputation: 67457
According to the plugin documentation, the agent
parameter is an array of files, i.e. there should be a way to specify multiple ones. Looking at the source code, I can also see that if there are in fact multiple agents specified they are all added to the list of command line parameters.
Now the open question is how to specify multiple agents? Usually in Maven plugins if there is an array element the naming is something with a plural "s", such as "agents", and inside you would use the singular "agent" for elements. But here the array element is a singular word already.
Why the Spring team did not do that here, I have no clue. But when experimenting with Maven parameter -X
and checking the debug output, I saw that whatever subtags you use, it works. You can use either of
<agent>
<agent>foo</agent>
<agent>bar</agent>
</agent>
<agent>
<x>foo</x>
<y>bar</y>
</agent>
<agent>
<agentElement>foo</agentElement>
<agentElement>bar</agentElement>
</agent>
For lack of a better convention, I recommend the latter. In any case, just repeating two top-level agent
tags does not solve the problem.
What I have not tested for lack of a complete project is whether the two agents on the command line actually start Spring Boot correctly. That part is up to you.
Update: I just raised the corresponding Spring Boot issue #15455.
Update 2: The Spring Boot issue has been resolved and in version 2.2.0 the parameter should be renamed to agents
, so it will be more intuitive to use multiple agent
entries inside it.
Upvotes: 1