{"iq":[{"id":"1",
"q":"What is a Spring Framework?",
"answer":"Spring is a powerful open source, application framework created to reduce the complexity of enterprise application development. It is light-weighted and loosely coupled.It has layered architecture, which allows you to select the components to use, while also providing a cohesive framework for J2EE application development.Spring framework is also called framework of frameworks as it provides support to various other frameworks such as Struts, Hibernate, Tapestry, EJB, JSF etc. "
},
{"id":"2",
"q":"List the advantages of Spring Framework. ",
"answer":"Because of Spring Frameworks layered architecture, you can use what you need and leave which you don’t.\nSpring Framework enables POJO (Plain Old Java Object) Programming which in turn enables continuous integration and testability.\nJDBC is simplified due to Dependency Injection and Inversion of Control.\nIt is open-source and has no vendor lock-in."
},
{"id":"3",
"q":"What are the different features of Spring Framework?",
"answer":"Lightweight\nInversion of control (IOC)\nAspect oriented Programming (AOP)\nContainer\nMVC Framework\nTransaction Management\nJDBC Exception Handling"
},
{"id":"4",
"q":"What is a Spring configuration file?",
"answer":"A Spring configuration file is an XML file.\nThis file mainly contains the classes information.\nIt describes how those classes are configured as well as introduced to each other.\nThe XML configuration files, however, are verbose and more clean.\nIf it’s not planned and written correctly, it becomes very difficult to manage in big projects. "
},
{"id":"5",
"q":"Which are the Spring framework modules?",
"answer":"The basic modules of the Spring framework are :\n\nCore module\nBean module\nContext module\nExpression Language module\nJDBC module\nORM module\nOXM module\nJava Messaging Service(JMS) module\nTransaction module\nWeb module\nWeb-Servlet module\nWeb-Struts module\nWeb-Portlet module"
},
{"id":"6",
"q":"Explain the Core Container (Application context) module",
"answer":"This is the basic Spring module, which provides the fundamental functionality of the Spring framework.\nBeanFactory is the heart of any spring-based application.\nSpring framework was built on the top of this module, which makes the Spring container. "
},
{"id":"7",
"q":"BeanFactory – BeanFactory implementation example",
"answer":"A BeanFactory is an implementation of the factory pattern that applies Inversion of Control to separate the application’s configuration and dependencies from the actual application code.\nThe most commonly used BeanFactory implementation is the XmlBeanFactory class. "
},
{"id":"8",
"q":"Explain the AOP module",
"answer":"The AOP module is used for developing aspects for our Spring-enabled application.\nMuch of the support has been provided by the AOP Alliance in order to ensure the interoperability between\nSpring and other AOP frameworks. This module also introduces metadata programming to Spring."
},
{"id":"9",
"q":"What are the various ways of using Spring Framework? ",
"answer":"Spring Framework can be used in various ways. They are listed as follows:\nAs a Full-fledged Spring web application.\nAs a third-party web framework, using Spring Frameworks middle-tier.\n\nFor remote usage.\nAs Enterprise Java Bean which can wrap existing POJOs (Plain Old Java Objects)."
},
{"id":"10",
"q":"What do you mean by Dependency Injection? ",
"answer":"In Dependency Injection, you do not have to create your objects but have to describe how they should be created.\nYou don’t connect your components and services together in the code directly, but describe which services are needed by which components in the configuration file.The IoC container will wire them up together."
},
{"id":"11",
"q":"In how many ways can Dependency Injection be done?",
"answer":"In general, dependency injection can be done in three ways, namely :\n\nConstructor Injection\nSetter Injection\nInterface Injection\nIn Spring Framework, only constructor and setter injections are used."
},
{"id":"12",
"q":"How many types of IOC containers are there in spring?",
"answer":"BeanFactory: BeanFactory is like a factory class that contains a collection of beans. It instantiates the bean whenever asked for by clients.\n\nApplicationContext: The ApplicationContext interface is built on top of the BeanFactory interface. It provides some extra functionality on top BeanFactory."
},
{"id":"13",
"q":"Explain Spring Beans?",
"answer":"They are the objects that form the backbone of the user’s application.\nBeans are managed by the Spring IoC container.\nThey are instantiated, configured, wired and managed by a Spring IoC container\nBeans are created with the configuration metadata that the users supply to the container."
},
{"id":"14",
"q":"How many bean scopes are supported by Spring?",
"answer":"The Spring Framework supports five scopes. They are:\n\nSingleton: This provides scope for the bean definition to single instance per Spring IoC container.\nPrototype: This provides scope for a single bean definition to have any number of object instances.\nRequest: This provides scope for a bean definition to an HTTP-request.\nSession: This provides scope for a bean definition to an HTTP-session.\nGlobal-session: This provides scope for a bean definition to an Global HTTP-session."
},
{"id":"15",
"q":"What is the Bean life cycle in Spring Bean Factory Container?",
"answer":"Bean life cycle in Spring Bean Factory Container is as follows:\n\nThe Spring container instantiates the bean from the bean’s definition in the XML file.\nSpring populates all of the properties using the dependency injection, as specified in the bean definition.\nThe factory calls setBeanName() by passing the bean’s ID, if the bean implements the BeanNameAware interface.\nThe factory calls setBeanFactory() by passing an instance of itself, if the bean implements the BeanFactoryAware interface.\npreProcessBeforeInitialization() methods are called if there are any BeanPostProcessors associated with the bean.\nIf an init-method is specified for the bean, then it will be called.\nFinally, postProcessAfterInitialization() methods will be called if there are any BeanPostProcessors associated with the bean. "
},
{"id":"16",
"q":"Define Bean Wiring. ",
"answer":"When beans are combined together within the Spring container, it’s called wiring or bean wiring. The Spring container needs to know what beans are needed and how the container should use dependency injection to tie the beans together, while wiring beans."
},
{"id":"17",
"q":"What do you understand by auto wiring and name the different modes of it?",
"answer":"The Spring container is able to autowire relationships between the collaborating beans. That is, it is possible to let Spring resolve collaborators for your bean automatically by inspecting the contents of the BeanFactory.\n\nDifferent modes of bean auto-wiring are:\n\nno: This is default setting which means no autowiring. Explicit bean reference should be used for wiring.\nbyName: It injects the object dependency according to name of the bean. It matches and wires its properties with the beans defined by the same names in the XML file.\nbyType: It injects the object dependency according to type. It matches and wires a property if its type matches with exactly one of the beans name in XML file.\nconstructor: It injects the dependency by calling the constructor of the class. It has a large number of parameters.\nautodetect: First the container tries to wire using autowire by constructor, if it can’t then it tries to autowire by byType. "
},
{"id":"18",
"q":"What are the limitations with auto wiring? ",
"answer":"Overriding possibility: You can always specify dependencies using <constructor-arg> and <property> settings which will override autowiring.\nPrimitive data type: Simple properties such as primitives, Strings and Classes can’t be autowired.\nConfusing nature: Always prefer using explicit wiring because autowiring is less precise. "
},
{"id":"19",
"q":"What do you understand by @Required annotation? ",
"answer":"@Required is applied to bean property setter methods.\nThis annotation simply indicates that the affected bean property must be populated at the configuration time with the help of an explicit property value in a bean definition or with autowiring. If the affected bean property has not been populated, the container will throw BeanInitializationException. "
},
{"id":"20",
"q":"What do you understand by @Autowired annotation?",
"answer":"The @Autowired annotation provides more accurate control over where and how autowiring should be done.This annotation is used to autowire bean on the setter methods, constructor, a property or methods with arbitrary names or multiple arguments.\n\nBy default, it is a type driven injection.\n\nFor Example:\n\npublic class Employee\n{\nprivate String name;\n@Autowired\npublic void setName(String name)\n{this.name=name; }\npublic string getName()\n{ return name; }\n}"
},
{"id":"21",
"q":"What do you understand by @RequestMapping annotation?",
"answer":"@RequestMapping annotation is used for mapping a particular HTTP request method to a specific class/ method in controller that will be handling the respective request. This annotation can be applied at both levels:\n\nClass level : Maps the URL of the request\n\nMethod level: Maps the URL as well as HTTP request method "
},
{"id":"22",
"q":"Describe Spring DAO support? ",
"answer":"The Data Access Object (DAO) support in Spring makes it easy to work with data access technologies like JDBC, Hibernate or JDO in a consistent way. This allows one to switch between the persistence technologies easily. It also allows you to code without worrying about catching exceptions that are specific to each of these technology. "
},
{"id":"23",
"q":"Which classes are present in spring JDBC API?",
"answer":"Classes present in JDBC API are as follows:\n\nJdbcTemplate\nSimpleJdbcTemplate\n\nNamedParameterJdbcTemplate\nSimpleJdbcInsert\nSimpleJdbcCall"
},{"id":"24",
"q":"What are the ways by which Hibernate can be accessed using Spring? ",
"answer":"There are two ways by which we can access Hibernate using Spring:\n\nInversion of Control with a Hibernate Template and Callback\nExtending HibernateDAOSupport and Applying an AOP Interceptor node"
},{"id":"25",
"q":"Describe AOP. ",
"answer":"Aspect-oriented programming or AOP is a programming technique which allows programmers to modularize crosscutting concerns or behavior that cuts across the typical divisions of responsibility. Examples of cross-cutting concerns can be logging and transaction management. The core of AOP is an aspect. It encapsulates behaviors that can affect multiple classes into reusable modules."
},{"id":"26",
"q":"What do you mean by Aspect?",
"answer":"Aspect is a modularization of concern which cuts across multiple objects.\nTransaction management is a good example of a crosscutting concern in J2EE applications.\nAspects are implemented using regular classes or regular classes annotated with the @Aspect annotation in Spring Framework."
},{"id":"27",
"q":"Explain JoinPoint.",
"answer":"A point during the execution of a program is called JoinPoint,such as the execution of a method or the handling of an exception.\n\nIn Spring AOP, a joinpoint always represents a method execution."
},{"id":"28",
"q":"What is an Advice? ",
"answer":" An Action taken by an aspect at a particular joinpoint is known as an Advice.\n\nSpring AOP uses an advice as an interceptor, maintaining a chain of interceptors “around” the join point."
},{"id":"29",
"q":"What are the different types of Advices? ",
"answer":"\n\nBefore: These types of advices execute before the joinpoint methods and are configured using @Before annotation mark.\nAfter returning: These types of advices execute after the joinpoint methods completes executing normally and are configured using @AfterReturning annotation mark.\nAfter throwing: These types of advices execute only if joinpoint method exits by throwing an exception and are configured using @AfterThrowing annotation mark.\nAfter (finally): These types of advices execute after a joinpoint method, regardless of the method’s exit whether normally or exceptional return and are configured using @After annotation mark.\nAround: These types of advices execute before and after a joinpoint and are configured using @Around annotation mark."
},{"id":"30",
"q":"Write about Core container module? ",
"answer":"Core container module is responsible for the basic functionality of the spring framework. The whole Spring framework is built with this module as a base."
},{"id":"31",
"q":"What is AOP module? ",
"answer":"This AOP module is used for spring enabled application. Support has been provided AOP alliance to ensure the interoperability between spring and other AOP frameworks."
},{"id":"32",
"q":"What is AOP Alliance?",
"answer":"AOP alliance is an open-source project which is aimed at promoting adoption of AOP. The AOP alliance’s goal is to define a common set of components and interfaces so as to improve interoperability among different AOP implementations. "
},{"id":"33",
"q":"What is called spring configuration file?",
"answer":"Spring configuration file is an XML file and it contains class information. It also describes how these classes are configured and interact with each other. "
},{"id":"34",
"q":"What are different types of Autowire?",
"answer":"There are four different types of Auto wire:\n\nbyName\nbyType\nconstructor\nautodetect "
},{"id":"35",
"q":"What are the types of the transaction management that is supported by spring?",
"answer":"Following are the types of transaction management that has been supported by spring:\ndeclarative\nprogrammatically"
},{"id":"36",
"q":"What is Aspect, Advice, Join point and pointcut in Spring AOP?",
"answer":"Aspect: An Aspect is a class that implements concerns that cut across different classes such as logging. It is just a name.\n\nJoint Point : It is a point in execution of program such as execution of method. In Spring AOP, a join point always represents a method execution.\nAdvice : Action taken by aspect at particular join point. For example: Before execution of getEmployeeName() method, put logging. So here, we are using before advice.\nPointcut : Pointcut is an expression that decides execution of advice at matched joint point. Spring uses the AspectJ pointcut expression language by default. "
},{"id":"37",
"q":"What is default scope of bean in Spring? ",
"answer":"singleton is default scope of a bean in Spring. You have to explicitly change scope of a bean if you want different scope. "
},{"id":"38",
"q":"What is Spring MVC Interceptor and how to use it?",
"answer":"Spring MVC Interceptors allow us to intercept a client request and process it at three places – before handling, after handling, or after completion (when the view is rendered) of a request.The interceptor can be used for cross-cutting concerns and to avoid repetitive handler code like logging, changing globally used parameters in Spring model, etc."
},{"id":"39",
"q":"What is a Controller in Spring MVC? ",
"answer":"Simply put, all the requests processed by the DispatcherServlet are directed to classes annotated with @Controller. Each controller class maps one or more requests to methods that process and execute the requests with provided inputs."
},{"id":"40",
"q":"How does the @RequestMapping annotation work? ",
"answer":"he @RequestMapping annotation is used to map web requests to Spring Controller methods. In addition to simple use cases, we can use it for mapping of HTTP headers, binding parts of the URI with @PathVariable, and working with URI parameters and the @RequestParam annotation."
},{"id":"41",
"q":"What are DispatcherServlet and ContextLoaderListener? ",
"answer":"Simply put, in the Front Controller design pattern, a single controller is responsible for directing incoming HttpRequests to all of an application’s other controllers and handlers."
},{"id":"42",
"q":"What is ViewResolver in Spring?",
"answer":"The ViewResolver enables an application to render models in the browser – without tying the implementation to a specific view technology – by mapping view names to actual views."
},{"id":"43",
"q":"What is a MultipartResolver and when is it used?",
"answer":"The MultipartResolver interface is used for uploading files. The Spring framework provides one MultipartResolver implementation for use with Commons FileUpload and another for use with Servlet 3.0 multipart request parsing.\nUsing these, we can support file uploads in our web applications."
},{"id":"44",
"q":"What is Spring JDBCTemplate class and how to use it?",
"answer":"The Spring JDBC template is the primary API through which we can access database operations logic that we’re interested in:\n\ncreation and closing of connections\n\nexecuting statements and stored procedure calls\n\niterating over the ResultSet and returning results"
},{"id":"45",
"q":"What is Spring DAO?",
"answer":"Spring Data Access Object is Spring’s support provided to work with data access technologies like JDBC, Hibernate, and JPA in a consistent and easy way.\n\nYou can, of course, go more in-depth on persistence, with the entire series discussing persistence in Spring."
},{"id":"46",
"q":"What is Weaving?",
"answer":"According to the official docs, weaving is a process that links aspects with other application types or objects to create an advised object. This can be done at compile time, load time, or at runtime. Spring AOP, like other pure Java AOP frameworks, performs weaving at runtime. "
},{"id":"47",
"q":"What is IOC?",
"answer":" IOC (Inversion of Control pattern) is also known as dependency injection. IOC directs the programmers to depict how to create objects instead of actually creating them. But in this design pattern, this control has been given to assembler and assembler will instantiate required class if needed. "
},{"id":"48",
"q":"What is an Aspect?",
"answer":"Aspect is also called as logging which is required throughout the application. Logging or aspect is a cross cutting functionality in an application using AOP. "
},{"id":"49",
"q":"What are the different types of AutoProxying? ",
"answer":"Following are the different types of AutoProxying:\n\nBeanNameAutoProxyCreator\n\nDefaultAdvisorAutoProxyCreator\n\nMetadata autoproxying "
},{"id":"50",
"q":"How can beans be made singleton or prototype? ",
"answer":"The bean tag has an attribute called ‘singleton’. The bean is singleton if its value is ‘TRUE’, otherwise the bean is a prototype."
},{"id":"51",
"q":"Describe about DAO in Spring framework? ",
"answer":"DAO is used to provide integration of Java database connectivity and Object relational mapping objects. DAO is spring framework provides connection for JDBC, hibernate, JDO, JPA, Common client interface and Oracle. "
},
{"id":"52",
"q":"What is ‘Throws advice’ in Spring?",
"answer":"Throws Advice’ define the behavior when an exception occurs. It is an interface and it has no methods which need to be implemented.\n\nA class that implements this interface should have method with this signature:\n\nVoid samplethrow (Throw table t)\n\nVoid samplethrow(Method m, Object[] o, Object target, Throw tablet) "
},{"id":"53",
"q":"What are the various editors used in spring work? ",
"answer":"The various custom editors provided by the Spring Framework are:\n\nPropertyEditor\nURLEditor\nClassEditor\nCustomDateEditor\nFileEditor\nLocaleEditor\nStringArrayPropertyEditor\nStringTrimmerEditor "
},{"id":"54",
"q":"What is the web module?",
"answer":"The web module enables the creation of a web application without XML. The web.xml file needs to be configured for using the web module."
},{"id":"55",
"q":"What is DataAccessException? ",
"answer":"DataAccessException is a RuntimeException. It is an Unchecked Exception. The user cannot be forced to handle these kinds of exceptions."
},{"id":"56",
"q":"What is XMLBeanFactory?",
"answer":"Spring includes several applications of Bean factory. Out of these, org.springframework.beans.factory.xml.XmlBeanFactory is a very important one. It loads the beans on the basis of the definitions stored in an XML file. For the creation of an XmlBeanFactory, a java.io.InputStream is passed to the constructor. The InputStream provides the XML to the factory. For example, for retrieval of the bean, the getBean() method is called by passing the name of the desired bean.\n\nMyBean helloBean = (MyBean) factory.getBean(\"helloBean\");"
},{"id":"57",
"q":"Name the Exception class which is connected to the exceptions thrown by the applications? ",
"answer":"It is the DataAccessException given by org.springframework.dao.DataAccessException"
},{"id":"58",
"q":"What are the important beans lifecycle methods? ",
"answer":"All in all, two bean lifecycle methods are there. The first method is the setup method which is called during the loading of the bean into the container. The second is when the bean is unloaded from the container, and this method is called the teardown."
},{"id":"59",
"q":"What is a Target?",
"answer":"A target is the class that is advised. This class can either be a class to which we want to add a special behavior to or a third party class. The target class is free to center on its major concern using the AOP concepts, regardless of any advice that is being applied."
},{"id":"60",
"q":"Explain the term Proxy? ",
"answer":"The term proxy refers to an object which is produced the application of an advice to the target object."
},{"id":"61",
"q":"What is cross cutting concern and concern in spring AOP?",
"answer":"Cross cutting concern: It is a concern which is applicable throughout the application and it affects the entire application. E.g Security, logging and data transfer are the concerns which are needed in almost every module of an application.\n\nConcern: Concern is a behavior that we want to have in a module of an application. Issues in which we are interested defines our concern."
},
{"id":"62",
"q":"How do you define the scope of a bean?",
"answer":"When defining a <bean> in Spring, we can also declare a scope for the bean. It can be defined through the scope attribute in the bean definition. For example, when Spring has to produce a new bean instance each time one is needed, the bean’s scope attribute to be prototype. On the other hand, when the same instance of a bean must be returned by Spring every time it is needed, the the bean scope attribute must be set to singleton."
},
{"id":"63",
"q":"Are Singleton beans thread safe in Spring Framework? ",
"answer":"No, singleton beans are not thread-safe in Spring framework."
},
{"id":"64",
"q":"What are inner beans in Spring?",
"answer":"When a bean is only used as a property of another bean it can be declared as an inner bean. Spring’s XML-based configuration metadata provides the use of <bean/> element inside the <property/> or <constructor-arg/> elements of a bean definition, in order to define the so-called inner bean. Inner beans are always anonymous and they are always scoped as prototypes."
},
{"id":"65",
"q":"Write about BatchPreparedStatementSetter?",
"answer":"BatchPreparedStatementSetter is used to update more than a single row in one go, they can use BatchPreparedStatementSetter. This interface provides two methods they are\n\nsetValues( PreparedStatement ps, int i) throws SOL exception\n\nint getBatchSize"
},
{"id":"66",
"q":"What is SQLProvider?",
"answer":"SQLProvider has only one method called getSql()and it is implemented using PreparedStatementCreator implementers. It is mainly used for debugging."
},
{"id":"67",
"q":"What is called PreparedStatementCreator?",
"answer":"PreparedStatementCreator is one of the most commonly used interfaces for writing data to the database.\n\ncreatePreparedStatement() is a method that can be used to create and return PreparedStatement from the\n\nConnection argument, and exception handling is automatically taken care of. When this interface is implemented, a different interface SqlProvider can alsobe implemented which has a method called getSql(). This method is useful for providing sql strings to the JdbcTemplate.\n\nIt does not handle SQLExceptions."
},
{"id":"68",
"q":"What is Inner bean? What is the drawback of inner bean?",
"answer":"If a bean element is directly embedded in a property tag while wiring beans, then the bean is called Inner Bean. Its drawback is that it cannot be reprocessed."
},
{"id":"69",
"q":"How is Hibernate accessed using the Spring framework?",
"answer":"Hibernate can be accessed in the following two ways:\n\nBy IOC with a Callback and HibernateTemplate.\n\nBy applying an AOP Interceptor and broadening the HibernateDaoSupport. "
},
{"id":"70",
"q":"Should we use XML or Annotation based wiring?",
"answer":"Which is better depends on a) context b) preference of the team.\n\nIf the configuration is specific to a bean, that is part of the current project code base - for example @Service, @Component, @Autowired - I prefer annotations.\n\nHowever, when it comes to some application related configuration or a common configuration example @ComponentScan, I do not really have a preference. I would leave it to the team. However, I would definitely want the entire team to discuss and agree what they prefer."
}
]
}
"q":"What is a Spring Framework?",
"answer":"Spring is a powerful open source, application framework created to reduce the complexity of enterprise application development. It is light-weighted and loosely coupled.It has layered architecture, which allows you to select the components to use, while also providing a cohesive framework for J2EE application development.Spring framework is also called framework of frameworks as it provides support to various other frameworks such as Struts, Hibernate, Tapestry, EJB, JSF etc. "
},
{"id":"2",
"q":"List the advantages of Spring Framework. ",
"answer":"Because of Spring Frameworks layered architecture, you can use what you need and leave which you don’t.\nSpring Framework enables POJO (Plain Old Java Object) Programming which in turn enables continuous integration and testability.\nJDBC is simplified due to Dependency Injection and Inversion of Control.\nIt is open-source and has no vendor lock-in."
},
{"id":"3",
"q":"What are the different features of Spring Framework?",
"answer":"Lightweight\nInversion of control (IOC)\nAspect oriented Programming (AOP)\nContainer\nMVC Framework\nTransaction Management\nJDBC Exception Handling"
},
{"id":"4",
"q":"What is a Spring configuration file?",
"answer":"A Spring configuration file is an XML file.\nThis file mainly contains the classes information.\nIt describes how those classes are configured as well as introduced to each other.\nThe XML configuration files, however, are verbose and more clean.\nIf it’s not planned and written correctly, it becomes very difficult to manage in big projects. "
},
{"id":"5",
"q":"Which are the Spring framework modules?",
"answer":"The basic modules of the Spring framework are :\n\nCore module\nBean module\nContext module\nExpression Language module\nJDBC module\nORM module\nOXM module\nJava Messaging Service(JMS) module\nTransaction module\nWeb module\nWeb-Servlet module\nWeb-Struts module\nWeb-Portlet module"
},
{"id":"6",
"q":"Explain the Core Container (Application context) module",
"answer":"This is the basic Spring module, which provides the fundamental functionality of the Spring framework.\nBeanFactory is the heart of any spring-based application.\nSpring framework was built on the top of this module, which makes the Spring container. "
},
{"id":"7",
"q":"BeanFactory – BeanFactory implementation example",
"answer":"A BeanFactory is an implementation of the factory pattern that applies Inversion of Control to separate the application’s configuration and dependencies from the actual application code.\nThe most commonly used BeanFactory implementation is the XmlBeanFactory class. "
},
{"id":"8",
"q":"Explain the AOP module",
"answer":"The AOP module is used for developing aspects for our Spring-enabled application.\nMuch of the support has been provided by the AOP Alliance in order to ensure the interoperability between\nSpring and other AOP frameworks. This module also introduces metadata programming to Spring."
},
{"id":"9",
"q":"What are the various ways of using Spring Framework? ",
"answer":"Spring Framework can be used in various ways. They are listed as follows:\nAs a Full-fledged Spring web application.\nAs a third-party web framework, using Spring Frameworks middle-tier.\n\nFor remote usage.\nAs Enterprise Java Bean which can wrap existing POJOs (Plain Old Java Objects)."
},
{"id":"10",
"q":"What do you mean by Dependency Injection? ",
"answer":"In Dependency Injection, you do not have to create your objects but have to describe how they should be created.\nYou don’t connect your components and services together in the code directly, but describe which services are needed by which components in the configuration file.The IoC container will wire them up together."
},
{"id":"11",
"q":"In how many ways can Dependency Injection be done?",
"answer":"In general, dependency injection can be done in three ways, namely :\n\nConstructor Injection\nSetter Injection\nInterface Injection\nIn Spring Framework, only constructor and setter injections are used."
},
{"id":"12",
"q":"How many types of IOC containers are there in spring?",
"answer":"BeanFactory: BeanFactory is like a factory class that contains a collection of beans. It instantiates the bean whenever asked for by clients.\n\nApplicationContext: The ApplicationContext interface is built on top of the BeanFactory interface. It provides some extra functionality on top BeanFactory."
},
{"id":"13",
"q":"Explain Spring Beans?",
"answer":"They are the objects that form the backbone of the user’s application.\nBeans are managed by the Spring IoC container.\nThey are instantiated, configured, wired and managed by a Spring IoC container\nBeans are created with the configuration metadata that the users supply to the container."
},
{"id":"14",
"q":"How many bean scopes are supported by Spring?",
"answer":"The Spring Framework supports five scopes. They are:\n\nSingleton: This provides scope for the bean definition to single instance per Spring IoC container.\nPrototype: This provides scope for a single bean definition to have any number of object instances.\nRequest: This provides scope for a bean definition to an HTTP-request.\nSession: This provides scope for a bean definition to an HTTP-session.\nGlobal-session: This provides scope for a bean definition to an Global HTTP-session."
},
{"id":"15",
"q":"What is the Bean life cycle in Spring Bean Factory Container?",
"answer":"Bean life cycle in Spring Bean Factory Container is as follows:\n\nThe Spring container instantiates the bean from the bean’s definition in the XML file.\nSpring populates all of the properties using the dependency injection, as specified in the bean definition.\nThe factory calls setBeanName() by passing the bean’s ID, if the bean implements the BeanNameAware interface.\nThe factory calls setBeanFactory() by passing an instance of itself, if the bean implements the BeanFactoryAware interface.\npreProcessBeforeInitialization() methods are called if there are any BeanPostProcessors associated with the bean.\nIf an init-method is specified for the bean, then it will be called.\nFinally, postProcessAfterInitialization() methods will be called if there are any BeanPostProcessors associated with the bean. "
},
{"id":"16",
"q":"Define Bean Wiring. ",
"answer":"When beans are combined together within the Spring container, it’s called wiring or bean wiring. The Spring container needs to know what beans are needed and how the container should use dependency injection to tie the beans together, while wiring beans."
},
{"id":"17",
"q":"What do you understand by auto wiring and name the different modes of it?",
"answer":"The Spring container is able to autowire relationships between the collaborating beans. That is, it is possible to let Spring resolve collaborators for your bean automatically by inspecting the contents of the BeanFactory.\n\nDifferent modes of bean auto-wiring are:\n\nno: This is default setting which means no autowiring. Explicit bean reference should be used for wiring.\nbyName: It injects the object dependency according to name of the bean. It matches and wires its properties with the beans defined by the same names in the XML file.\nbyType: It injects the object dependency according to type. It matches and wires a property if its type matches with exactly one of the beans name in XML file.\nconstructor: It injects the dependency by calling the constructor of the class. It has a large number of parameters.\nautodetect: First the container tries to wire using autowire by constructor, if it can’t then it tries to autowire by byType. "
},
{"id":"18",
"q":"What are the limitations with auto wiring? ",
"answer":"Overriding possibility: You can always specify dependencies using <constructor-arg> and <property> settings which will override autowiring.\nPrimitive data type: Simple properties such as primitives, Strings and Classes can’t be autowired.\nConfusing nature: Always prefer using explicit wiring because autowiring is less precise. "
},
{"id":"19",
"q":"What do you understand by @Required annotation? ",
"answer":"@Required is applied to bean property setter methods.\nThis annotation simply indicates that the affected bean property must be populated at the configuration time with the help of an explicit property value in a bean definition or with autowiring. If the affected bean property has not been populated, the container will throw BeanInitializationException. "
},
{"id":"20",
"q":"What do you understand by @Autowired annotation?",
"answer":"The @Autowired annotation provides more accurate control over where and how autowiring should be done.This annotation is used to autowire bean on the setter methods, constructor, a property or methods with arbitrary names or multiple arguments.\n\nBy default, it is a type driven injection.\n\nFor Example:\n\npublic class Employee\n{\nprivate String name;\n@Autowired\npublic void setName(String name)\n{this.name=name; }\npublic string getName()\n{ return name; }\n}"
},
{"id":"21",
"q":"What do you understand by @RequestMapping annotation?",
"answer":"@RequestMapping annotation is used for mapping a particular HTTP request method to a specific class/ method in controller that will be handling the respective request. This annotation can be applied at both levels:\n\nClass level : Maps the URL of the request\n\nMethod level: Maps the URL as well as HTTP request method "
},
{"id":"22",
"q":"Describe Spring DAO support? ",
"answer":"The Data Access Object (DAO) support in Spring makes it easy to work with data access technologies like JDBC, Hibernate or JDO in a consistent way. This allows one to switch between the persistence technologies easily. It also allows you to code without worrying about catching exceptions that are specific to each of these technology. "
},
{"id":"23",
"q":"Which classes are present in spring JDBC API?",
"answer":"Classes present in JDBC API are as follows:\n\nJdbcTemplate\nSimpleJdbcTemplate\n\nNamedParameterJdbcTemplate\nSimpleJdbcInsert\nSimpleJdbcCall"
},{"id":"24",
"q":"What are the ways by which Hibernate can be accessed using Spring? ",
"answer":"There are two ways by which we can access Hibernate using Spring:\n\nInversion of Control with a Hibernate Template and Callback\nExtending HibernateDAOSupport and Applying an AOP Interceptor node"
},{"id":"25",
"q":"Describe AOP. ",
"answer":"Aspect-oriented programming or AOP is a programming technique which allows programmers to modularize crosscutting concerns or behavior that cuts across the typical divisions of responsibility. Examples of cross-cutting concerns can be logging and transaction management. The core of AOP is an aspect. It encapsulates behaviors that can affect multiple classes into reusable modules."
},{"id":"26",
"q":"What do you mean by Aspect?",
"answer":"Aspect is a modularization of concern which cuts across multiple objects.\nTransaction management is a good example of a crosscutting concern in J2EE applications.\nAspects are implemented using regular classes or regular classes annotated with the @Aspect annotation in Spring Framework."
},{"id":"27",
"q":"Explain JoinPoint.",
"answer":"A point during the execution of a program is called JoinPoint,such as the execution of a method or the handling of an exception.\n\nIn Spring AOP, a joinpoint always represents a method execution."
},{"id":"28",
"q":"What is an Advice? ",
"answer":" An Action taken by an aspect at a particular joinpoint is known as an Advice.\n\nSpring AOP uses an advice as an interceptor, maintaining a chain of interceptors “around” the join point."
},{"id":"29",
"q":"What are the different types of Advices? ",
"answer":"\n\nBefore: These types of advices execute before the joinpoint methods and are configured using @Before annotation mark.\nAfter returning: These types of advices execute after the joinpoint methods completes executing normally and are configured using @AfterReturning annotation mark.\nAfter throwing: These types of advices execute only if joinpoint method exits by throwing an exception and are configured using @AfterThrowing annotation mark.\nAfter (finally): These types of advices execute after a joinpoint method, regardless of the method’s exit whether normally or exceptional return and are configured using @After annotation mark.\nAround: These types of advices execute before and after a joinpoint and are configured using @Around annotation mark."
},{"id":"30",
"q":"Write about Core container module? ",
"answer":"Core container module is responsible for the basic functionality of the spring framework. The whole Spring framework is built with this module as a base."
},{"id":"31",
"q":"What is AOP module? ",
"answer":"This AOP module is used for spring enabled application. Support has been provided AOP alliance to ensure the interoperability between spring and other AOP frameworks."
},{"id":"32",
"q":"What is AOP Alliance?",
"answer":"AOP alliance is an open-source project which is aimed at promoting adoption of AOP. The AOP alliance’s goal is to define a common set of components and interfaces so as to improve interoperability among different AOP implementations. "
},{"id":"33",
"q":"What is called spring configuration file?",
"answer":"Spring configuration file is an XML file and it contains class information. It also describes how these classes are configured and interact with each other. "
},{"id":"34",
"q":"What are different types of Autowire?",
"answer":"There are four different types of Auto wire:\n\nbyName\nbyType\nconstructor\nautodetect "
},{"id":"35",
"q":"What are the types of the transaction management that is supported by spring?",
"answer":"Following are the types of transaction management that has been supported by spring:\ndeclarative\nprogrammatically"
},{"id":"36",
"q":"What is Aspect, Advice, Join point and pointcut in Spring AOP?",
"answer":"Aspect: An Aspect is a class that implements concerns that cut across different classes such as logging. It is just a name.\n\nJoint Point : It is a point in execution of program such as execution of method. In Spring AOP, a join point always represents a method execution.\nAdvice : Action taken by aspect at particular join point. For example: Before execution of getEmployeeName() method, put logging. So here, we are using before advice.\nPointcut : Pointcut is an expression that decides execution of advice at matched joint point. Spring uses the AspectJ pointcut expression language by default. "
},{"id":"37",
"q":"What is default scope of bean in Spring? ",
"answer":"singleton is default scope of a bean in Spring. You have to explicitly change scope of a bean if you want different scope. "
},{"id":"38",
"q":"What is Spring MVC Interceptor and how to use it?",
"answer":"Spring MVC Interceptors allow us to intercept a client request and process it at three places – before handling, after handling, or after completion (when the view is rendered) of a request.The interceptor can be used for cross-cutting concerns and to avoid repetitive handler code like logging, changing globally used parameters in Spring model, etc."
},{"id":"39",
"q":"What is a Controller in Spring MVC? ",
"answer":"Simply put, all the requests processed by the DispatcherServlet are directed to classes annotated with @Controller. Each controller class maps one or more requests to methods that process and execute the requests with provided inputs."
},{"id":"40",
"q":"How does the @RequestMapping annotation work? ",
"answer":"he @RequestMapping annotation is used to map web requests to Spring Controller methods. In addition to simple use cases, we can use it for mapping of HTTP headers, binding parts of the URI with @PathVariable, and working with URI parameters and the @RequestParam annotation."
},{"id":"41",
"q":"What are DispatcherServlet and ContextLoaderListener? ",
"answer":"Simply put, in the Front Controller design pattern, a single controller is responsible for directing incoming HttpRequests to all of an application’s other controllers and handlers."
},{"id":"42",
"q":"What is ViewResolver in Spring?",
"answer":"The ViewResolver enables an application to render models in the browser – without tying the implementation to a specific view technology – by mapping view names to actual views."
},{"id":"43",
"q":"What is a MultipartResolver and when is it used?",
"answer":"The MultipartResolver interface is used for uploading files. The Spring framework provides one MultipartResolver implementation for use with Commons FileUpload and another for use with Servlet 3.0 multipart request parsing.\nUsing these, we can support file uploads in our web applications."
},{"id":"44",
"q":"What is Spring JDBCTemplate class and how to use it?",
"answer":"The Spring JDBC template is the primary API through which we can access database operations logic that we’re interested in:\n\ncreation and closing of connections\n\nexecuting statements and stored procedure calls\n\niterating over the ResultSet and returning results"
},{"id":"45",
"q":"What is Spring DAO?",
"answer":"Spring Data Access Object is Spring’s support provided to work with data access technologies like JDBC, Hibernate, and JPA in a consistent and easy way.\n\nYou can, of course, go more in-depth on persistence, with the entire series discussing persistence in Spring."
},{"id":"46",
"q":"What is Weaving?",
"answer":"According to the official docs, weaving is a process that links aspects with other application types or objects to create an advised object. This can be done at compile time, load time, or at runtime. Spring AOP, like other pure Java AOP frameworks, performs weaving at runtime. "
},{"id":"47",
"q":"What is IOC?",
"answer":" IOC (Inversion of Control pattern) is also known as dependency injection. IOC directs the programmers to depict how to create objects instead of actually creating them. But in this design pattern, this control has been given to assembler and assembler will instantiate required class if needed. "
},{"id":"48",
"q":"What is an Aspect?",
"answer":"Aspect is also called as logging which is required throughout the application. Logging or aspect is a cross cutting functionality in an application using AOP. "
},{"id":"49",
"q":"What are the different types of AutoProxying? ",
"answer":"Following are the different types of AutoProxying:\n\nBeanNameAutoProxyCreator\n\nDefaultAdvisorAutoProxyCreator\n\nMetadata autoproxying "
},{"id":"50",
"q":"How can beans be made singleton or prototype? ",
"answer":"The bean tag has an attribute called ‘singleton’. The bean is singleton if its value is ‘TRUE’, otherwise the bean is a prototype."
},{"id":"51",
"q":"Describe about DAO in Spring framework? ",
"answer":"DAO is used to provide integration of Java database connectivity and Object relational mapping objects. DAO is spring framework provides connection for JDBC, hibernate, JDO, JPA, Common client interface and Oracle. "
},
{"id":"52",
"q":"What is ‘Throws advice’ in Spring?",
"answer":"Throws Advice’ define the behavior when an exception occurs. It is an interface and it has no methods which need to be implemented.\n\nA class that implements this interface should have method with this signature:\n\nVoid samplethrow (Throw table t)\n\nVoid samplethrow(Method m, Object[] o, Object target, Throw tablet) "
},{"id":"53",
"q":"What are the various editors used in spring work? ",
"answer":"The various custom editors provided by the Spring Framework are:\n\nPropertyEditor\nURLEditor\nClassEditor\nCustomDateEditor\nFileEditor\nLocaleEditor\nStringArrayPropertyEditor\nStringTrimmerEditor "
},{"id":"54",
"q":"What is the web module?",
"answer":"The web module enables the creation of a web application without XML. The web.xml file needs to be configured for using the web module."
},{"id":"55",
"q":"What is DataAccessException? ",
"answer":"DataAccessException is a RuntimeException. It is an Unchecked Exception. The user cannot be forced to handle these kinds of exceptions."
},{"id":"56",
"q":"What is XMLBeanFactory?",
"answer":"Spring includes several applications of Bean factory. Out of these, org.springframework.beans.factory.xml.XmlBeanFactory is a very important one. It loads the beans on the basis of the definitions stored in an XML file. For the creation of an XmlBeanFactory, a java.io.InputStream is passed to the constructor. The InputStream provides the XML to the factory. For example, for retrieval of the bean, the getBean() method is called by passing the name of the desired bean.\n\nMyBean helloBean = (MyBean) factory.getBean(\"helloBean\");"
},{"id":"57",
"q":"Name the Exception class which is connected to the exceptions thrown by the applications? ",
"answer":"It is the DataAccessException given by org.springframework.dao.DataAccessException"
},{"id":"58",
"q":"What are the important beans lifecycle methods? ",
"answer":"All in all, two bean lifecycle methods are there. The first method is the setup method which is called during the loading of the bean into the container. The second is when the bean is unloaded from the container, and this method is called the teardown."
},{"id":"59",
"q":"What is a Target?",
"answer":"A target is the class that is advised. This class can either be a class to which we want to add a special behavior to or a third party class. The target class is free to center on its major concern using the AOP concepts, regardless of any advice that is being applied."
},{"id":"60",
"q":"Explain the term Proxy? ",
"answer":"The term proxy refers to an object which is produced the application of an advice to the target object."
},{"id":"61",
"q":"What is cross cutting concern and concern in spring AOP?",
"answer":"Cross cutting concern: It is a concern which is applicable throughout the application and it affects the entire application. E.g Security, logging and data transfer are the concerns which are needed in almost every module of an application.\n\nConcern: Concern is a behavior that we want to have in a module of an application. Issues in which we are interested defines our concern."
},
{"id":"62",
"q":"How do you define the scope of a bean?",
"answer":"When defining a <bean> in Spring, we can also declare a scope for the bean. It can be defined through the scope attribute in the bean definition. For example, when Spring has to produce a new bean instance each time one is needed, the bean’s scope attribute to be prototype. On the other hand, when the same instance of a bean must be returned by Spring every time it is needed, the the bean scope attribute must be set to singleton."
},
{"id":"63",
"q":"Are Singleton beans thread safe in Spring Framework? ",
"answer":"No, singleton beans are not thread-safe in Spring framework."
},
{"id":"64",
"q":"What are inner beans in Spring?",
"answer":"When a bean is only used as a property of another bean it can be declared as an inner bean. Spring’s XML-based configuration metadata provides the use of <bean/> element inside the <property/> or <constructor-arg/> elements of a bean definition, in order to define the so-called inner bean. Inner beans are always anonymous and they are always scoped as prototypes."
},
{"id":"65",
"q":"Write about BatchPreparedStatementSetter?",
"answer":"BatchPreparedStatementSetter is used to update more than a single row in one go, they can use BatchPreparedStatementSetter. This interface provides two methods they are\n\nsetValues( PreparedStatement ps, int i) throws SOL exception\n\nint getBatchSize"
},
{"id":"66",
"q":"What is SQLProvider?",
"answer":"SQLProvider has only one method called getSql()and it is implemented using PreparedStatementCreator implementers. It is mainly used for debugging."
},
{"id":"67",
"q":"What is called PreparedStatementCreator?",
"answer":"PreparedStatementCreator is one of the most commonly used interfaces for writing data to the database.\n\ncreatePreparedStatement() is a method that can be used to create and return PreparedStatement from the\n\nConnection argument, and exception handling is automatically taken care of. When this interface is implemented, a different interface SqlProvider can alsobe implemented which has a method called getSql(). This method is useful for providing sql strings to the JdbcTemplate.\n\nIt does not handle SQLExceptions."
},
{"id":"68",
"q":"What is Inner bean? What is the drawback of inner bean?",
"answer":"If a bean element is directly embedded in a property tag while wiring beans, then the bean is called Inner Bean. Its drawback is that it cannot be reprocessed."
},
{"id":"69",
"q":"How is Hibernate accessed using the Spring framework?",
"answer":"Hibernate can be accessed in the following two ways:\n\nBy IOC with a Callback and HibernateTemplate.\n\nBy applying an AOP Interceptor and broadening the HibernateDaoSupport. "
},
{"id":"70",
"q":"Should we use XML or Annotation based wiring?",
"answer":"Which is better depends on a) context b) preference of the team.\n\nIf the configuration is specific to a bean, that is part of the current project code base - for example @Service, @Component, @Autowired - I prefer annotations.\n\nHowever, when it comes to some application related configuration or a common configuration example @ComponentScan, I do not really have a preference. I would leave it to the team. However, I would definitely want the entire team to discuss and agree what they prefer."
}
]
}