Spring Interview Questions
Explain the Weaving process in Spring framework?
Weaving is the process of applying aspects to a to a target object to create a new proxied object. The aspects are woven into the target object at the specified joinpoints. The weaving can take place at several points in the target class’s lifetime:
* Compile time : Aspects are woven in when the target class is compiled. This requires a special compiler.
* Classload time : Aspects are woven at the time of loading of the target class into the JVM. It is done by ClassLoader that enhances that target class’s bytecode before the class is introduced into the application.
* Runtime : Sometimes aspects are woven in during the execution of the applicaion.
Define the AOP terminology?
Many terms used to define the AOP (Aspect Oriented Programming) features and they are part of the AOP language. These terms must be known to understand the AOP:
* Aspect : An aspect is the cross-cutting functionality you are implementing. It is the aspect, or area of your application you are modularizing. The most common example of aspect is logging. Logging is something that is required throughout an application.
* Joinpoint : A joinpoint is a point in the execution of the application where an aspect can be plugged in.
* Advice : Advice is the actual implementation of our aspect. It is advising your application of new behaviour.
* Pointcut : A pointcut defines at what joinpoints advice should be applied.
* Introduction : An introduction allows you to add new methods or attributes to existing classes.
* Target : A target is the class that is being advised.
* Proxy : A proxy is the object created after applying advice to the target object.
* Weawing : Weawing is the process of applying aspects to a target object to create a new proxied object.
What is an Advisor API in Spring ?
Advisor is an aspect that contains just a single advice object associated with a pointcut expression. A pointcut is something that defines at what joinpoints an advice should be applied. Advices can be applied at any joinpoint that is supported by the AOP framework. These Pointcuts allow you to specify where the advice can be applied.
Any advisor can be used with any advice. The org.springframework.aop.support.DefaultPointcutAdvisor is the most commonly used advisor class. For example, it can be used with a MethodInterceptor, BeforeAdvice or ThrowsAdvice.
What is an Advice in Spring framework?
An Advice is a Spring bean. Advice is the implementation of an aspect. It is something like telling your application of a new behavior. Generally, and advice is inserted into an application at joinpoints. An advice instance can be shared across all advised objects, or unique to each advised object. This corresponds to per-class or per-instance advice.
Advice types in Spring:
* Interception around advice
* Before advice
* Throws advice
* After Returning advice
* Introduction advice
What are the various custom editors provided by the Spring Framework?
The various custom editors provided by the Spring Framework are:
Is there a way where you can wire a non-string to string in Spring ?How will you wire a string value to a property whose type is a non-string?
Yes. You can wire a string value to a property whose type is a non-string. The java.beans.PropertyEditor interface provides a means to customize how String values are mapped to non-String types. This interface is implemented by java.beans.PropertyEditorSupport that has two methods:
* getAsText() : returns the String representation of a property’s value.
* setAsText(String value) : sets a bean property value from the String value passed in.
If you want to map the non-string property to a String value, the setAsText() method is called to perform the conversion.
How will you handle the ambiguities of autowiring in Spring?
When sutowiring using byType or constructor, it’s possible that the container may find two or more beans whose type matches the property’s type or the types of the constructor arguments. What will happen if there are ambiguous beans suitable for autowiring?
Spring can’t sort out ambiguities and chooses to throw an exception raher than guess which bean you meant to wire in. If you encounter such ambiguities when autowiring, the best solution is not to autowire the bean.
- Struts to Spring
- Spring IDE
- Spring Interview Questions
- Spring Dependency Injection and Inversion of Control
- Spring Dependency Injection using the setter method
- Spring Framework
- Spring MVC Framework
- Spring Annotations
- Spring Tiles Integration
- Spring JDBC
- Spring Exception Handling
- Spring AOP
- Spring Core