Spring Flashcards

1
Q

What is IOC?

A

A key characteristic of IOC is the calling code has the ability to customize the calling methods according to an external configuration (XML) file. The most common implementation of IOC is dependency injection.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is dependency injection?

A

A software design pattern that promotes the single responsibility principle, which is simply saying that one module of a project only does one thing, and it does it well.

It uses a Builder pattern to obtain valid instances of your object’s dependencies and pass them to your object during the object’s creation and/or initialization. Using polymorphism and interfaces, the class that needs the dependency does not need to reference the concrete class type. Instead, you declaratively express dependencies through a configuration medium (like XML). The main goal is to decouple classes and test concrete classes in isolation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is decoupling?

A

Decoupling is also known as loose coupling, or loosen the relationship between two classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is isolation testing?

A

Isolation testing is the process of breaking down the system into various modules so that defects can be spotted easily in isolation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the different types of dependency injection and which does Spring support?

A

● Constructor Injection (Pico container, Spring etc):
● Setter Injection (eSpring):
● Interface Injection (Avalon): Note: Spring supports only Constructor and Setter Injection

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Constructor Injection in Spring?

A

Dependencies are provided as constructor parameters.

We can inject the dependency by constructor. The tag constructor-arg subelement of tag bean is used for constructor injection.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Setter Injection in Spring?

A

Dependencies are assigned through JavaBeans properties (ex: setter methods).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Interface Injection in Spring?

A

Injection is done through an interface.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the benefits of IOC?

A

● Minimizes the amount of code in your application.
● Make your application more testable
● Loose coupling is promoted
● IOC containers support eager instantiation and lazy loading of services.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does IOC minimize code?

A

With IOC containers you do not care about how services are created and how you get references to the ones you need. You can also easily add additional services by adding a new constructor or a setter method with little or no extra configuration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does IOC make application testable?

A

By not requiring any singletons or JNDI lookup mechanisms in your unit test cases. IOC containers make unit testing and switching implementations very easy by manually allowing you to inject your own objects into the object under test.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How does IOC promote loose coupling?

A

With minimal effort and least intrusive mechanism. The factory design pattern is more intrusive because components or services need to be requested explicitly whereas in IOC the dependency is injected into requesting piece of code. Also some containers promote the design to interfaces not to implementations design concept by encouraging managed objects to implement a well-defined service interface of your own.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How does IOC support eager instantiation and lazy loading of services?

A

Containers also provide support for instantiation of managed objects, cyclical dependencies, life cycles management, and dependency resolution between managed objects etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is Spring?

A

Spring is an open source framework created to address the complexity of enterprise application development. One of the chief advantages of the Spring framework is its layered architecture, which allows you to be selective about which of its components you use while also providing a cohesive framework for J2EE application development.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are some features of Spring?

A
● Lightweight: 
● Inversion of control (IOC): 
● AsWhat are some features of Spring?pect oriented (AOP): 
● Container: 
● MVC Framework: 
● Transaction Management: 
● JDBC Exception Handling:
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What makes Spring lightweight?

A

Spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 1MB. And the processing overhead is also very negligible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is Spring Inversion Control?

A

Loose coupling is achieved in spring using the technique Inversion of Control. The objects give their dependencies instead of creating or looking for dependent objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is Spring Aspect oriented Programming(AOP)?

A

Spring supports Aspect oriented programming and enables cohesive development by separating application business logic from system services.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is Spring Container?

A

Spring contains and manages the life cycle and configuration of application objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is Spring MVC Framework?

A

Model View Controller

Spring comes with MVC web application framework, built on core Spring functionality. This framework is highly configurable via strategy interfaces, and accommodates multiple view technologies like JSP, Velocity, Tiles, iText, and POI. But other frameworks can be easily used instead of Spring MVC Framework.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is Spring Transaction Management?

A

Spring framework provides a generic abstraction layer for transaction management. This allowing the developer to add the pluggable transaction managers, and making it easy to demarcate transactions without dealing with low-level issues. Spring’s transaction support is not tied to J2EE environments and it can be also used in container less environments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is Spring JDBC Exception Handling?

