Tonight Only: Join the AppLand Team at the Boston Java Meetup!

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
  • 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
  • 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/[email protected] install-agent 
    

Step 3: Record and open AppMaps from tests

  • Run tests with Maven
    • mvnw test (Windows)
    • ./mvnw test (macOS, Linux)
  • View recorded AppMaps in your IDE:

Step 4: Record AppMaps 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
    • 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
  • Inspect the recorded AppMap
    • HTTP requests
    • Function calls
    • SQL commands

Step 5: Record and inspect the behavior of the Spring framework

  • Configure AppMaps 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 AppMaps

  • 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

Step 7: Share AppMap with your peers


Step 8: Record AppMaps of your own application

  • Set up AppMap for your application
  • Fine-tune the AppMap configuration for your app
  • Record and open AppMaps

Additional Resources: