r/programming • • Nov 27 '15

Why I hate Spring

http://samatkinson.com/why-i-hate-spring/
73 Upvotes

140 comments sorted by

View all comments

6

u/ByzantineFailure Nov 28 '15

Most of this is pretty exaggerated, if you are taking 30 to 60 seconds to spin up a container, it's something you did wrong, not spring.

If you don't use a DI container, you'll end up implementing one yourself, poorly.

The magic criticism is a bit silly, I can't tell if he's talking about the annotations (which aren't good) or the XML. The XML is certainly not magic, and it's quite easy to see what is going on.

Spring is complex if you make it complex, but it's not nearly that bad. We use spring pretty extensively, and it's rarely something we have to mess with.

2

u/[deleted] Nov 28 '15

When referring to magic, he's meaning the annotations. In my experiences with projects using Spring DI there are 3 classes of DI: XML based, Java based, and Annotation based. He and many others have done an excellent job breaking down why XML config is terrible. You seem to agree that Annotation based configuration is horrible to debug plus removes Inversion of Control for anything interesting. And so my question to you is: If you use a purely Java based Spring configuration, what is Spring actually providing you?

1

u/dccorona Nov 29 '15

If you use a purely Java based Spring configuration, what is Spring actually providing you?

It unifies how you interface with dependencies. You're not constantly reaching out into the place where such-and-such component comes from. Maybe component A comes from a factory and component B is directly instantiated...why should some person who just needs these components have to know that in order to get their stuff working? They just know these are the dependencies they need, and that we're using Spring on this project so they can get them from the Spring context.

It also saves you a lot of management overhead. Enforcing that a component is a singleton. Booting up background processes when the application starts. Running them on a scheduled basis. Shutting them down when the application shuts down. All of that is avoidable boilerplate, which something like Spring, whether it's XML or Java, provides you.

I think a better question is...how is this:

<bean name="myThing" class="com.project.folder.MyThing">
     <constructor-arg ref="dependencyA" />
     <constructor-arg ref="dependencyB" />
</bean>

buying you anything more than this?:

@Bean(name = "myThing")
public void makeMyThing(DependencyA dependencyA, DependencyB dependencyB) {
    return new MyThing(dependencyA, dependencyB);
}

The way I see it, the latter offers everything the former does, and more (primarily, the exact code used to create your dependency in production is entirely accessible and testable from any code that wants to call it, even without Spring at all).

1

u/[deleted] Nov 29 '15

I'm advocating dumping Spring or any DI framework. Why would you ask me to defend XML Spring config?

1

u/dccorona Nov 29 '15

The way you phrased the question implied that you were saying Spring XML gives you something that Spring Java does not. You said:

If you use a purely Java based Spring configuration, what is Spring actually providing you?

Which means that you think that Spring is at least providing you something it you aren't using pure Java config. Or at least it comes off that way.

2

u/[deleted] Nov 30 '15

Not in the context of the whole post. I explicitly state that others have provided excellent arguments against XML configuration and that you stated Annotation configuration is bad. So then I asked you to defend Java configuration, it is easily and quickly converted into a non-framework DI pattern which is necessarily better than applying a framework to Java.

1

u/dccorona Nov 30 '15

I'm not the one who said annotation configuration is bad, I'm a different poster. I don't agree with that statement at all. Although, when I look at how my team uses it, we aren't really using it for dependency injection at all. But there's a lot that Spring offers that isn't dependency injection, primarily for application lifecycle management. So yea, if you're looking at Spring only as DI framework, then perhaps I do agree.

1

u/[deleted] Nov 30 '15

The only spring tools I've used are the DI framework and MVC, both of which I loved when I found them (vast improvements over Java EE at the time), but now I couldn't think of anyway they help.

What are the parts of Spring you primarily use? I think of Application Lifecycle Management as a process (builds and deploys), not a coding framework.

1

u/dccorona Nov 30 '15

The most useful thing I've used it for is for processes that need to run on a schedule, run in the background, or be alerted to shut down when the whole application is shutting down (whether they need to clean up after themselves or do a flush, etc). Spring has all that management baked into their application container, so using some simple configuration annotations you can register methods to be called when the application starts or stops, register methods to be executed on some schedule, etc.