Does Grails use Spring Dependency Injection by default - spring

An additional question: What is service layer in Grails app?
Thanks

Yes, Grails uses Spring Dependency Injection by default. Grails is in fact Spring at the core of it all.
Your second question, "what is a service layer" is best described as singleton instances of classes that serve as a layer of abstraction and encapsulation of business logic.

Related

This is in the company requirement list, I want to know the difference between them

what is the difference between spring core, spring boot, and spring MVC?
In Simple terms,
Spring MVC
Spring - It is a Inversion of control (IOC) and Dependency Injection (DI) framework. Spring helps you develop enterprise applications. Most information you can read here https://spring.io/projects/spring-framework
MVC - It is a design pattern (Model - View - Controller ) MVC , by definition, they are proven patterns and methods to design your application well. We have several design patterns such as Singleton, Factory pattern etc Read more about it here https://refactoring.guru/design-patterns
Spring-boot - It is a library built on top of Spring framework (like we have JARs) which helps develop production ready quick service oriented applications. You can still use typical Spring features. Read more about it here https://spring.io/projects/spring-boot
Spring-core - Just a named terminology representing core features of Spring framework such as IOC container, Dependency Injection, Bean scopes, Autowiring etc
Hope this helps!

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.

Migrating application from Spring to CDI

I would like to migrate an application from Spring 3 to Weld. In order not to rewrite the whole bean configuration at once, it would be cool if I could inject part of the application that is still written in Spring in the new CDI part.
Is that possible?
This should be possible. CDI has an extension system where you can hook into the injection mechanism. From there you can manually bootstrap your Spring beans and then return those.
I wouldn't be surprised if there's already an extension for this, so before looking into writing one yourself check if there's not one already.
There have been a few attempts at making CDI and Spring work together. Take a look at CDI Advocate for one.
It comes down to how much of your app is spring. If you're running something like Spring MVC, it'll be very difficult since it manages essentially your whole app.

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.

Resources