A

The JDBC abstraction layer of the Spring offers a meaningful exception hierarchy, which simplifies the error handling strategy. Integration with Hibernate, JDO, and iBATIS: Spring provides best Integration services with Hibernate, JDO and iBATIS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Name the modules of Spring.

A

The basic Spring Framework contains the following libraries grouped by functionality.

  1. Core Container
  2. Test
  3. AOP
  4. Instrumentation
  5. Web and Remoting
  6. Data Access and Integration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is Bean Factory?

A

A BeanFactory is like a factory class that contains a collection of beans. The BeanFactory holds Bean Definitions of multiple beans within itself and then instantiates the bean whenever asked for by clients.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What does a Bean Factory do?

A

● BeanFactory is able to create associations between collaborating objects as they are instantiated. This removes the burden of configuration from bean itself and the beans client.
● BeanFactory also takes part in the life cycle of a bean, making calls to custom initialization and destruction methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What is Application Context?

A

A bean factory is fine to simple applications, but to take advantage of the full power of the Spring framework, you may want to move up to Springs more advanced container, the application context. On the surface, an application context is same as a bean factory.Both load bean definitions, wire beans together, and dispense beans upon request.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

ApplicationContext will preinstantiate singleton beans and also provides:

A

● A means for resolving text messages, including support for internationalization.
● A generic way to load file resources.
● Events to beans that are registered as listeners.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What is the difference between BeanFactory and ApplicationContext ?

A

On the surface, an ApplicationContext is the same as a the bean factory, but it offers much more..

● ApplicationContext preinstantiates the beans (Singletons) while BeanFactory does lazy initialization.
● ApplicationContext provides a means for resolving text messages including support for I18N.
● ApplicationContext provide a generic way to load file resources such as images.
● ApplicationContext can publish events to beans that are registered as listeners.
● Certain operations on the container or beans in the container, which have to be handled in a programmatic fashion with a bean factory, can be handled declaratively in an application context.
● ResourceLoader support: Spring’s Resource interface us a flexible generic abstraction for handling low-level resources. An ApplicationContext itself is a ResourceLoader, Hence provides an application with access to deployment-specific Resource instances.
● MessageSource support: The ApplicationContext implements MessageSource, an interface used to obtain localized messages, with the actual implementation being pluggable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What are the common implementations of the Application Context ?

A

The three commonly used implementation of ‘Application Context’ are
●ClassPathXmlApplicationContext: ●FileSystemXmlApplicationContext :
● XmlWebApplicationContext :

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What does ClassPathXmlApplicationContext do?

A

It loads context definition from an XML file located in the classpath, treating context definitions as classpath resources. The application context is loaded from the application’s classpath by using the code .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What does FileSystemXmlApplicationContext do?

A

It loads a context definition from an XML file in the file system. The application context is loaded from the file system by using the code .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What does XmlWebApplicationContext do?

A

It loads context definition from an XML file contained within a web application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What is the typical Bean life cycle in Spring Bean Factory Container ?

A

Bean life cycle in Spring Bean Factory Container is as follows:
● The spring container finds the bean’s definition from the XML file and instantiates the bean.
● Using the dependency injection, spring populates all of the properties as specified in the bean definition
● If the bean implements the BeanNameAware interface, the factory calls setBeanName() passing the bean’s ID.
● If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of itself.
● If there are any BeanPostProcessors associated with the bean, their post- ProcessBeforeInitialization() methods will be called.
● If an init-method is specified for the bean, it will be called.
● Finally, if there are any BeanPostProcessors associated with the bean, their postProcessAfterInitialization() methods will be called.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What do you mean by bean wiring?

A

The act of creating associations between application components (beans) within the Spring container is referred to as Bean wiring.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What do you mean by autowiring?

