r/java • u/GreemT • Oct 17 '20
What is your enterprise experience with the Spring ecosystem?
TL;DR
What is your experience with the Spring ecosystem in an enterprise environment? Some key questions:
How do you deal with dependency hell?
What if the Spring framework doesn't do exactly as you want? How do you work around it?
Do you recommend using Spring for starting a new application that will be used in a large company?
Background
I am a Senior Software Engineer at a company (4 years total working experience) that creates the usual Java web application (SPA, tomcat server, relational database, reporting database, batch processing, etc). The company is medium sized (~200 Software Engineers).
We are NOT using anything from the Spring. The reason is that the company was created more than 15 years ago and has evolved into what we are now. The framework code that was build way in the past has been adapted and is still used today. This generally works fine, since we have full control over the framework. We would never switch to any other framework, because there is no business case for it.
My Spring experience
I have created small projects for myself at home using Spring Boot. It seems pretty cool, but I also see a lot of downsides. My small application without any code was already >50MB from all the dependencies and embedded tomcat. There is also a lot of automagical configuration, which seems very frustrating to debug if you don't know how it works. I need to read a lot of documentation and even looking a bit through the source code to really get to know the specifics.
Other libraries and frameworks need to be a specific version to work correctly. Yeah there is this cool dependency management plugin in Gradle or BOM in Maven, but what if I wanted that other version that includes my new feature? Or what if the library or framework doesn't have an integration with Spring? And what if you have a huge enterprise application and you are going to upgrade the Spring version, isn't that going to take a lot of work? Is there even a business case to do so? As a programmer you surely want to upgrade the version, but if your managers say you don't have the time for that...?
Also, frameworks never do what you want. They are often opiniated. That's why you have the saying "Build libraries not frameworks". Of course, the libraries help reduce boilerplate code. But what if you want to do that one thing that isn't supported by the framework? Now you have to create terrible workarounds just to get that thing that you want... How hard is this with Spring? Is this common?
I did read that Spring Boot was actually the opiniated part, but Spring Framework is actually less opiniated and you can use that without Spring Boot. Though I couldn't really find a good manual for that. Is that so uncommon?
Questions
It is obvious that Spring is extremely widely used. I read about it everywhere I go. Conferences often have at least one talk that is related to Spring. When our company is hiring new Software Engineers, we sometimes have people reject our offer because they want to work in a company that uses Spring. The fact that I seem hessitant to use this in a large company, leads me to think two things: I don't have enough experience (with Spring) and I am wrong about how "blocking"the problems are that I see.
I have looked around a bit and it seems people generally agree that large companies can use Spring just fine. One recent post (https://www.reddit.com/r/java/comments/ib2mqt/spring_batch_in_enterprise_2020/) indicated that maybe not all parts of the Spring ecosystem is enterprise ready, but the framework seems to have proven its worth.
My current company will never switch to Spring. But what if I would start a new company and I would be the lead architect. Should I advice to use the Spring? And if you do, do you advice using Spring Framework or Spring Boot? There are some obvious benefits: quicker startup and easier to recruit new Software Engineers with experience. Popularity shouldn't always be a criteria for selecting a library or framework, but Spring is so extreme maybe I should listen to it. But what about the downsides?
What is your opinion on all of this?
14
u/lukaseder Oct 18 '20 edited Oct 18 '20
I'm glad you asked! JDBC is a great API for network protocol abstraction. It also works nicely for simple clients and a few queries. It is excellent for libraries like jOOQ or Hiberante to bind to. For end users, however, once applications get more complex, you are missing out on:
Type safety for your column types via code generation.
Type safety for your schema objects via code generation (rename a table, column, stored procedure, etc., code doesn't compile anymore)
Much simpler integration of vendor specific features (array types, user-defined types, etc.)
Powerful dynamic SQL (this is really the biggest benefit. You won't get that elsewhere at the same level of quality).
Vendor agnosticity, in case you need that (support for multiple database products or migrations from one database product to another)
Advanced syntax support, like row value expressions, recursive SQL, window functions, SQL/XML and SQL/JSON support.
Plain SQL templating. (Really cool with text blocks)
A lot of different, convenient ways to fetch data
Updatable records for CRUD (including optimistic locking)
Data export and import
A powerful built-in RecordMapper, which can even map SQL/XML or SQL/JSON to nested collections starting from jOOQ 3.14 (the SQL/XML and SQL/JSON support will be a game changer on its own!)
The usual convenience on top of JDBC: No need for resource management, simpler bind variable management (feels like PL/SQL, not like JDBC), better result types and APIs, simpler transaction APIs, mapping functionality. (JDBI, JdbcTemplate, and many others do that as well)
SQL injection protection (which is a side effect of using an internal DSL rather than an external one)
A lot of convenience, such as implicit join, keyset pagination, embeddable types, custom converters and bindings,
Less popular but occasionally very useful things:
Execution lifecycle management
Schema and table mapping (e.g. for multi tenancy)
DAOs
DDL support, including DDL export
Dynamic procedural statements
An increasing number of SQL transformations
A SQL parser
A SQL interpreter
A SQL translator
A schema diff tool
A mocking connection and file based implementation for simple tests
Diagnostics SPI
Near future roadmap:
jOOQ migrations will significantly improve the database change management experience when using Flyway, Liquibase or other products in the near future.
A new query object model will allow for implementing custom SQL transformations more easily, which is especially useful when working with native SQL and the parser
And much much more. We've only just started! (11 years ago)
Obviously, you're not going to need all of these, but you're quite likely going to profit from at least half the list. See also, the manual.
(Thanks for the ping, /u/GreemT)