6 ms·
I used to joke that the direction spring was heading was that you’d have an application be a boilerplate main method with a dozen lines of annotations. Then I a
by dhosek 1y ago
I used to joke that the direction spring was heading was that you’d have an application be a boilerplate main method with a dozen lines of annotations. Then I actually encountered this in the wild: we had an app that sent updates from db2 to rabbitmq, and the application literally was just configuration via annotations and no actual Java code other than the usual spring main method.
- bdangubic 1y agothis is exactly why spring succeeded. I need to run a scheduled job, @EnableScheduling then @Scheduled(cron = “xxxxxx”) - done. I need XYZ, @EnableXYZ the @XYZ… sh*t just works…
- vbezhenar 1y agoYeah, it works until it isn't. And they good luck debugging it. I'd prefer simple obvious linear code calling some functions over this declarative magic any day. cronService.schedule("xxx", this::refresh); This isn't any harder than annotation. But you can ctrl+click on schedule implementation and below easily. You can put breakpoint and whatnot.
- bdangubic 1y agonever had any issues debugging as I am never debugging the scheduler (that works :) ) but my own code. and what exactly is “cronService”? you write in each service or copy/paste each time you need it?
- alex_smart 1y agoYou can write your own libraries? My goodness. What a question!
- bdangubic 1y agoyou write your own database driver? encryption?
- alex_smart 1y agoWhy would I write my own database driver or encryption just because I wanted to implement my own "cronService"?
- blackoil 1y agoIf you want to build an application from scratch, you must first create the universe.
- alex_smart 1y agoAll this because I told one guy who asked "what exactly is “cronService”? you write in each service or copy/paste each time you need it?" that they can reuse code by writing a library instead of copy/pasting it? If this is the level of incompetence encouraged by a framework, I would avoid using it just to avoid the chance of hiring people like you. Just kidding. Spring boot is great. But yeah, I would fire people with this attitude without blinking an eye.
- bdangubic 1y ago* Why would I write my own database driver or encryption just because I wanted to implement my own "cronService"?* how do you decide whether you will write your own or pull in a dependency? this is a legit question. you did start this with writing your own “cronService” (which is about as insane as writing your own database driver) so asked about it.
- alex_smart 1y ago> you did start this with writing your own I really did not. I only said that if you were to create your own cronService, you can reuse it by creating your library rather than copy pasting code (which is obviously insane). > which is about as insane as writing your own database driver No, it is not. Spring Boot’s support for async jobs and scheduled jobs is lacking. A lot of people roll their own. Including yours truly. It is also much easier than writing a database driver so there is that.
- throwaway7783 1y agoWhole point of spring is so you don't have to write your own libraries. Batteries included and all.
- bdangubic 1y ago@alex_smart hand rolls it all :)
- alex_smart 1y agoWhat if I told you - you can use a batteries-included framework, and still write your own libraries specifically only for things you want your own version of and want to share across projects? The problem isn't that I don't know how to use a batteries included framework. The problem is that you guys don't know there is even an option to reuse your code by writing libraries.
- throwaway7783 1y agoWhy are you assuming you cannot write your own library and use it with Spring? It's not an either/or, just like most frameworks are. You are framing it as if there is only one way to do it in spring. Please do not project things like "you guys don't even know..". I'm one of "you guys" , and have built production code in a variety of languages and frameworks. So this "you guys" knows exactly what he/she is talking about.
- alex_smart 1y ago> Why are you assuming you cannot write your own library and use it with Spring? I am not. I am literally saying the exact opposite.
- throwaway7783 1y agoOkay, that's fair. I don't even know anymore what point you are trying to make.
- vbezhenar 1y ago`cronService` is an injected instance of some class, probably provided by framework. My point is to demonstrate alternative, imperative way of defining cron tasks, as compared to declarative one.
- vips7L 1y agoA better name would probably be CronScheduler or something else. “Service” is always overused and doesn’t actually describe or mean anything.
- skeletal88 1y agoThen you need to deploy it on multiple nodes and neex to make sure it only runs once for each run of the cron, etc.
- bdangubic 1y agowhile not working on out of the box clustered this is trivial issue to address
- didntcheck 1y agoI believe Quartz is the go-to solution for this. It's not part of Spring but it offers a similar annotation-driven interface, but with distributed locking via a database
- bdangubic 1y agoAbsolutely! But Quartz is also quite heavy. If all you need is to ensure scheduled jobs run in a clustered environment there are more “lighweight” options
- happymellon 1y agoLike Shedlock?
- taftster 1y agoAnd then I realize I need to change that schedule. And would like to do it without recompiling my code. Oh, and I need to allow for environment specific scheduling, weekdays on one system, weekends on others. And I need other dependencies that are environment specific. I much prefer Spring's XML configuration from the old days. Yeah, XML sucks and all that. But still, with XML, the configuration is completely external from the application and I can manage it from /etc style layouts. Hard coding and compiling in dependency injection via annotations or other such behaviors into the class directly has caused me grief over the long term pretty much every time.
- nunobrito 1y agoThe only real-world usage I see for annotations are in GSON (the @Expose) and JUnit with @Test. Never really came across with any other real cases where it solves a pressing issue as you mention. Most times is far more convenient to do things outside the compiled code.
- taftster 1y agoAgreed. These are good examples where annotations seem like a good fit. Being able to tell a processor that a method or field is "special". Test methods, serializable hints, etc. It's kind of like, when annotations were delivered to Java, lots of projects thought they were just the next greatest thing. I followed right along at the time, as well. But over time, finding the value in the configuration-as-code approach to application deployment, I definitely feel that annotations have been abused for many use cases.
- bdangubic 1y agoall trivial things you are listing, every single one…
- sass_muffin 1y agoI do realize you were intending to give examples of why you don't think annotations aren't very extensible, but it is an odd example as all those things can still be achieved via annotation, since the annotations can accept values loaded from env specific properties.
- mikelpr 1y agowhy does this sound like systemd?
- 9dev 1y agoIs that strictly bad, though? Being able to run an enterprise service by setting configuration values declaratively, and get all the guarantees of a well-tested framework, seems like a pretty good thing. Yes, it’s weird how that’s still Java, but using standard components and only using code as glue where it’s absolutely necessary seems very similar to other engineering disciplines to me.
- SkiFire13 1y agoI think the general adversity against this specialized configurations is that they often tend to be fairly limited/rigid in what they can do, and if you want to customize anything you have to rewrite the whole thing. They effectively lock you into one black box of doing things, and getting out of it can be very painful.
- 2muchcoffeeman 1y agoSpring boot just provides what they think are reasonable defaults and you provide some specifics. You can always inject your own implementation if needed right?
- _ea1k 1y agoIn theory, yes. In practice, I've found that things get really complicated as soon as you start trying to interact with the spring lifecycle. Figuring out how to customize things and manage priority is the trickiest thing in Spring, IMO.
- lenkite 1y agoPlease use the facilities of the framework for debugging any lifecycle issues. I was surprised when I found out that people did not use `--debug` for example or enabled logging of application startup events. If you prefer GUI, Intellij even has a Spring Debugger: https://www.jetbrains.com/help/idea/spring-debugger.html https://www.jetbrains.com/help/idea/spring-debugger.html