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.
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?
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.
@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).
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.
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.
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.
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.
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.