154 points · by philonoist · 3y ago · 127 comments
The issue with spring boot is not it's feature-set or it's robustness. It's with it's heavy handedness to force you down the "spring way". Annotation driven. Extending provided interfaces. Making it "sticky" and impossible to remove. Want to introduce gRPC? yeah, you're going to have to find a way to weave that into Netty or use a different port. It's robust enough just up unto a point where you hit a roadblock and have to dig deep deep into Spring land to understand whats going on.
It's still the best framework for standard crud web api's and such with Java. Though micronauts is quickly approaching. You can't go wrong choosing spring boot in 2023 if your intention is to ship in 2024. Whether or not that codebase is solid in 2027 is another matter.
I'm from the Java/Jakarta EE parallel universe. Where everything is the same, but different. Both universes have impacted each other is various ways.
JEE has a lot of baggage and notoriety, but, to be fair, so does Spring as they both came up in the same domain at the same time. The XML Hell that JEE was notorious for afflicted Spring as well back in the day. Spring has been more nimble and brought many things to light before they hit the JEE standard, but JEE marches to a different drummer.
Modern JEE is pretty darn good. JAX-RS for web services is really nice, and there's a lot of different deployment options. A lot of the things you can love in Spring you can find in JEE, a lot of the things you can hate in JEE you can find in Spring.
Again, not able to speak to Spring, but JEE has been really stable over time. In that old code continues to work even in new containers. There's a good chance that could even deploy an old, creaky "J2EE" application from 20 years ago in a modern container.
The most disruptive thing to happen to JEE was the Jakartatization of it when it moved from Java EE to Jakarata EE, and all of the namespace changes that happened between Java EE 8 and Jakarta EE 9 with the move from Oracle to Eclipse. But even then, you can still deploy old code in new containers. This was far less disruptive than it could have been, frankly.
I'm certainly not going to suggest to not use Spring, but at the same time, I wouldn't discard JEE out of hand either. It's also an exciting space (for assorted values of "exciting" and "enterprise") for back end work.
Just no. No. All the different types of EJBs… won’t work. Neither will SOAP endpoints. And a shit ton of other stuff that JEE dropped. What are you talking about? Even XML parsing moved packages.
Fundamentally they are an abstraction over a rats nest of code (of a specific version), library dependencies and configuration. Gods help you when something breaks, the abstraction leaks and you are presented with a glimpse of the underlying complexity that is now yours to tinker with.
But as you pointed out, since there are established spring ways to do something, it doen't matter if it's ugly since it actually "just works".
```
@Bean
public AuthorizedClientServiceOAuth2AuthorizedClientManager authorizedClientServiceAndManager (
ClientRegistrationRepository
clientRegistrationRepository,
OAuth2AuthorizedClientService authorizedClientService) {
OAuth2AuthorizedClientProvider authorizedClientProvider =
OAuth2AuthorizedClientProviderBuilder.builder()
.clientCredentials()
.build();
AuthorizedClientServiceOAuth2AuthorizedClientManager authorizedClientManager =
new AuthorizedClientServiceOAuth2AuthorizedClientManager(
clientRegistrationRepository, authorizedClientService);
authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider);
return authorizedClientManager;
}```
With similar code I almost made a vulnerability in my app because Spring cached tokens which belong to different users.
Spring security is terrible piece of code. Spring - I can stand it. Spring Security - I can not. It was different project back in the day (Acegi Security if I remember correctly). It should have stayed that way.
Thank you, thank you (and others like you) for taking the time to type this up!
So yeah, you’re welcome, thanks for coming to my grey beard tech talk. Ask your managers for more brown bag/lunch & learns from the older folks at your company - they have stories.
For example, some queries are naturally best done as analytic queries (or window queries). I have no idea how to do that in JQL (JPA's query language). Moving those queries to the database side can come to the rescure, but it's still an issue.. Which makes me think that JPA makes the easy queries even easier, but the difficult queries nearly impossible (if not outright impossible).
> Though micronauts is quickly approaching.
I've been looking at micronaut quite a bit as well. Another big downside to springboot is that by default it wants around 100MB of RAM per instance. With 6~7 applications on one host, the expenditure for the memory is sizable. Micronaut has a significant leg up here.
[+] DB Queries are often developed first by figuring out what the right query is. After that is done, it needs to be translated to JPA. If JPA eventually starts doing the wrong thing, or something slow - it then needs to be converted to SQL so you can do an explain plan. The latter is not that hard as you can enable a debug output to see what it is, but overall there are quite a few more steps here compared to: "develop your SQL query, next plop that into a string variable in your java code", vs "develop your SQL query, model the table relationships as java objects, build a JPA repository to run some queries against those tables" (in the happy case the latter is all that you need and is not bad, but when a query starts going slow, or starts fetching MB of data which you won't notice on local development but in production causes a p0...)
Of course, everyone who complains about a technology just hasn't learned it properly.
I think I understand the Spring model fairly well at this point. But one of the problems with it is that it's confusing and that the runtime-reflection-heavy approach causes issues with debuggability, performance and also errors creeping into production that should by all accounts be preventable at compile-time.
It's rather easy to make silly mistakes with Spring, such as confusing @Configuration and @ConfigurationProperties or writing tests that share the application context even though they require different configuration and suddenly stop working if they're executed in the wrong order, and even if you yourself learn it perfectly, your coworkers might not.
I agree that it offers a ton of benefits - but that doesn't mean that it isn't valid to criticise it.
With that said, Spring Boot will be vastly more mature, have a lot more resources available, bigger community, etc. There's also tons of 3rd party libraries that have support for spring and/or spring boot out of the box - such as resiliance4j, openapi-generators, etc.
With that said, Spring/Boot's Kotlin support is really good. The team has clearly put a lot of effort into making Kotlin a first-class language within the Spring ecosystem.
For backend work, Kotlin + Spring Boot is amazing.
Running Boot in a container is also not great due to the memory requirements needed for bootstrap (min 0.5 Gi). I know GraalVm makes this better but compile times are still too painful.
I also think the push to make Reactor the default choice was a mistake (deprecating RestTemplate). The reactive model in Java feels unnatural and it can be very hard to debug.
I am working with Go now and don’t miss Spring Boot that much but it still has a place in my heart for the amazing community and docs.
Don't overlook @ConfigurationProperties <https://docs.spring.io/spring-boot/docs/3.1.1/reference/html...> as a way of strongly typing any configuration knobs that your application may require. That not only allows static typing to avoid the hazardous @Value("some.vaule.oops") but it also means that IJ will tab complete (with typechecks) in your application.{properties,json,yaml,whatever}
That said, the downsides aren't really that bad. It's got a strong community, will obviously still be around in 5 years, and the JVM is seeing strong investment and modernization. All in all, it'd be a strong contender if I was putting my money on the line. I'm still a fan of the simplest-thing-that-can-work approach (in the old days it was Jetty + Guice + whatever else you wanted), but modern Spring isn't all that far off from the experience anymore.
Yes its been tied to many java architectural fashion boondoggles of the past (XML config madness, XML namespace magic, overly heavyweight serverside HTML rendering, JSP tag madness, software patterns) but I still turn to it for basic code structuring in any JVM app.
Boot is pretty good ... until its not. If you are doing garden variety web services it gets you up and running fairly well. If you need to do anything fancy with routing or raw data in the html request/response, then it is not. And Spring is now so synonymous with Spring Boot that it kind of isn't a good thing.
Spring also isn't a pure open source project, it has a company trying to constantly steer it to revenue production, but as those types of entities go, stewardship has been decent. Normally things like that have about four or five years of trying to use open source for market expansion before impatience/greed/frustration sits in and they go for the closed source grab (see: Hashicorp recently). 20 years is a remarkable run for something like that.
spring => configuration over conventions
spring-boot => conventions over configuration
I would take Spring config XML over the tightly coupled mess of Spring config annotations and code. Circa 2006, Spring config was about binding decoupled POJOs together and code didn’t require any build time dependency on Spring. Now Spring is required at build time and objects expect to be instantiated as beans, and unit tests either require a minimal spring context or some other method of injecting dependencies that would have otherwise existed as a constructor arg or mutator anyway. Now “config” is fully Turing complete as opposed to declarative. Yuck! I’m no fan of XML, but config as code is no longer config, imho.
There was time when Spring was considered lightweight. Oh, well.
Spring Boot is when it all went downhill.
You nailed it though with Spring being configuration over convention and Spring Boot being the opposite. At the time, there was a competing web framework that was really simple to build with called Rails that made the mindset shift to ease-of-use from a dev standpoint away from ease-of-use from an ops standpoint.
It includes actuators, the auto configuration system, embedded web server and configuration properties
We personally use Quarkus and it's also pretty good. I think the Quarkus story has driven spring towards having a better story and both are pretty excellent stacks to go with.
Granted, it can probable be helpful in many ways, but it comes at a price. But I think improvements in developer tooling will make annotation-driven programming unmodern. I see a renaissance coming for plain old programming.
It's boring tech, which is a good thing IMHO.
First, that Spring it's bloated. Spring now has a wide extension of modules that you may or may not need. Most of those modules won't even be added in your classpath unless specified in your pom.xml or build.gradle file. Very simple projects won't need the vast majority of the full Spring power.
Second, that a Spring project takes too much time to launch the web app (Compared against other frameworks doing the same task). Part of the reason it takes too much time to start comes from how the engine inflates the beans and injects it. On that same topic, other frameworks such as Micronaut are more lightweight because they don't bloat the framework as much as spring, thus the launch time is shorter. Also take into account that Java developers adore complexity in code structure so that also affects launch time.
Are you going to regret going with Spring? No, there is a lot of support from the community, if you have any issue you will find help in reddit and stackoverflow. It's a really mature framework.
However it's not the only option. There are other frameworks that could be a better choice for your use cases.
Yes. One day you'll add another dependency to your classpath and your application will magically be doing something you didn't want or need. And the way to turn it off will be an undocumented annotation that only exists in the next version of spring boot, so you'll upgrade to that, and then a whole bunch of other stuff will break.
The tradeoff of today with Spring Boot is you might get bitten down the line with a little configuration mystery, although it’s such a well-blazed path you’re probably in good company and will find your error solved and documented.
In addition, it’s Java so virtually any serious task is done in a well-blazed fashion with numerous open-source options available. In contrast my Node library I used to generate and validate an XML document at work last month cannot read in its own XML output. It’s a boon for efficiency.
The only downside Java really has is that it’s a bit harder to “hack on” a dynamic, evolving JSON structure so it may be a bad fit for organizational reasons if your company lacks a cohesive, mature Engineering staff.
Also, Spring would be a miserable experience if it were not for Maven/Gradle. Have you ever counted the jar files included in a typical SpringBoot+Spring-Security+Spring-Data app?
If your product happens to be something serving a zillion requests per second, using some exotic protocol, or doing some wildly complex calculations, then Spring might not be be the best choice. And it just so happens that the HN community's primary interest goes out to these rare exceptions and not to the 99% other projects in the real world.
The major gripes I have is that _up-to-date_ documentation on the best ways compose a modern app using several modules where you aren’t fighting the tools. Official module docs tend to breeze over stuff. I can’t tell you how much time I’ve wasted rolling my own ____ and fighting against autoconfig then finding there’s a simple but poorly documented way of doing what I need. But even with that frustration, I feel like I’m able to launch projects faster using Spring Boot than dotnet.
You won't regret using it in 6 months except maybe for the fact that your backend will be just working and doing its thing and there's not really much else to do except watch it work.
Now, we have modern java + simpflified saner default named spring boot, that's a different story
There's been some real symbiosis among the backend frameworks that has caused them all to lift in quality.
If you just upgrade all your spring-related dependencies to latest-of-same-major-version every time you upgrade, on average how much does your own code end up breaking?
I wouldn't change Jakarta EE, Spring, ASP.NET for framework of the day, with a subset of functionality and molass performance, unless told otherwise by customer architect.
It's a tricky question to get a real answer, due to all the vested interests, lack of real research, and differing views of "what is good"
Which is better, Amiga or ST (Amiga!)
Only if you plan to collect kudos with it on HN. Otherwise you'll be fine.
There's a huge difference between "Spring pre-Boot" and "Spring post-Boot."
Not quite as significant as Angular 1 vs Angular 2, but close.
So, my honest evaluation: learning Spring is frustrating and not an enjoyable experience at all. Just the sheer verbosity of things hurts my Pythonista soul. It's not just that Java is inherently more verbose than Python, it's just that "the Spring way" forces you to create three classes with little to no shortcuts around it; even the most opinionated Python/Node frameworks I've encountered wouldn't be that draconian. Coming from Python/Node/PHP/serverless, the framework's philosophy seems incomprehensibly monolithic.
All the layers of abstraction (and their resulting stack traces) make for an extremely confusing debugging experience especially for noobs.
*BUT*, I admit, judging a technology for its learning curve is not fair. I just had to vent my honest opinion on the experience.
I'm now at that point where I think I've grokked "the Spring way". That is, my Google searches on how to do X in Spring/troubleshoot a problem are smarter now. I've actually grown to appreciate it. (I'm pretty sure the Spring Gods would make me pay for the sheer hubris of this statement and will make me eat my words in the next feature I come up with in my side project.)
JpaRepositories are powerful magic. If Spring has any advantage over the frameworks I've come to love, it's this. JpaRepositories compensate for what Spring/Java lacks in brevity. Oh, also, not a Spring-specific advice but Lambdas and method references have made Java easier to write and has definitely deflated the number of classes I've had to create otherwise. Some would say that's just lipstick on a pig but I prefer to see it as an oasis in a desert.
Lastly, don't take this as advice for the backend you are building for a new start-up but I really see Spring's strength in that consulting CRUD-software market. If I can define specs in a legally-binding contract before writing a single line of code, if I can bang out a schema at the start of development and not worry about migrations, I would actually choose Spring. All the "corporate-rep" of Java won't hurt for these types of projects either.
But on the other hand, for environments where I need a lot of flexibility and lack the leisure of time almost always, I feel like Spring would be a development death march.
Misc notes:
1. I'm not actually learning vanilla Spring. I'm using Spring Boot alongside Vaadin. Overtime I've come to distinguish better between the two but maybe some percent of my frustrations in the learning phase is on Vaadin, not really Spring.
2. I made extensive use of ChatGPT in learning Spring. Even for such a boring/common tech, it's hilarious what ChatGPT gets wrong. But it also gets things right, giving advice in a level of clarity that blog posts and SO posts couldn't have provided. I would recommend anyone trying to learn Spring (or maybe any other framework/technology) to give ChatGPT a shot too. Even when it gets things wrong, the feedback loop that resembles actually talking to someone helps with the rubber ducking.
Again, all 2c worth of opinions from someone not even a year in this framework. Caveat lector!
Blockhound I have gound useful for detecting blocking in non blocking areas.
Never was invested in anything beyond Java SE, now I'm never going to invest in Java SE again.
Is Hibernate moving towards Java generics, about 2 decades after the fact?
Spring seems much bigger and seems to moving much more quickly, but it's weird that Hibernate seems to still be stuck somewhere around Java-in-the-00s.
What did you have in mind?
their call stacks between injected components are sometimes a couple dozen layers deep and it makes no sense.
they don't provide easy upgrade paths between majors versions and they stop updating vulnerabilities on older major versions. I inherited some code that was using version x but had to be upgraded due to critical vulnerabilities. The vulns weren't fixed in x or y but only z. I tried moving over and their cryptic unit test fixtures stopped working. No docs on migration. Spring is sort of like cancer.
I'd call Spring feature-rich than bloated. You can always shed weight that you don't want to carry.
> Plus there's multiple ways of doing the same thing. e.g. JPA, spring-data.
That's because there are different ways to solve a problem. Someone may want an ORM-based approach to connect to the database; they can choose spring-data-jpa. Someone may want to use JDBC with a light abstraction on top of it; they can choose spring-data-jdbc. It's all about choices and right tradeoffs and Spring offers plenty of them.
> they don't provide easy upgrade paths between majors versions
That's not my experience. I've been happily upgrading 2.x.x versions and plan to upgrade to 3.2.x when it is ready. But depending on the codebase, I admit it can be painful. Projects like OpenRewrite[1] might help here.
> and they stop updating vulnerabilities on older major versions.
This is not news. They want you to pay for extended support if you need it.
> No docs on migration.
They do maintain migration docs on GitHub wiki which are a lot more detailed than their blog posts on migration. Here's the latest one to upgrade from Spring Boot 2 to 3: https://github.com/spring-projects/spring-boot/wiki/Spring-B...
Well the opposite of this is the antiquated world of "old Java". My subjective assessment is that Spring is somewhere in the middle: reasonable conservatism of principles but eager adoption of beneficial new things. Jumping on virtual threads is a reasonable action.
> their call stacks between injected components are sometimes a couple dozen layers deep and it makes no sense.
We're talking big enterprise-y software, right? Things get huge over time, no way out of complexity. The major red-flag would be accidental complexity which Spring, compared to the rest of the Java world, generally manages well, I'd say.
> they don't provide easy upgrade paths between majors versions and they stop updating vulnerabilities on older major versions. I inherited some code that was using version x but had to be upgraded due to critical vulnerabilities. The vulns weren't fixed in x or y but only z. I tried moving over and their cryptic unit test fixtures stopped working. No docs on migration. Spring is sort of like cancer.
Well non-trivial upgrade paths is the essence of a "major version upgrade". The alternative is to let old ideas never die and either stop introducing new concepts at all (old Java) or introduce them and make the framework bloated (something you criticized in the beginning of your comment). It's a trade-off which I think generally is well managed in Spring. It's boring, but in a good way.
That itself is kind of polite way of putting it. This thing is freaking pandemic virus. Spreading in all sort of projects including code with single CRUD operation.
Enterprise has been relying on Java's compatibility promises for decades. It means the business decides when to invest, not the technology. The cost of re-validating and re-integrating a new system far, far outweighs that of re-writing the software, so you only upgrade the software when you're already having to upgrade the system.
Mark Reinhold managed to move Java to open-source, to frequent releases, and to supporting alternative languages (Kotlin for Google) and deployments (graalvm for containers) -- all while maintaining compatibility. He entirely effaced the notion that change means breakage.
Compare the breakage story in Python and C++ in the same time period.
There was a core development intelligence level that JDK8 represented a sweet spot for (ahem, offshoring development). Which is really the core of the hate for Java these days although ... isn't Go the same trap?
Most of the post-JDK8 features are moving the language to what Groovy is, but closures, magic string templates, etc, but the IQ level of the programmers for that is a different market availability. Combined with the inherent deployment churn needed for modern JVM version turnover, which most enterprises simply don't have the organizational ability to do, means that JDK8 is going to stick around a LONG time.
The real reason is simply that JDK9 was a much bigger compatibility break (in practice if not in theory) than any release before or since, and came after a long time of relatively little development. A lot of frameworks weren't compatible with JDK9 until years after release; some older ones may never be. So especially for enterprises that may have their own large internal frameworks, it takes a while.
I see you are also one of the folks who ignores try-with-resources. And, say what you will about lambdas, it is night and day different between pre-8 and post-8 implementations of those various one-method interfaces such as InvocationHandler
Connection fakeConn = (Connection)Proxy.newInstance(cl, new Class[]{Connection.class}, (proxy, method, args) -> { /*something awesome*/ })Even Android team has acknowledged that despite Kotlin, they needed to improve their support due to third party libraries, with Java 11 LTS last year, and Java 17 LTS coming this year. Both down to Android 12, naturally the usual subset without the graphics/UI related packages.
Perhaps since they come from Sun and Solaris had zones, et cetera?
OSGI was probably the closest thing that tried to embrace that model, and it didn't turn out very well (putting it mildly). If the JVM actually did provide the same guarantees and restrictions as a real container, that would have been very useful.