A
The Spring container is able to autowire relationships between collaborating beans. This means that it is possible to automatically let Spring resolve collaborators (other beans) for your bean by inspecting the contents of the BeanFactory. The autowiring functionality has four modes. 
● byName 
● byType 
● constructor 
● autodetect
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

What is autowiring byName?

A

Spring, “Autowiring by Name” means, if the name of a bean is same as the name of other bean property, auto wire it. For example, if a “customer” bean exposes an “address” property, Spring will find the “address” bean in current container and wire it automatically. And if no matching found, just do nothing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

What is autowiring byType?

A

In Spring, “Autowiring by Type” means, if data type of a bean is compatible with the data type of other bean property, auto wire it. For example, a “person” bean exposes a property with data type of “ability” class, Spring will find the bean with same data type of class “ability” and wire it automatically. And if no matching found, just do nothing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

What is autowiring constructor?

A

In Spring, “Autowiring by Constructor” is actually autowiring by Type in constructor argument. It means, if data type of a bean is same as the data type of other bean constructor argument, auto wire it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

What is autowiring by autodetect?

A

In Spring, “Autowiring by AutoDetect“, means chooses “autowire by constructor” if default constructor (argument with any data type), otherwise uses “autowire by type“.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

Name the design pattern used in the Spring MVC architecture and the control element?

A

The design pattern followed by all MVC frameworks including Struts, JSF, and Spring is the Front Controller pattern. The central control element in Spring MVC is the Dispatcher Servlet.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

What does DefaultAnnotationHandlerMapping do in Spring MVC?

A

This is one of five handler mapping classes available in Spring. It is used by DispatcherServlet to map requests to specific controllers and controller methods annotated with @RequestMapping.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

What does the ViewResolver do in Spring MVC?

A

The last task to be performed in HTTP request handling is rendering output to the user. The ViewResolver exchanges a logical view name supplied by the controller for a an actual view (JSP) that renders the result. There are 12 ViewResolver classes to choose from depending on the desired rendering technology.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

How do you turn ON annotation support in Spring MVC?

A

Use tag mvc:annotation-driven in mvc-dispatcher-servlet.xml to switch ON annotation support, form validation, message conversion, and field formatting.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

List the annotations used to configure a basic controller class in Spring MVC.

A

The annotations required to configure a basic spring controller class are:
@Controller
@RequestMapping

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

What is the @Controller in Spring MVC?

A

This registers the class as a controller and must be used in conjunction with context: component-scan tag in the XML to automatically discover and register the controllers as Spring beans.

The class defines a Spring MVC controller.

46
Q

What is @RequestMapping in Spring MVC?

A

This identifies the method as a request handler type for a given path.

47
Q

How do you turn ON annotation-based autowiring in Spring?

A

To turn ON autowiring use the context:annotation-config tag in the spring xml. This will enable
@Autowired,
@Inject
@Resource

48
Q

How does the @Autowired annotation work?

A

It is used to automatically wire values into properties, methods, and constructors. It works similar to xml-based autowiring but can be selectively used. Bean properties can be annotated directly allowing removal of the setters in the class and the property tags in the spring xml. If no bean is found to wire to the annotated property a NoSuchBeanDefinitionException is thrown by default.

49
Q

What annotations are used to register a class as a spring bean?

A
By default, context:component-scan tag in the spring.xml tells the container to look for classes that are annotated with one of the following: 
@Component 
@Controller  
@Repository 
@Service
50
Q

How do you integrate Struts with Spring?

A

Using ContextLoaderPlugIn:
● Install the ContextLoaderPlugin in struts-config.xml
● In the “type” attribute of the action tag use: org.springframework.web.struts.DelegatingActionProxy.
● In action-servlet.xml map the HTML action to the action class and reference the injected bean.
● In appContext.xml map the injected bean to a bean class. ● In the action class install a setter for the injected bean.

51
Q

What ORMs does Spring support?

A
Spring supports the following ORMs : ● Hibernate 
● iBatis 
● JPA (Java Persistence API) 
● TopLink 
● JDO (Java Data Objects) 
● OJB
52
Q

