Showing posts with label SpringBoot. Show all posts
Showing posts with label SpringBoot. Show all posts

Monday, November 24, 2025

Two Things I Ran Across Trying to Learn about Spring Boot

For some of the projects I've been working on I've wanted to set up an easy web interface based in Java. After looking at a bunch of options to learn, I chose Spring Boot which seemed like the most straight forward and possibly useful choice.

I ran into some issues getting started, so I thought I'd write them down in case it helps anyone else. I'm sure that mostly I'm confused and not reading the documentation carefully, but writing is a good way to learn.

For context, I'm working from what looked like a good tutorial on Spring Boot (https://spring.io/guides/gs/spring-boot) and started working through it. The tutorial points you at the helpful Spring Initalizr (https://start.spring.io/) which helpfully (helpfully?) generates everything you need to get started on a Spring Boot project.

Gradlew Version (Which looks like Unsupported class file major version)

The first big thing I ran across was an error from Gradle saying:

BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 69 Unsupported class file major version 69

This was surprising but not super unexpected, for most of the projects I regularly worked in Java in I locked to a version and tended to build most things from scratch (Also updates to the Java version were way less frequent). So I almost never ended up with classes compiled in different versions of Java in the same place. I poked this for a while, but it seemed wrong to get this in a clean install of a Spring Boot application, where I hadn't even edited anything yet.

I don't use Gradle for anything (that's why I'm learning right now) and certainly haven't updated my tech stack for a while, so I figured a good updating of everything would probably help. I fired up Homebrew and let it upgrade everything. This took a few hours — did I mention that I hadn't updated everything in while, but it was fun in the way installing software off of diskettes in the 90s was fun.

This certainly fixed a lot of things and ensured that I had the newest version of Gradle (9.2.0) and Java (25) in the path. Problem solved, I ran

./gradlew bootRun

aaand got the same error.

This was particularly frustrating because a lot of the Stackoverflow and forum posts, tend to — slightly snarkilly — point to the Gradle compatibility matrix (https://docs.gradle.org/current/userguide/compatibility.html) which is slightly frustrating when you are clearly using not only a correct paring of Gradle and Java, but the latest paring of Gradle and Java.

After quite a bit of poking and reading things online, I eventually landed on something being weird with the Gradle Wrapper. I remain a little confused by the Gradle Wrapper, especially when you get the wrapper with a project you're starting on. The idea that it allows you to lock your Gradle version and settings makes sense, but a lot of the details feel fuzzy in the documentation I've read so far and I'm not sure what the difference is between the wrapper and just running Gradle with a specific version. Possibly it's more convenient.

Anyway, it took me a while, but I eventually realized that while I was running Gradle 9.2.0 the Gradle Wrapper in my project from Spring Initalizr was running 8.14.3.

After some more reading I eventually figured out that I had to upgrade the wrapper, with the command:

gradle wrapper --gradle-version 9.2.0

My Googling was sub-par, but I think the document I should have been looking at is this one: https://docs.gradle.org/current/userguide/upgrading_major_version_9.html. Although since I hadn't upgraded my version of Gradle (I just started the project), I felt a bit unsatisfied.

(On further reading (https://docs.gradle.org/current/userguide/command_line_interface.html#sec:environment_options) it seems that what that does create a new wrapper using the specified version, which I guess makes sense.)

Anyway that was the key to getting Spring Boot up and running.

Spring Boot Does Something Weird With Packages

With Spring Boot running, it started Tomcat correctly, but when I poked it using curl all I got was a 404. This was again a little frustrating because I was using the fresh zip file from Spring Initializr and the code from the tutorial.

The application was clearly running, as the code the tutorial includes to show all the beans was working and when I started the app, it gave me a long list of Beans, but when I sent a web request, I got nothing back.

The annotation Spring (Boot?Web?... still learning I guess) uses for establishing endpoints seems to be pretty clear @GetMapping("/") where whatever you put in for a path should be where your Controller gets served, but changing out the path didn't work.

Again my Googleing was a bit weak and I couldn't find anything that directly related to what I was seeing — which is why I thought it would be worth while to write it up here, even if my problems are mostly due to my lack of knowledge.

It seemed to me that the @GetMapping("/") assignment wasn't taking and especially since I'd had some issues with getting things from the Spring Initalizr I wondered if there was something funky in the naming of some of our files or paths.

As I was looking around, I noticed a note in the Spring HELP.md file:

The original package name 'com.example.spring-boot' is invalid and this project uses 'com.example.spring_boot' instead.

Which given my guess about why I was getting the 404 error, gave me a good place to look.

So I went and looked at the two files I'd added from the tutorial src/main/java/com/example/spring_boot/Application.java and src/main/java/com/example/spring_boot/HelloController.java. And as it turns out I did have the package names wrong, just ... not in the way Java would usually find them wrong...

In HelloController I discovered had the package name right, package com.example.spring_boot;, however I had the package name wrong in Application.java, where it was package com.example.springboot;. For the record I think this came from copying files out of the tutorial slightly incorrectly (it uses springboot without a space, which doesn't align with the Spring Initalizr settings they point to, but I didn't catch that).

Now the issue here, at least to my old-timey java mind is that. Application.java was working, the code added in the tutorial ran — it printed the list of beans, and later the message I replaced that list with — but that should have failed based on the package name.

Or I guess that being said, given that spring is very good about finding and plumbing things together, maybe the error shouldn't have happened at all? Or it could possibly have put a warning somewhere I noticed it. Once I got everybody on the same package name (spring_boot) then

Summing Up

As I noticed, I really only wrote this up because some of the things I found online didn't really answer the questions I had. Since I had to do a little learning to solve them, I figured I'd write it up for myself, and maybe it will help someone else at some point.

So,

  • Make sure you have Gradle and Java updated to the right — and compatible — versions.
    • Run gradle wrapper --gradle-version 9.2.0 to fix the gradle wrapper.
  • Make sure that you have the correct — and matching — package in your .java files
    • The tutorial as written and hooked up to Spring Initalizr don't quite align if you're not paying attention.

Two Things I Ran Across Trying to Learn about Spring Boot

For some of the projects I've been working on I've wanted to set up an easy web interface based in Java. After looking ...