Spring Boot Dependency only for Dependency Injection Features? - spring

I just started a Compose for Desktop project with Kotlin. So there is no web stuff I am used to. This is why I did not use Spring stuff from the beginning.
However after a while I kind of miss dependency injection ;)
I tried to look for a spring boot / spring framework dependency that only has functionality like #Service, #Component, #Autowired etc. I was not able to find anything. This always was somewhat included into other contexts like Spring-Boot-Web etc.
So my question: Is there a Dependency Injection Only library with spring?

Related

Spring vs JAX-RS

Here, several questions have been asked by many developers about difference between Spring-Rest and JAX-RS.
And, I have also learned that Spring is not following any specification and Spring framework has their own implementation then
Why Spring allows all that Annotations which are supported/used by JAX-RS by default?
Spring does not support JAX-RS annotations. If there is a situation where you think they do, then you are mistaken or it's just a coincidence. Period. If you will add any JAX-RS annotations in my Spring MVC program, nothing will happen. Annotations are just metadata. They are not programs. If Spring does not recognize the metadata, it will ignore it. But if you use a JAX-RS annotation in place of a Spring annotation that is used for the same purpose, respective of their framework, then you will not get the expected Spring behavior. So basically, if you are using Spring MVC, remove any JAX-RS dependencies so you don't mistakenly use them.

What Spring annotations can we use in Hybris commerce project?

I was reading about Spring core module and came across Spring annotations that I did not see till now in the Hybris project:
#Component,#Qualifier
Are these used in Hybris projects?
Hybris uses both. Annotation Injection and XML Injection. You can also use both. I recommend you, to define a clear strategy when you use which one.
For example:
Controller - Annotation Injection
Facade - XML Injection
Service - XML Injection
To your point, which kind of Annotation you should use, have a look here:
What's the difference between #Component, #Repository & #Service annotations in Spring?
In common said, there is not really a different. It's just nice to use the correct Annotation for the correct class.
Hybris 6.6 uses Spring 4.3. The usual annotations like #Autowired, #Required, #Controller, and many others should work.
If you have access to Hybris Help, have a look at "Spring Framework in SAP Commerce": https://help.hybris.com/6.6.0/hcd/8c63621986691014a7e0a18695d7d410.html
There is:
Dependency Injection
Interface-Driven Design
Beans (and aliasing)
Spring Profiles
Spring MVC
Spring Integration
etc

Ioc Container: Dependency Injection, Dependency Lookup?

I am trying to understand Spring Framework more what I know currently, and I am referring to "Pro Spring 3" book.
I came across the following section in the book as below:
It says that in general IoC can be decomposed into two components viz:
Dependency Injection and Dependency Lookup.
With respect to this, I have following questions:
1) Do Spring provide both Dependency Injection ,Dependency Lookup ?
2) Do all Ioc container have both these systems viz: Dependency Injection ,Dependency Lookup?
3) If Spring provides both Dependency Injection ,Dependency Lookup, then isn't it wrong to say that Spring is DI framework, when it has both these capabilities?
1: Yes, Spring provides both dependency injection and dependency lookup. You can let Spring inject dependencies using for example the #Autowired annotation, and you can also manually lookup components from Spring's ApplicationContext by calling one of the getBean methods.
The main thing to understand about the concept "inversion of control" (IoC) is that Spring does the work for you, instead of the other way around: you let Spring create instances of your components, and you let Spring inject the dependencies, instead of the other way around, where you write code yourself to create instances and lookup dependencies.
2: No, not necessarily.
3: Spring can do dependency injection (DI), so it is a DI framework. Just because it also does other things (such allow you to lookup components explicitly) doesn't suddenly not make it a DI framework anymore.

CDI annotated classes used both in EE6 context and Spring DI context

I have an issue concerning a jar declaring CDI annotated beans, and used both in a spring context and an EE6 context.
This jar, say service.jar, contains classes that are annotated with qualifiers (#Qualifier, allows you to declare your own annotations such as #DataAccessObject in order to identify your beans), and has private members annotated with #Inject.
It's compiled with maven, and it's dependency to javax.javaee-api is declared as provided, because these classes are only needed when deployed within an EE6 context.
Though, there's something that I don't understand. In this service.jar, once compiled, and whether I deploy it in an EE6 context or not, the bytecode references classes such as javax.inject.#Inject.
So why my spring application - which has no javax.javaee-api jar in its classpath - is able to load its configuration correctly and run ?
I was even more confused when I learned that spring provides support for #Inject (JSR 330) annotation.
Can anyone enlighten me on that ?
Thanks.
You must not confuse DI (JSR330) and CDI (JSR299). CDI includes DI. All those javax.inject Annotations belong to DI and are supported by many frameworks (spring and guice for example).
If you strictly reduce your jar dependencies to JSR330 (no need to switch Java EE deps for deployment), you will be able to use any of the supporting frameworks.
Checkout this example: http://www.mkyong.com/spring3/spring-3-and-jsr-330-inject-and-named-example/

spring 3.0.5-RELEASE and javaconfig

what is the correct maven dependency for spring 3.0.5-RELEASE and the javaconfig features (#Configuration, #Bean, etc.)?
I tried this:
http://mvnrepository.com/artifact/org.springframework.javaconfig/spring-javaconfig
But I got the error described here:
http://forum.springsource.org/showthread.php?t=74730
That thread seems to imply that javaconfig is bundled with spring 3, but when I remove the explicit spring-javaconfig dependency (1.0.0.m3) it can't find the symbols.
I'm sure I'm missing something simple...
JavaConfig is part of core Spring as of Spring 3.0. So you just need to have a dependency on spring-context.

Resources