What are the ways to access Hibernate using Spring?

A

There are several ways to achieve this; however, the two popular approaches to Spring’s Hibernate integration are:
● Hibernate Contextual Sessions (newer)
● HibernateTemplate (older)

53
Q

How do you integrate Spring and Hibernate using Contextual Sessions?

A

There are two popular approaches to this declarative, POJO-based integration:

  1. XML approach:
  2. Annotation approach:
54
Q

What is the XML approach when you integrate Spring and Hibernate using Contextual Sessions?

A

1) XML approach:
● Create the DaoImpl class with a setter for the Session Factory.
● Wire up the following beans: DataSource, SessionFactory, HibernateTransactionManager, and DaoImpl class.
● Bind each CRUD method to a transaction in the appContext.xml. Define the AOP configuration using the aop:config tags and the transaction advice using the tx:advice tags and the transaction properties (propagation, isolation, and rollback) for each method with the tx:method tags.

55
Q

What is the Annotation approach when you integrate Spring and Hibernate using Contextual Sessions?

A

2) Annotation approach:
● Create the annotated (@Repository) DaoImpl class with an annotated (@Inject) sessionFactory.
● Wire up the following beans: DataSource, SessionFactory, and HibernateTransactionManager in the appContext.xml
● Use context:component-scan tag to find the annotated classes.
● Include a PersistenceExceptionTranslationPostProcessor bean definition to convert platform specific exceptions to a richer set of Spring runtime data access exceptions.
● Bind and annotate (@Transactional) each CRUD method to a transaction in the DaoImpl class and use the tx:annotation-driven tag in appContext.xml.

56
Q

Define HibernateTemplate.

A

org.springframework.orm.hibernate.HibernateTemplate is a helper class which provides different methods for querying/retrieving data from the database. It also converts checked HibernateExceptions into unchecked DataAccessExceptions.

57
Q

What benefits does the HibernateTemplate provide?

A
The benefits of the Hibernate Template are: 
● HibernateTemplate, a Spring Template class simplifies interactions with Hibernate Session. 
● Common functions are simplified to single method calls. 
● Sessions are automatically closed. 
● Exceptions are automatically caught and converted to runtime exceptions.
58
Q

How did you integrate Spring and Hibernate using Template Injection?

A
Follow this three-step process: 
● Wire up the following beans in the spring.xml: DataSource, SessionFactory, HibernateTransactionManager, and DaoImpl class. 
● Place a setter for the HibernateTemplate in the DaoImpl class and 
● Create an anonymous inner class to implement the doInHibernate method of the Callback interface and place the desired Template CRUD method there. Pass the inner class object to the Template execute method to invoke the desired CRUD operation.
59
Q

What are Bean scopes in Spring Framework ?

A

The Spring Framework supports exactly five scopes (of which three are available only if you are using a web-aware ApplicationContext). The scopes supported are listed below:

  1. Singleton
  2. Prototype
  3. Request
  4. Session
  5. Global Session
60
Q

What is the Singleton Bean scope?

A

Scopes a single bean definition to a single object instance per Spring IoC container.

61
Q

What is the Prototype Bean scope?

A

Scopes a single bean definition to any number of object instances.

62
Q

What is the Request Bean scope?

A

Scopes a single bean definition to the lifecycle of a single HTTP request; that is each and every HTTP request will have its own instance of a bean created off the back of a single bean definition. Only valid in the context of a web-aware Spring ApplicationContext.

63
Q

What is the Session Bean scope?

A

Scopes a single bean definition to the lifecycle of a HTTP Session. Only valid in the context of a web-aware Spring ApplicationContext.

64
Q

What is the Global Session scope?

A

Scopes a single bean definition to the lifecycle of a global HTTP Session. Typically only valid when used in a portlet context. Only valid in the context of a web-aware Spring ApplicationContext.

65
Q

What is AOP?

A

Aspect-oriented programming, or AOP, is a programming technique that allows programmers to modularize crosscutting concerns, or behavior that cuts across the typical divisions of responsibility, such as logging, security, exception handling and transaction management. The core construct of AOP is the aspect, which encapsulates behaviors affecting multiple classes into reusable modules.

