1

I'm trying to use Jakarta jnosql Artemis along with a Spring Boot application. Artemis requires a CDI (Context and Dependency Injection) implementation to be provided. Overall, Spring Framework does it, however it implements it's own, similar interface org.springframework.web.SpringServletContainerInitializer, but Artemis seems to require exact implementation of SeContainerInitializer.

Does any class from a Spring ecosystem implement SeContainerInitializer or SeContainer?

or

Is it possible to use Jakarta jnosql Artemis with a Spring Boot application?

If yes - how? A simple example of Spring Boot using Jakarta jnosql Artemis graph to insert and query would be great.

If no - why? Especially, is it a temporary (will Spring implement it in a future) or a permanent state?

I explicitly do not want to use Spring Data.

I am aware, that they do provide a similar solution to Jakarta jnosql Artemis.

Two years ago a similar question was asked [ https://stackoverflow.com/questions/68592784/using-jnosql-cdi-library-with-spring-boot-bean-not-found ], and one of the comments claimed that Spring does not implement that interface. I would like to know if that has changed or is going to change. Answer also suggested Spring Data, which I do not want to use.

I tried setting up a Spring Boot application and using @Inject annotation to inject classes like GraphTemplate (from Artemis). Spring throws an exception, that it is unable to find any bean to inject of that class.

I have also found an application on Github that has a working example of Jakarta jnosql Artemis with Weld (CDI implementation). Then I tries to replace Weld with Spring Boot, however I cannot find an implementation for an interface SeContainer.

xinus01
  • 47
  • 1
  • 8
  • **Does any class from a Spring ecosystem implement SeContainerInitializer or SeContainer?**. No and it won't. – M. Deinum Aug 03 '23 at 14:25
  • @M.Deinum ok, but why? – xinus01 Aug 03 '23 at 14:31
  • Because Spring isn't a CDI implementation. – M. Deinum Aug 03 '23 at 18:03
  • @M.Deinum Why is it not, if it does CDI? They have implemented nearly identical (but own) interface. Any why do you say that they will not implement Jakarta CDI? Please elaborate, I would like to understand a whole story behind it. – xinus01 Aug 04 '23 at 11:17
  • In the JNoSQL site, it says "Diana plus CDI equals to Artemis". So, maybe Artemis *minus* CDI is Diana - and that may be what you want? – Nikos Paraskevopoulos Aug 13 '23 at 16:21
  • Spring pre-dates CDI, they don't do CDI they do dependency injection. They do support (some) of the CDI annotations but aren't themselves and will not be a CDI container (at least not in the forseable future). – M. Deinum Aug 14 '23 at 06:27
  • @NikosParaskevopoulos this is how I'm using it right now, but it means, that I need to do what Artemis does by hand, and that's suboptimal. – xinus01 Aug 14 '23 at 14:54
  • @M.Deinum I see. It explains why Spring didn't implement it in the past, but why won't it implement in a future? What can CDI do that Spring cannot? Could you please provide an example? – xinus01 Aug 14 '23 at 14:55
  • 1
    It is more the other way around what can Spring do what CDI cannot. Spring is more capable then CDI as CDI is injection only whereas spring can create proxies, do AOP etc. etc. – M. Deinum Aug 15 '23 at 06:16
  • @M.Deinum thank you, that helps to understand. Now I'm missing a last puzzle - why doesn't Spring want to implement CDI interface? – xinus01 Aug 17 '23 at 13:16
  • 1
    Because they are different. While similar they are still different in respects to how dependencies are managed, scopes etc. There was CDI - Spring bridge years ago (some open source project) but I doubt that that is still maintained. It is alos not a matter of "just a CDI interface" it is a whole Specification which you need to adhere to. So while it might seem like "just an inteface" it isn't. – M. Deinum Aug 17 '23 at 13:26

1 Answers1

1

Does any class from a Spring ecosystem implement SeContainerInitializer or SeContainer?

No, they won't/can't. Spring is not a CDI implementation. Spring does seem to borrow some CDI interfaces/annotations occasionally, but that does not mean it implements the CDI Specification or could even hope to pass the CDI TCK. While CDI and Spring serve a similar/related purpose, Spring is just its own thing.

Some concepts that exist in CDI don't exist in Spring and vice-versa, for better/worse.

There's a bit of history to this. The idea of Runtime Dependency Injection manifested itself J2EE a long time ago (Late 2000s era). This required Application Server Vendors (like IBM) to implement the specifications in their containers (like WebSphere).

Spring designers were frustrated at the pace of J2EE feature development and created an alternate and different framework called Spring Framework, a full stack enterprise framework. At no point was compatibility with J2EE specifications a concern, although certain parts of Spring could interact with J2EE servers.

Fast forward and that legacy lives on: Spring is it's own framework that does not implement the JavaEE/JakartaEE specification; but Spring can call into parts of it or borrow some of the annotations. But for the most part you can't pull in components designed for CDI into Spring and vice-versa. It's just two different worlds.

Jonathan S. Fisher
  • 8,189
  • 6
  • 46
  • 84
  • 1
    Thank you for a background. If Spring is not a CDI but can interact with CDI, does it mean, that it is possible to use Spring with Jakarta Artemis (that requires CDI), as long as additionally to those two, a CDI implementation is provided? If yes, are you able to provide an example of Spring app with Artemis? – xinus01 Aug 17 '23 at 12:15
  • Spring does not Interact with CDI. It does not start a CDI runtime. It can _read_ CDI annotations and do stuff with them, but Spring does not start a CDI runtime and cannot interact with a CDI Runtime. Spring CAN interact with JakarataEE components though, but I think you should skip that. Instead, you need to have spring connect directly to Artemis and don't mess with CDI at all. – Jonathan S. Fisher Aug 17 '23 at 14:52
  • Maybe something like this? https://1kevinson.com/springboot-artemis-broker/ – Jonathan S. Fisher Aug 17 '23 at 14:52
  • Unfortunately no. This shows integration with Artemis MQ (AMQ) and not Jakarta jnosql Artemis. Unfortunately name is identical, but first is a message queue and second one is ORM (Object-Relation Mapper). I'm looking for an example with second one (ORM). – xinus01 Aug 18 '23 at 13:37