Spring Framework Interview Questions

  • 1
    List out the major features in the versions of spring framework.

    The three (3) major features are as follows:

    • Spring 2.5
    • Spring 3.0
    • Spring 4.0
  • 2
    What is the purpose of Bean Factory Post Processor?

    creating BeanFactory and before using the bean if we need to change in the bean or if we need to add into the metadata then we will use BeanFactoryPostProcessors and we will add the data to metadata.

  • 3
    What are all the AOP advice used in Spring Transaction internally?

     In Spring transaction internally two Advices they used. Before starting the operation it will start the transaction and if operation is successful it will call commit operation . Here Spring transaction used “Around Advice” and When Saving the Data Error came at that time it will call rollback operation here they used “throws Advice”

  • 4
    One-to-many relationship: how we will map objects in Spring JDBC?

     In One-to-Many relational objects we need to implement “ResultSetExtractor” In Spring JDBC. It will get Result Set.inside that one we need to write our own logic to populate the data into objects and we need to give this ResultSetExtractor implemented class to JDBCTemplate class uery method.

  • 5
    What are all the annotations used inside of @SpringBootApplication annotation?

    The @SpringBootApplication annotation is using internally 2 annotations are major.

    Those are:

    • @EnableAutoConfiguration
    • @ComponentScan
  • 6
    Why does spring provide Starter Dependencies?

     For the easy of Developers Spring provided Starter dependencies. Normally Programmers are more concentrating on Configuration rather than business logic. For decreasing time to programmers on configuration dependency jars they provided starter dependencies. Internally they configured all dependencies.

  • 7
    Limitations of Dependency Injection

    • If we are using dependency injection it is good about managing the dependency between those components which are having the static references with each other.
    • If we have some dynamic dependency to be managed means the class whom I talk to will be decided by runtime instead of development time. Then dependency injection will not work.
    • We cannot use prototype scope beans into singleton scope, because that prototype class behaves like singleton only.
  • 8
    Spring Internationalization

    Spring has provided better support for internationalization when compared with JEE internationalization. It has provided multiple classes “ReloadableResourceBundleMessagesource” to support Internationalization.

  • 9
    How many times the static pointcut matches method will be called?

    Depends on the number of methods present in the target class to create the proxy. Once the proxy has created only the number of methods applied, that method has been called and also 2 times extra for equals and hashcode.

  • 10
    What is the reason to create two injections with each other?

    First of all spring is the non programmer to create two IOC dispatcher-servlet.xml one for spring specific applicationContext.xml one is for Business layer component means in future if we don’t want to use spring mvc then we can get read out from spring mvc easily without disturbing the existing business tire logic and we can replace any web component easily.

  • 11

    When should we go for Abstract Wizard Controller?

    It is the controller which helps the developer to gather the data using multiple wizards. We cannot gather 100% of records or columns of data using jsp pages .It may load bad user experience to make good and to gather the data mostly developers follow Wizard conversion and flow driven approach.

  • 12
    @Bean Annotation in which scenario we will use.

    This annotation also we will use for creating the bean but we have another Stereotype annotations for creating bean. By using those annotation we will create a bean if we write the Source code.But some classes we will get from jars .class files. creating beans for .class files we will use @Bean annotation under JavaConfiguration class.

  • 13
    What is the difference between Spring non Annotation and Spring Annotation MVC.

    Spring non annotation MVC flow programmer must and Should extends from Any implementation of the controller of he need to implement the controller interface and Must and Should return value could be “ModelandView ”. But Annotation flow programmers don’t need to implement any class. And we can return any value.

  • 14
     Spring ORM based on which design pattern it implemented?

    Spring ORM implemented Based on Template Design Pattern they implemented. This Template will support for All ORM frameworks like Spring JDBC , Hibernate , Ibattis in this way for every framework they implement Template for every ORM implementation.

  • 15
    What is Named ParameterJDBCTemplate?

    Normally writing Prepared statement programmers will confuse which value we need to pass in which Positional parameter(?. in which place exactly programmers need to remember. But in NamedParameterJDBCTemplate we will not give Positional parameters like(?. , we will give a proper name for that positional parameter(:name. like a programmer will not confuse and the ease of programmer implements NamedParameterJDBCTemplate.

  • 16
    How many ways can we break the singleton?

    We can Break the Singleton in many ways those are:

    • MultiThreading
    • Serialization
    • clone
    • Reflection etc.

    If we restrict all these things then only we will get Complete Singleton class.

  • 17
    Write some points in spring AOP and aspect AOP?

    SpringAOP:

    • Only supported joinpoint is method Execution.
    • Spring supports Runtime Viewing; this means the proxy object will be built on the fly at runtime in the memory.
    • Spring supports Static and Dynamic pointcuts.

    AspectJAOP:

    • It supports various types of join points like constructor Execution, method execution , field set or field get etc.
    • AspectJ uses compile-time Weaving;this indicates your proxy classes will be available whenever you compile your code.
    • AspectJ supports only static pointcut.
  • 18
    What is the Spring Security internal Architecture flow?

    First DelegatingFilterProxy will get the request and it will pass that request to Authentication manager to ask that URL is restricted or not if that is not restricted url that request will come back to DelegatingFilterProxy and it will forward to DispatcherServlet. Authentication Manager will search in the AuthenticationCOnfiguration file whether the URL is restricted or not. If the URL is Restricted That will ask the details to AuthenticationProvider to get the details of the user and it will do the Authentication. If the User is Authorised User it will forward the URL to DispatcherServlet.

  • 19
    What is the Use of @PostConstruct and @PreDestroy annotations?

    • @PostConstruct: This annotation we will use in SpringBean Lifecycle in annotation approach. This will execute that particular method after executing the constructor.
    • @PreDestroy: This Annotation will execute the method before executing finalize method or before exiting control from the program it will execute for pre destroy or complete activities.
  • 20
    What is Dependency Check in Spring?

    In Spring Dependency Injection we will inject the Objects in two ways

    • ConstructorInjection
    • SetterInjection

    if we use Constructor injection those dependencies are mandatory. But if we use Constructor Injection there is a chance of CyclicDependencyInjection. That time we need to go to Mandatory SetterInjection only. If the Setter injection those are optional. With the SetterInjection we need to make those are mandatory we need to enable “DependencyCheck=true''.

  • 21
    What is Bean Alias in Spring?

    For Spring Bean id if we need to give multiple names at that time we will use BeanAlias in Spring.

    Example

    <bean id=”mobile” class=”Nokia”>
    <alias name=”pone” alias=”mobile”>
    
  • 22
    What is the use of @Configuration and when will we use?

     This annotation we will use if we used Pure Annotation based Approach at that time we will write one class For Configuration class instead of SpringBean Configuration class. For Telling that class in Configuration class we will write this @Configuration annotation on top of that class.

  • 23
    How do we implement DI in Spring Framework?

    We can use Spring XML based as well as Annotation-based configuration to implement DI in spring applications. For better understanding, please read the Spring Dependency Injection example where you can learn both the ways with JUnit test cases. The post also contains a sample project zip file, that you can down

  • 24
     How to make scope prototype?

    By using the attribute scope=”prototype” in xml.

  • 25
    What are the attributes which helps to solve ambiguity problem in constructor dependency Injection?

    By using type and index attributes in xml.

  • 26
    What are mutual dependencies?

    When both the objects depending on each other we can call mutual dependencies

    example: A Object depends on B and B also depends on A.

  • 27
    What are types of Advisors?

    • Default pointcut Advisor
    • Regex method pointcut Advisor
  • 28
     What Are Devtools In Spring Boot?

    Spring boot comes with DevTools which is introduced to increase the productivity of developers.

  • 29
    What is Session scope?

    Session: It returns a single bean instance per HTTP session (User level session.

  • 30
    What are the Spring scopes?

    Singleton, prototype, request, session, global session.

  • 31
    What is the difference between the application context and Bean factor?

    Application context creates the object at time of loading but Bean factor creates the object at first request.

  • 32
    What is a Spring Bean?

    • Any normal java class that is initialized by Spring IoC container is called Spring Bean. We use Spring ApplicationContext to get the Spring Bean instance.
    • Spring IoC container manages the life cycle of Spring Bean, bean scopes and injecting any required dependencies in the bean.
  • 33
    What is the use of Actuator in Spring Boot?

    It is tool which is used for monitoring and managing the application

  • 34
    What is CrudRepository?

    It is a spring given interface used for crud operations on repositories.

  • 35
    one of the ways for creating spring boot applications?

    By using Spring Initializr.

  • 36
    How to use CrudRepository?

     We need to create our interface and extend crudrepository.

  • 37
    What is the use of application.properties in spring boot?

     It configuration file in spring boot used to override all the default setups

  • 38
    What is the default scope?

    Singleton.

  • 39
    How to inject arraylist into a class through xml?

     By using <list> tag

  • 40
    Types of stereotype annotation?

    • @controller,
    • @component,
    • @Repository,
    • @service
  • 41
    What are different types of Autowire?

    There are four different types of Auto wire:

    • byName
    • byType
    • constructor
    • autodetect
  • 42
    What are types of pointcuts?

    • Static Method Matcher point cut
    • Name Method Matcher point cut
  • 43
    What is the use of spring-boot-devtools?

    It is used for auto reload of an application.

  • 44
    What is spring-boot-starter-parent?

    It is used to set-up spring boot applications with maven.

  • 45
    What are @PostConstruct and @PreDestroy annotations?

    They are used at method and methods act like init and destroy

  • 46
    When to use Bean Name Url Handler Mapping?

    When we need matching to be done using name of the controller or by pattern.

  • 47
    What is the default handler mapping?

    BeanNameUrlHandlerMapping

  • 48
    What is Autowired Annotation Bean Post Processor?

    It is also the class

  • 49
    What is the use of <context:annotation-config />?

    It is used to enable @Autowired annotation

  • 50
    Which method is used to set the data source in the jdbc template?

    setDataSource()