66
Q

How is AOP used in Spring?

A

AOP is used in the Spring Framework to provide declarative enterprise services, especially as a replacement for EJB declarative services. The most important such service is declarative transaction management, which builds on the Spring Framework’s transaction abstraction.To allow users to implement custom aspects, complementing their use of OOP with AOP.

67
Q

What do you mean by Aspect?

A

A modularization of a concern that cuts across multiple objects. Transaction management is a good example of a crosscutting concern in J2EE applications. In Spring AOP, aspects are implemented using regular classes (the schema-based approach) or regular classes annotated with the @Aspect annotation (@AspectJ style).

68
Q

What do you mean by join point?

A

A point during the execution of a program, such as the execution of a method or the handling of an exception. In Spring AOP, a join point always represents a method execution.

69
Q

What do you mean by Advice?

A

Action taken by an aspect at a particular join point. Different types of advice include “around,” “before” and “after” advice. Many AOP frameworks, including Spring, model an advice as an interceptor, maintaining a chain of interceptors “around” the join point.

70
Q

What are the types of Advice?

A

Types of Advice:

  1. Introduction
  2. Before Advice
  3. After returning Advice
  4. After throwing Advice
  5. After (finally) Advice
  6. Around Advice
71
Q

What is the Introduction Advice?

A

● Introduction : Introduction advice cannot be used with any pointcut, as it applies only at class, rather than method, level. You can only use introduction advice with the IntroductionAdvisor.

72
Q

What is the Before Advice?

A

● Before advice: Advice that executes before a join point, but which does not have the ability to prevent execution flow proceeding to the join point (unless it throws an exception).

73
Q

What is the After returning Advice?

A

● After returning advice: Advice to be executed after a join point completes normally: for example, if a method returns without throwing an exception.

74
Q

What is the After throwing Advice?

A

● After throwing advice: Advice to be executed if a method exits by throwing an exception.

75
Q

What is the After (finally) Advice?

A

● After (finally) advice: Advice to be executed regardless of the means by which a join point exits (normal or exceptional return).

76
Q

What is the Around Advice?

A

● Around advice: Advice that surrounds a join point such as a method invocation. This is the most powerful kind of advice. Around advice can perform custom behavior before and after the method invocation. It is also responsible for choosing whether to proceed to the join point or to shortcut the advised method execution by returning its own return value or throwing an exception

77
Q

What are the types of the transaction management Spring supports?

A

Spring Framework supports:
● Programmatic transaction management.
● Declarative transaction management.

78
Q

What is Spring Framework Programmatic transaction management?

A

This means that you have manage the transaction with the help of programming. That gives you extreme flexibility, but it is difficult to maintain. Programmatic transaction management is usually a good idea only if you have a small number of transactional operations.

79
Q

What is Spring Framework Programmatic Declarative transaction management.

A

Declarative transaction management approach allows you to manage the transaction with the help of configuration instead of hard coding in your source code. This means that you can separate transaction management from the business code. You only use annotations or XML based configuration to manage the transactions. The bean configuration will specify the methods to be transactional.

80
Q

What are the benefits of the Spring Framework transaction management?

A

The Spring Framework provides a consistent abstraction for transaction management that delivers the following benefits:
● Provides a consistent programming model across different transaction APIs such as JTA, JDBC, Hibernate, JPA, and JDO.
● Supports declarative transaction management.
● Provides a simpler API for programmatic transaction management than a number of complex transaction APIs such as JTA.
● Integrates very well with Spring’s various data access abstractions.

81
Q

When to use programmatic and declarative transaction management ?

A

Programmatic transaction management is usually a good idea only if you have a small number of transactional operations. On the other hand, if your application has numerous transactional operations, declarative transaction management is usually worthwhile. It keeps transaction management out of business logic, and is not difficult to configure.

82
Q

What is Spring’s jdbc template?

