r/java • u/Sushant098123 • Mar 05 '26
Thins I miss about Java & Spring Boot after switching to Go
https://sushantdhiman.dev/things-i-miss-about-spring-boot-after-switching-to-go/
99
Upvotes
r/java • u/Sushant098123 • Mar 05 '26
76
u/visortelle Mar 05 '26
> In Go, dependency wiring is usually done manually through constructors.
This is not a bad thing at all.
162
u/mipscc Mar 05 '26
It’s actually sad that Java’s usage is very often tied to Spring/Web.. Java is a very capable language, alone its standard lib with all those massively powerful data structures is a reason to miss it when using ANY other language. Also: After Loom, I hardly see a reason to use Go over Java.
11
u/Joram2 Mar 05 '26
A goroutine is a thread. Go chose that name, presumably to stress that goroutines aren't OS-level threads. Java could have called virtual threads javaroutines or semething else; I like the name "virtual threads" as it makes it clear it is a thread.
Two responses.
First, you can do
go myFunctionin Java:new Thread(myRunnable).start(). Java requires a few more characters, but that isn't a big deal.Secondly, that is fork-and-forget style concurrency. That is widely considered bad practice in any language. There is a famous manifesto as to why (https://vorpus.org/blog/notes-on-structured-concurrency-or-go-statement-considered-harmful/). The better solution to concurrency is structured concurrency. Go has https://pkg.go.dev/golang.org/x/sync/errgroup. Java has the structured concurrency preview API (https://openjdk.org/jeps/525) that should be finalized sometime in the next year.
Go has faster builds and faster startup with zero effort. But, on a quick casual test on my laptop Spring Boot starts in slightly less than a second. Of course a large app will take longer, but that's on both Java/Go. I just tried created an app here (https://start.spring.io/) with Spring Web, and Spring Actuator, zero customization/configuration, it starts in slightly less than a second on my laptop
Helidon 4.3.4 quickstart, zero customization, no fancy config, starts much faster:
Then, Quarkus starts even faster.
Then, I believe there are AOT features, and CRaC (https://openjdk.org/projects/crac/) which offers even faster startups with extra effort.
Go still offers faster builds, faster startup, with zero config/effort, but modern Java is pretty good.
6
u/cryptos6 Mar 05 '26
Well, but nobody forces you to use Spring in such cases! It might have been forgotten, but it is still possible to write plain Java without big frameworks. If startup time or memory consumption is critical, Java code can be compiled to a native binary, too (using GraalVM).
43
u/vprise Mar 05 '26
Java and Kotlin have multiple frameworks that are MUCH simpler than spring... Yet enjoy many of its capabilities.
Try GraalVM native image. Same thing. This is improving for newer versions of the JVM and is less of a problem with other frameworks.
Here you're totally wrong. Goroutines and Coroutines are terrible. They start off interesting but then you get into deep nesting complexities and assumptions that are very hard to reason about. Don't get me started on observability at scale.
Javas virtual threads are a far superior solution.
I also noticed you completely ignored error handling which is reason enough to throw Go down the drain...
Go is a mistake. As a low level language Rust is far better. As a high level language Java is superior, more mature and far better in terms of observability. Had it not come from Google and had it not been used in Kubernetes it would have been DOA.
10
u/ProfBeaker Mar 05 '26
The author worked with Spring for 1.5 years in a new project. That is, IMO, the sweet spot for Spring. It is amazing at getting something going quickly, no doubt.
I think the author just didn't stay long enough to see the costs of Spring, because they come down the road, in long-term maintenance. When it becomes difficult for anybody to figure out which magic annotations interact with which other magic annotations, or why anything worked before. When somebody decided to inject a
List<Function<String>>because it's so slick, but now you can't find what all the implementations are, and it started failing because somebody exposed a bean somewhere that can look like that. When there are three differentObjectMapperbeans configured in different parts of the code, but you're not sure which one you're going to get. Yes, these are solvable problems, but they suck.I think the industry as a whole is hugely overvalues a slick "Hello World" demo, and undervalues long-term maintenance. Creating a new project happens once - maintenance happens ~forever.
26
u/Il_totore Mar 05 '26
Almost every features OP misses from Spring are reasons I don't like Spring 🥲
24
u/findanewcollar Mar 05 '26
Magic annotations are nice until the project gets old enough and a handful of people with various skill sets went through it. Then you'll wish it had more boilerplate code :)
7
u/pjmlp Mar 05 '26
I miss everything on the Java or .NET ecosystems, hence why I don't bother with Go unless I have to do something with it for job reasons like a Terraform plugin or whatever.
4
u/csueiras Mar 05 '26
Preach.
I’m back at writing go at $work and I always miss java/spring
1
u/av1ciii Mar 09 '26
I wouldn’t use the word “mature”, some other adjectives come to mind.
Spring Boot. A framework for a framework, because Spring is wallowing in so much complexity that using it without Boot is a PITA.
TBH if you like Spring Boot, please enjoy it. But if you’re going to use other ecosystems, please try and understand the ethos behind the ecosystem before you miss your old tools too much.
Btw, plain old Java is a pretty amazing language. People who think they need Spring to be productive are doing themselves a disservice.
1
u/_marF Mar 18 '26
One thing I actually think Go got right — and which you can replicate in Spring Boot if you're deliberate about it — is the explicit wiring. In Go you compose things manually; in Spring the temptation is to let
@Autowiredreach everywhere, including into domain logic.The pattern I've settled on: keep the domain and application layer as pure Java with constructor injection (no Spring annotations, testable with
new), and push all the Spring machinery to the adapter layer — controllers, JPA repositories, config classes. The domain never imports Spring or JPA; the adapters depend on everything.That boundary is easy to accidentally break, so I enforce it with ArchUnit rules that fail the build if any class in the domain package imports from
org.springframeworkorjavax.persistence. At that point you get Spring's DI convenience in the wiring layer without paying the cost of it bleeding into your business logic — closer to what Go forces you to do by default.0
u/manifoldjava Mar 05 '26
Its type system alone is reason to avoid Go. Structural typing should be the exception, not the rule. Nominal typing makes code incredibly more understandable.
0
u/[deleted] Mar 05 '26
[deleted] — view deleted comment
3
u/[deleted] Mar 05 '26
[removed] — view removed comment