We’re excited to host a hands-on, online workshop tonight at 6 pm EDT for the Boston Java Meetup Group! Come join us, all are welcome and we’d love to meet you 😊
We’ll be demoing how to use a free and open source tool to highlight a design flaw in a simple Spring application. We’ll also show how to use the tool to analyze your own projects, so you can follow along using the same simple application we’ll be using, or use your own Java-based app.
Here’s everything you’ll need to join us and get the most out of the event…
For all the logistical details and how to register (for free!), click here.
Prerequisites
- JDK 8 and newer
- macOS, Linux or Windows are all fine
- Supported IDE: IntelliJ 2021.1 or newer, or VSCode with Java extensions
- git client, basic familiarity with git
- Node.js installed
- GitHub or GitLab account
Recommended
- Spring framework app or a servlet-based web app will be a great fit
- Integration tests are a plus, but not required for web applications
Instructions for installing and using AppMap for Java
Step 1: Clone, build and run the Spring Petclinic Application
- Clone the Petclinic git repository to a local folder
git clone https://github.com/spring-projects/spring-petclinic.git cd spring-petclinic
- Build locally with Maven
- mvnw clean install (Windows)
- ./mvnw clean install (macOS, Linux)
- Start the app and open the web UI
- java -jar target/*.jar
- Open http://localhost:8080
- Stop the app with CTRL+C
Step 2: Install AppMap for IntelliJ or VSCode
- Open the PetClinic project in your IDE
- Install AppMap from the marketplace
- Use this command to install the appmap-java agent for this project
npx @appland/appmap install
Step 3: Record and open AppMap Diagrams from tests
- Run tests with Maven
- mvnw test (Windows)
- ./mvnw test (macOS, Linux)
- View recorded AppMap Diagrams in your IDE:
Step 4: Record AppMap Data with remote recording
The AppMap agent can record all running application code. In this step, we’ll instrument the application server and record your application’s behavior as it runs. Here’s how it’ll happen:
- Configure and start the application with remote recording
- Download appmap-1.5.0.jar
- Start the application with the appmap-1.5.0.jar javaagent:
java -javaagent:appmap-1.5.0.jar -jar target/*.jar
- Record an AppMap
- Start AppMap recording in your IDE
- IntelliJ: Menu
Tools
->AppMap
->Start AppMap Recording
- VSCode:
SHIFT+COMMAND+P
AppMap: Start remote recording
- IntelliJ: Menu
- Find and view owner in the PetClinic application
- Stop and save AppMap in your IDE
- IntelliJ: Menu
Tools
->AppMap
->Stop AppMap Recording
- VSCode:
SHIFT+COMMAND+P
AppMap: Stop remote recording
- IntelliJ: Menu
- Start AppMap recording in your IDE
- Inspect the recorded AppMap
- HTTP requests
- Function calls
- SQL commands
Step 5: Record and inspect the behavior of the Spring framework
-
Configure AppMap for shallow recording of the Spring framework. Update the
appmap.yml
file in the project root folder to include this path:- path: org.springframework.web shallow: true exclude: - org.springframework.web.filter.OncePerRequestFilter - org.springframework.web.context.request.RequestContextHolder - org.springframework.web.context - org.springframework.web.servlet.resource.ResourceUrlEncodingFilter
- Make a new remote recording
- Start AppMap recording in your IDE
- Find and view owner in the PetClinic app
- Stop and save AppMap
- Inspect the Spring framework events in the AppMap
- See how OwnerController is called from the framework
Step 6: Find N+1 anti-pattern with AppMap Diagrams
- Find and fix N+1 SQL antipattern in the Pet Clinic app
- View the anti-pattern in a recorded AppMap
- Find and open a ‘should find vets’ AppMap recorded from a test
- View the SQL commands
- Find the bug and fix the code (here is a hint)
- Re-record the AppMap with the fix in place and compare it with the “before” AppMap
- View the anti-pattern in a recorded AppMap
Step 7: Record AppMap Data of your own application
- Set Up AppMap for your application
- Fine-tune the AppMap configuration for your app
- Record and open AppMap Diagrams
Additional Resources:
- Pre-configured Pet Clinic repo
- A recent blog post and video on the topic
- AppMap documentation site
- Additional AppMap use cases and tutorials
- AppMap Slack