A

Spring’s JdbcTemplate is central class to interact with a database through JDBC. JdbcTemplate provides many convenience methods for doing things such as converting database data into primitives or objects, executing prepared and callable statements, and providing custom database error handling.

83
Q

How do you create a JdbcTemplate?

A

JdbcTemplate template = new JdbcTemplate(myDataSource);

84
Q

How do you create an Application Context for Class Path XML?

A

ApplicationContext context = new ClassPathXmlApplicationContext(“bean.xml”);

85
Q

How do you create an Application Context for Annotation?

A

ApplicationContext context = new AnnotationConfigApplicationContext(AnnotationConfig.class)

86
Q

How do you create an Application Context for File System XML?

A

ApplicationContext context = new FileSystemXmlApplicationContext(“bean.xml”);

87
Q

How do you register a method as a Bean in Spring?

A

To declare a bean, simply annotate a method with the @Bean annotation. When JavaConfig encounters such a method, it will execute that method and register the return value as a bean within a BeanFactory. By default, the bean name will be the same as the method name.

88
Q

What is the @Configuration annotation in Spring?

A

Indicates that a class declares one or more @Bean methods and may be processed by the Spring container to generate bean definitions and service requests for those beans at runtime.

89
Q

What is the @Repository annotation in Spring?

A

The class defines a data repository such as a DAO implementation class.

Indicates that an annotated class is a “Repository” as “a mechanism for encapsulating storage, retrieval, and search behavior which emulates a collection of objects”.

90
Q

What is the @Controller annotation in Spring?

A

Base Controller interface, representing a component that receives HttpServletRequest and HttpServletResponse instances just like a HttpServlet but is able to participate in an MVC workflow. Controllers are comparable to the notion of a Struts Action.

Any implementation of the Controller interface should be a reusable, thread-safe class, capable of handling multiple HTTP requests throughout the lifecycle of an application. To be able to configure a Controller easily, Controller implementations are encouraged to be (and usually are) JavaBeans.

91
Q

What is the @Service annotation in Spring?

A

The class defines a service.

Indicates that an annotated class is a "Service", originally defined by Domain-Driven Design "an operation offered as an interface that stands alone in the model, with no encapsulated state."
May also indicate that a class is a "Business Service Facade" (in the Core J2EE patterns sense), or something similar. This annotation is a general-purpose stereotype and individual teams may narrow their semantics and use as appropriate.

This annotation serves as a specialization of @Component, allowing for implementation classes to be autodetected through classpath scanning.

92
Q

What is the @Component annotation in Spring?

A

Indicates that an annotated class is a “component”. Such classes are considered as candidates for auto-detection when using annotation-based configuration and classpath scanning.

The class defines a Spring component.

93
Q

What is Spring View Resolver?

A

Tells the dispatcher servlet where to go next by looking at a string called “view”.

94
Q

What is ResponseEntity?

A
A builder for ResponseEntity objects. Enforces common HTTP response practices through a fluent API.
This class is typically used in @Controller methods through a static import.
95
Q

What is HandlerMapping?

A

HandlerMapping is an interface that is implemented by all Objects that map the request to the corresponding Handler Object. A HandlerExecutionChain always wraps the Handler and may also contain one or more HandlerInterceptors. The default Implementations used by the DispatcherServlet are BeanNameUrlHandlerMapping and DefaultAnnotationHandlerMapping

96
Q

What is Spring DispatcherServlet?

A

The job of the DispatcherServlet is to take an incoming URI and find the right combination of handlers (generally methods on Controller classes) and views (generally JSPs) that combine to form the page or resource that’s supposed to be found at that location.

97
Q

What is the @RequestBody annotation in Spring?

A

Annotation indicating a method parameter should be bound to the body of the web request. The body of the request is passed through an HttpMessageConverter to resolve the method argument depending on the content type of the request. Optionally, automatic validation can be applied by annotating the argument with @Valid

98
Q

What is the @RequestMapping annotation in Spring?

A

