from Hacker News

My experience using Spring boot for website development

by mr_puzzled on 8/3/19, 7:56 PM with 13 comments

At work, I was asked to learn spring boot and the first task was to build a simple crud app, just end to end functionality for a model with automated tests, builds, static code analysis etc. I hate to admit it, but for the first few days (and even now) I couldn't tell which was up and which way was down, nothing made sense.

- Installation was a nightmare. Workplace uses windows, so the usual dance of installing the jdk, setting the env variables, creating a project in eclipse and for some reason it uses the jre instead of the jdk. Some plugins/packages such as lombok work in eclipse but not in vs code! And even in eclipse there's some annotation (@Data I think) that's supposed to generate getters and setters but it doesn't work.

- Flexible architecture : some use service, serviceimpl and controllers. Some skip the service interface. And it turns out you can extend crudrepository and have a fully functioning rest endpoint without writing any code using spring data rest!

- Magic : this is incredibly frustrating. Some repository types are automatically exported, some are not and the docs do an atrocious job of explaing what's going on. Place some file abc.xyz in the root and magic happens!

- Docs : the single worst part of learning spring boot, especially for newcomers. How can the docs possibly be so insensitive to newcomers? Or do they expect only experienced devs at big cos to use spring boot?

- I hate to admit this, but I still don't know what a god damn bean is, what AOP is, what inversion of control is.

This was mainly a rant and a bad one at that, but I had to vent.

  • by karmakaze on 8/4/19, 4:07 AM

    I would say that you were likely more successful than the typical first time exposure using Sprint Boot.

    Your comments also sound spot-on to much of my first time exposure to Spring (pre Boot). I've used Spring and Spring Boot on many projects since and it wouldn't be my first choice. It tends to be selected for its popularity which means there are StackOverflow answers, pretty good support for common use cases, and a large pool to hire from.

    At the same time, Spring Boot (or even just Spring) aren't the worst once you get used to them. I myself have come to dislike other aspects of it (e.g. slow startup, JPQL and Hibernate quirks, excessive gc, poor scaling). Most of these things probably won't have much of an impact until the application gets to a certain level of complexity or scale. But if it wasn't about solving for the future, Ruby or Python would be better to start.

  • by tmm84 on 8/7/19, 4:22 AM

    I've been programming in Java since I started working as a programmer. Learning to setup a Windows machine for Java development is difficult if you aren't familiar with environment variables and the like.

    Java, like C++, has gotten more and more features/keywords over the years. Frameworks like Spring Boot tend to make use of those features. Also, Spring Boot is a sit down and read the guides compared to something like Rails or ExpressJS and the like. Depending on your Java knowledge the documentation is going to be hit or miss I think. Also, convention over configuration makes it harder for new developers to get the hang of developing with a framework like Spring Boot because they don't know the conventions usually.

  • by jryan49 on 8/4/19, 3:56 AM

    It really doesn't take that long to read the Spring docs. I know a few days for some devs is an eternity though. The magic can be frustrating though and burn you. When you have millions of lines of code in a project though, AOP and Spring can make your life bearable. I'd much rather spend the time to learn some magic than have to deal with that much boilerplate. Spring is most likely overkill for a small/medium sized project.
  • by maynman on 8/6/19, 3:39 PM

    One suggestion I have is to try using Intellij as your IDE. It has some built in integrations that make spinning up a new spring boot project a lot simpler.

    Or, if you really like using an IDE that doesn't offer these integrations, then another option is to make use of this page: https://start.spring.io/

    It makes the initial setup easier.

  • by mr_puzzled on 8/3/19, 7:56 PM

    Continuation:

    I will likely be changing teams soon, so hopefully this will be the last time I use spring boot.

    Now I am not a complete noob to webdev. I have worked with django extensively and I have had a pleasant expereince with it. Everything is so beuatifully thought out, the docs are wonderful and I am never left scratching my head wanting to curse at the top of my lungs.

    I'd love to hear your thoughts on this topic.

  • by codegladiator on 8/3/19, 8:40 PM

    either you go in with a mentor to understand spring or read their docs like a book for a day or two. otherwise everything will feel like your point 3, magic

    spring definitely feels like magic for first 6 months.

    aop and ioc exist outside of spring and java as well.

  • by AwesomeFaic on 8/6/19, 6:27 PM

    I use Intellij with Spring and all that jazz at work. Massive enterprise software. I don't hate it, but boy, I can see why these behemoth applications move at a snail's pace.
  • by yasp on 8/3/19, 8:04 PM

    You mention Django. What amount of experience with Java did you have going into this? IMO Java development has a steeper learning curve than Python development.
  • by BjoernKW on 8/4/19, 1:24 PM

    #1 is a mostly Windows-related problem. You would've had similar issues with a Ruby- or JavaScript-based stack, probably much more so because Java generally is quite decent in terms of platform-independence. With other environments you often have to deal with native binaries or compiling for your specific architecture, which can get messy if things don't work as expected during installation.

    I agree that the magic behind autowiring different types of Spring Data repositories can be quite confusing.

    The Spring Boot documentation in general is quite good, though. There are many how-tos and specific examples with working source code. Apart from Pivotal's (the company that's the main maintainer of Spring and Spring Boot) own resources, https://www.baeldung.com/ and https://www.mkyong.com/ are fantastic for learning about Spring and Spring Boot, too.

    Concepts such as AOP or inversion of control aren't exclusive to Spring Boot (or Java, for that matter). It's useful to learn about them anyway and yes, if you don't know about those subjects before starting with Spring Boot you're in for quite a steep learning curve because you'll not only have to grasp the ins and outs and implementation details of a new framework but understand entirely new abstract concepts at the same time as well.

    As for beans specifically, the definition of that term within the larger context of Java has varied a bit over time so there might be at least some ambiguity here, which can lead to understandable confusion. Traditionally, a bean in Java is a class which a.) is serialisable, b.) has a zero-argument constructor and c.) has getters and setters for modifying the internal state of its instances. Due to these properties beans lend themselves to storing and passing application state (for example in the larger context of a dependency injection environment).

    With Spring and Spring Boot, 'bean' usually refers to the @Bean annotation that allows to have a method return an instance of a particular class, which will then be made available to other components of the application through Spring's dependency injection.

    The @Bean annotation leaves the object instantiation and wiring to the user (see https://www.baeldung.com/spring-bean ) whereas other Spring annotations such as @Component or @Service (both are so-called stereotypes, with @Component being the more generic one that simply marks a class as 'managed by Spring' while @Service denotes that the component in question is to be used within the application's service layer. See https://www.baeldung.com/spring-component-repository-service) delegate wiring to Spring dependency injection.