What Spring annotations can we use in Hybris commerce project? - spring

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

Related

Spring Boot Dependency only for Dependency Injection Features?

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?

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.

Spring can be used in Seam?

I understand that Spring has really nice features, such as dependency injection. I am new to Spring. I have understood that I can use Spring alongside with struts and other frameworks too, in order to use its capabilities.
In my project I am going to use Seam 2.0, I am using JNDI to lookup for the EJBs. I am wondering if I can integrate Spring with Seam and use its ApplicationContext in order to get beans from that directly and not use JNDI lookup anymore?
There is a whole chapter in the Seam reference dedicated to this:
27. Spring Framework integration

Manage beans via Spring or via JSF

In my JSF Webapp I am using Spring vor DI etc.
At the moment I have my beans managed by Spring.
(SpringBeanFacesELResolver defined in faces-config.xml)
But I'm not sure, if this is the right way...
For example: A bean defined in Spring cannot use the new JSF 2 view scope, right?
My question is not, if I should use Spring or not... Just HOW to manage my beans?!
You should in any case stick with one DI in your project. For me, Spring is clearly much more powerful that JSF managed beans. So I would opt to Spring in this situation.
You can hanlde view scope in Spring using custom scopes, it is quite straigtforward actually. Here's a blog post on this question.

Which Spring annotation to use for Hibernate DAO class?

What Spring annotation should I use for Hibernate DAO classes so they could be found in scanning process? #Repository, #Service or #Component? I couldn't figure out the difference. I'm on Spring 2.5.6 now.
P.S. Can someone guide me quickly through the layer idea? I only have heard a thing like presentation layer, but don't have exact understanding what should I call so and what is the business layer? Are there other?
#Repository would be my recommendation.
Presentation tier means web UI, so those should use the #Controller annotation.
Services implement use cases using POJO interfaces; mark this as #Service. Controllers will use services to fulfill use cases.
It doesn't matter much, but #Repository is a good bet. The Spring manual has this to say:
Beginning with Spring 2.0, the
#Repository annotation was introduced
as a marker for any class that
fulfills the role or stereotype of a
repository (a.k.a. Data Access Object
or DAO)
In core Spring, I don't believe there is any difference. Generally, these stereotype annotations are used for auto-detection when using annotation-based configuration and classpath scanning (from Spring docs). It is possible to have some software to make use of them but in absence of such software I choose stereotype that makes most sense to me. In case of DAO I usually choose #Component, although #Repository is a good option as well.

Resources