Annotation for mapping web requests onto specific handler classes and/or handler methods. Provides a consistent style between Servlet and Portlet environments, with the semantics adapting to the concrete environment.

99
Q

What is the @ResponseBody annotation in Spring?

A

Annotation that indicates a method return value should be bound to the web response body. Supported for annotated handler methods in Servlet environments.
As of version 4.0 this annotation can also be added on the type level in which case it is inherited and does not need to be added on the method level.

100
Q

How do you annotate Beans with constraints?

A

There are pros and cons for considering validation as business logic, and Spring offers a design for validation (and data binding) that does not exclude either one of them. Specifically validation should not be tied to the web tier, should be easy to localize and it should be possible to plug in any validator available. Considering the above, Spring has come up with a Validator interface that is both basic and eminently usable in every layer of an application.

101
Q

Spring Path Parameter

A

Path parameter is the string that is passed over in the hyperlink

Path Parameter
http://localhost:9999/mvc/vehicle/find/34G3HG989CN1BK

@RequestMapping(value="find/{vin}",
method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE
@ResponseBody
public ResponseEntity findByVin(@PathVariable String vin) {
      for (Vehicle v: vehicles) {
               return new ResponseEntity(v, HttpStatus.OK);
       }
          return new ResponseEntity<>(HttpStatus.NOT_FOUN)
}
102
Q

Spring Query Parameter

A

Query parameter is the string that is passed over in the hyperlink

Query Parameter
http://localhost:9999/mvc/vehicle/find/

@ResponseBody
@RequestMapping(value=”find”, method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity> findByMake(
@RequestParam(value=”make”, required=true) String make) {
List results = new ArrayList<>();

     for (Vehicle v: vehicles) {
          if (v.getMake().equals(make))
               resukts.add(v);
      }
      return new ResponseEntity(results, HttpStatus.OK);
}
103
Q

What is AOP security aspect?

A

A lot of modules needs security. It cuts across all our modules.

104
Q

What is AOP Cross Cutting concerns?

A

A Concern is a term that refers to a part of the system divided on the basis of the functionality.

Concerns are two types:

The concerns representing single and specific functionality for primary requirements are known as core concerns.
OR
Primary functionality of the system is known as core concerns.
For example: Business logic
The concerns representing functionalities for secondary requirements are referred to as crosscutting concerns or system-wide concerns.
OR
The crosscutting concern is a concern which is applicable throughout the application and it affects the entire application.
For example: logging, security and data transfer are the concerns which are needed in almost every module of an application, hence they are cross-cutting concerns.

105
Q

What is AOP JoinPoint

A

The joinpoint is any potential point any aspect can jump in and do its job. Can potentially happen.

106
Q

What is AOP PointCut

A

The point in which an aspect intercepts and does it works. Can actually happen.

@Pointcut(“execution(public void somemethod())”)

107
Q

What is AspectJ

A

Better than Spring when it comes to AOP. it has all kinds of interception and join points.

108
Q

What is AOP Advice

A

Combination of what and when to work for aspects. We can tell the aspect to do its job before or after a method, after it returns a value, throws an exception.

109
Q

AOP Contextual Session

A

A given session is in effect throughout the scope of a given context.

110
Q

What is Business Logic?

A

In computer software, business logic or domain logic is the part of the program that encodes the real-world business rules that determine how data can be created, stored, and changed. It is contrasted with the remainder of the software that might be concerned with lower-level details of managing a database or displaying the user interface, system infrastructure, or generally connecting various parts of the program.

111
Q

What is IoC Container?

A

IoC is also known as dependency injection (DI). It is a process whereby objects define their dependencies, that is, the other objects they work with, only through constructor arguments, arguments to a factory method, or properties that are set on the object instance after it is constructed or returned from a factory method. The container then injects those dependencies when it creates the bean. This process is fundamentally the inverse, hence the name Inversion of Control (IoC), of the bean itself controlling the instantiation or location of its dependencies by using direct construction of classes, or a mechanism such as the Service Locator pattern.

https://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html