InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What Are Orm's Spring Supports ? |
|
Answer» Spring SUPPORTS the FOLLOWING ORM's :
Spring supports the following ORM's : |
|
| 2. |
What Are The Ways To Access Hibernate By Using Spring? |
|
Answer» There are two WAYS to access HIBERNATE using SPRING:
There are two ways to access hibernate using spring: |
|
| 3. |
Explain Requestmapping Annotation.? |
|
Answer» RequestMapping annotation is used to MAP a URL to EITHER an ENTIRE class or a PARTICULAR handler method. RequestMapping annotation is used to map a URL to either an entire class or a particular handler method. |
|
| 4. |
Explain The @controller Annotation.? |
|
Answer» The @Controller annotation indicates that a PARTICULAR class serves the role of a controller. Spring does not require you to extend any controller BASE class or REFERENCE the SERVLET API. The @Controller annotation indicates that a particular class serves the role of a controller. Spring does not require you to extend any controller base class or reference the Servlet API. |
|
| 5. |
What Is Controller In Spring Mvc Framework? |
|
Answer» Controllers provide access to the application behavior that you typically define through a SERVICE INTERFACE. Controllers interpret USER input and TRANSFORM it into a model that is represented to the user by the view. Spring implements a controller in a very abstract way, which enables you to create a WIDE variety of controllers. Controllers provide access to the application behavior that you typically define through a service interface. Controllers interpret user input and transform it into a model that is represented to the user by the view. Spring implements a controller in a very abstract way, which enables you to create a wide variety of controllers. |
|
| 6. |
What Are The Advantages Of Spring Mvc Over Struts Mvc ? |
|
Answer» FOLLOWING are some of the advantages of Spring MVC over Struts MVC:
Following are some of the advantages of Spring MVC over Struts MVC: |
|
| 7. |
What Is Webapplicationcontext ? |
|
Answer» The WebApplicationContext is an extension of the plain ApplicationContext that has some extra FEATURES NECESSARY for web applications. It differs from a NORMAL ApplicationContext in that it is capable of resolving THEMES, and that it knows which SERVLET it is associated with. The WebApplicationContext is an extension of the plain ApplicationContext that has some extra features necessary for web applications. It differs from a normal ApplicationContext in that it is capable of resolving themes, and that it knows which servlet it is associated with. |
|
| 8. |
What Is A Dispatcherservlet? |
|
Answer» The Spring Web MVC framework is DESIGNED AROUND a DISPATCHERSERVLET that handles all the HTTP requests and responses. The Spring Web MVC framework is designed around a DispatcherServlet that handles all the HTTP requests and responses. |
|
| 9. |
What Is Spring Mvc Framework? |
|
Answer» The Spring web MVC framework provides model-view-controller ARCHITECTURE and READY components that can be used to develop FLEXIBLE and loosely coupled web applications. The MVC PATTERN results in separating the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements. The Spring web MVC framework provides model-view-controller architecture and ready components that can be used to develop flexible and loosely coupled web applications. The MVC pattern results in separating the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements. |
|
| 10. |
Which Of The Above Transaction Management Type Is Preferable? |
|
Answer» DECLARATIVE transaction MANAGEMENT is preferable over PROGRAMMATIC transaction management though it is less FLEXIBLE than programmatic transaction management, which allows you to control transactions through your CODE. Declarative transaction management is preferable over programmatic transaction management though it is less flexible than programmatic transaction management, which allows you to control transactions through your code. |
|
| 11. |
What Are The Types Of The Transaction Management Spring Supports? |
|
Answer» Spring supports two types of transaction management: PROGRAMMATIC transaction management: This means that you have managed the transaction with the help of PROGRAMMING. That gives you extreme flexibility, but it is difficult to maintain. Declarative transaction management: This means you SEPARATE transaction management from the business code. You only USE annotations or XML based configuration to manage the transactions. Spring supports two types of transaction management: Programmatic transaction management: This means that you have managed the transaction with the help of programming. That gives you extreme flexibility, but it is difficult to maintain. Declarative transaction management: This means you separate transaction management from the business code. You only use annotations or XML based configuration to manage the transactions. |
|
| 12. |
How Jdbctemplate Can Be Used? |
|
Answer» With use of Spring JDBC framework the BURDEN of resource management and error handling is reduced a lot. So it leaves DEVELOPERS to WRITE the statements and queries to get the data to and from the database. 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. With use of Spring JDBC framework the burden of resource management and error handling is reduced a lot. So it leaves developers to write the statements and queries to get the data to and from the database. 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. |
|
| 13. |
How Jdbc Can Be Used More Efficiently In Spring Framework? |
|
Answer» JDBC can be used more EFFICIENTLY with the help of a TEMPLATE class provided by spring framework called as JDBCTEMPLATE. JDBC can be used more efficiently with the help of a template class provided by spring framework called as JdbcTemplate. |
|
| 14. |
What Is @aspectj? Based Aspect Implementation? |
|
Answer» @AspectJ refers to a style of declaring aspects as regular JAVA classes ANNOTATED with Java 5 ANNOTATIONS. @AspectJ refers to a style of declaring aspects as regular Java classes annotated with Java 5 annotations. |
|
| 15. |
What Is Xml Schema Based Aspectj Implementation? |
|
Answer» ASPECTS are IMPLEMENTED USING REGULAR classes along with XML BASED configuration. Aspects are implemented using regular classes along with XML based configuration. |
|
| 16. |
What Are The Types Of Advice? |
|
Answer» Spring aspects can work with FIVE kinds of advice mentioned below: before: RUN advice before the a method execution. after: Run advice after the a method execution regardless of its OUTCOME. after-returning: Run advice after the a method execution only if method completes successfully. after-throwing: Run advice after the a method execution only if method exits by throwing an exception. around: Run advice before and after the ADVISED method is invoked. Spring aspects can work with five kinds of advice mentioned below: before: Run advice before the a method execution. after: Run advice after the a method execution regardless of its outcome. after-returning: Run advice after the a method execution only if method completes successfully. after-throwing: Run advice after the a method execution only if method exits by throwing an exception. around: Run advice before and after the advised method is invoked. |
|
| 17. |
What Are The Different Points Where Weaving Can Be Applied? |
|
Answer» Weaving can be DONE at COMPILE time, load time, or at RUNTIME. Weaving can be done at compile time, load time, or at runtime. |
|
| 18. |
What Is Weaving? |
|
Answer» Weaving is the PROCESS of linking ASPECTS with other application types or OBJECTS to create an advised OBJECT. Weaving is the process of linking aspects with other application types or objects to create an advised object. |
|
| 19. |
What Is Target Object? |
|
Answer» The OBJECT being advised by one or more ASPECTS, this object will always be a proxy object. Also REFERRED to as the advised object. The object being advised by one or more aspects, this object will always be a proxy object. Also referred to as the advised object. |
|
| 20. |
What Is Introduction? |
|
Answer» An INTRODUCTION ALLOWS you to ADD NEW METHODS or attributes to existing classes. An introduction allows you to add new methods or attributes to existing classes. |
|
| 21. |
What Is Pointcut? |
|
Answer» This is a set of ONE or more joinpoints where an advice should be EXECUTED. You can SPECIFY pointcuts using expressions or patterns as we will see in our AOP EXAMPLES. This is a set of one or more joinpoints where an advice should be executed. You can specify pointcuts using expressions or patterns as we will see in our AOP examples. |
|
| 22. |
What Is Advice? |
|
Answer» This is the actual ACTION to be TAKEN EITHER before or after the method execution. This is actual piece of code that is INVOKED during program execution by Spring AOP FRAMEWORK. This is the actual action to be taken either before or after the method execution. This is actual piece of code that is invoked during program execution by Spring AOP framework. |
|
| 23. |
What Is Join Point? |
|
Answer» This REPRESENTS a point in your application where you can plug-in AOP aspect. You can ALSO say, it is the actual PLACE in the application where an action will be taken USING Spring AOP framework. This represents a point in your application where you can plug-in AOP aspect. You can also say, it is the actual place in the application where an action will be taken using Spring AOP framework. |
|
| 24. |
What Is The Difference Between Concern And Cross-cutting Concern In Spring Aop? |
|
Answer» Concern: Concern is behavior which we want to have in a module of an application. Concern MAY be defined as a FUNCTIONALITY we want to implement. ISSUES in which we are interested define our concerns. Cross-cutting concern: It's a concern which is applicable throughout the application and it affects the entire application. e.g. LOGGING , security and data TRANSFER are the concerns which are needed in almost every module of an application, hence are cross-cutting concerns. Concern: Concern is behavior which we want to have in a module of an application. Concern may be defined as a functionality we want to implement. Issues in which we are interested define our concerns. Cross-cutting concern: It's a concern which is applicable throughout the application and it affects the entire application. e.g. logging , security and data transfer are the concerns which are needed in almost every module of an application, hence are cross-cutting concerns. |
|
| 25. |
What Is Aspect? |
|
Answer» A module which has a SET of APIs providing cross-cutting requirements. For example, a logging module would be called AOP aspect for logging. An APPLICATION can have any number of aspects depending on the requirement. In Spring AOP, aspects are IMPLEMENTED using regular classes (the schema-based approach) or regular classes ANNOTATED with the @Aspect annotation (@AspectJ style). A module which has a set of APIs providing cross-cutting requirements. For example, a logging module would be called AOP aspect for logging. An application can have any number of aspects depending on the requirement. In Spring AOP, aspects are implemented using regular classes (the schema-based approach) or regular classes annotated with the @Aspect annotation (@AspectJ style). |
|
| 26. |
Describe Some Of The Standard Spring Events.? |
|
Answer» Spring provides the following standard events: ContextRefreshedEvent: This event is published when the APPLICATIONCONTEXT is either initialized or refreshed. This can also be raised using the REFRESH() method on the ConfigurableApplicationContext interface. ContextStartedEvent: This event is published when the ApplicationContext is started using the START() method on the ConfigurableApplicationContext interface. You can poll your database or you can re/start any stopped application after receiving this event. ContextStoppedEvent: This event is published when the ApplicationContext is stopped using the stop() method on the ConfigurableApplicationContext interface. You can do required housekeep work after receiving this event. ContextClosedEvent: This event is published when the ApplicationContext is closed using the close() method on the ConfigurableApplicationContext interface. A closed CONTEXT reaches its end of life; it cannot be refreshed or RESTARTED. RequestHandledEvent: This is a web-specific event telling all beans that an HTTP request has been serviced. Spring provides the following standard events: ContextRefreshedEvent: This event is published when the ApplicationContext is either initialized or refreshed. This can also be raised using the refresh() method on the ConfigurableApplicationContext interface. ContextStartedEvent: This event is published when the ApplicationContext is started using the start() method on the ConfigurableApplicationContext interface. You can poll your database or you can re/start any stopped application after receiving this event. ContextStoppedEvent: This event is published when the ApplicationContext is stopped using the stop() method on the ConfigurableApplicationContext interface. You can do required housekeep work after receiving this event. ContextClosedEvent: This event is published when the ApplicationContext is closed using the close() method on the ConfigurableApplicationContext interface. A closed context reaches its end of life; it cannot be refreshed or restarted. RequestHandledEvent: This is a web-specific event telling all beans that an HTTP request has been serviced. |
|
| 27. |
How Is Event Handling Done In Spring? |
|
Answer» Event handling in the ApplicationContext is PROVIDED through the ApplicationEvent class and ApplicationListener interface. So if a bean IMPLEMENTS the ApplicationListener, then EVERY time an ApplicationEvent gets published to the ApplicationContext, that bean is NOTIFIED. Event handling in the ApplicationContext is provided through the ApplicationEvent class and ApplicationListener interface. So if a bean implements the ApplicationListener, then every time an ApplicationEvent gets published to the ApplicationContext, that bean is notified. |
|
| 28. |
What Is Spring Java Based Configuration? Give Some Annotation Example.? |
|
Answer» Java BASED CONFIGURATION option enables you to write most of your Spring configuration without XML but with the help of few Java-based ANNOTATIONS. For example: Annotation @Configuration indicates that the class can be USED by the Spring IOC container as a source of bean definitions. The @Bean annotation tells Spring that a method annotated with @Bean will return an object that should be registered as a bean in the Spring application context. Java based configuration option enables you to write most of your Spring configuration without XML but with the help of few Java-based annotations. For example: Annotation @Configuration indicates that the class can be used by the Spring IoC container as a source of bean definitions. The @Bean annotation tells Spring that a method annotated with @Bean will return an object that should be registered as a bean in the Spring application context. |
|
| 29. |
What Are The Jsr-250 Annotations? Explain Them.? |
|
Answer» Spring has JSR-250 based annotations which INCLUDE @POSTCONSTRUCT, @PreDestroy and @Resource annotations. @PostConstruct: This annotation can be USED as an ALTERNATE of initialization callback. @PreDestroy: This annotation can be used as an alternate of destruction callback. @Resource : This annotation can be used on fields or setter METHODS. The @Resource annotation takes a 'name' attribute which will be interpreted as the bean name to be injected. You can say, it follows by-name autowiring semantics. Spring has JSR-250 based annotations which include @PostConstruct, @PreDestroy and @Resource annotations. @PostConstruct: This annotation can be used as an alternate of initialization callback. @PreDestroy: This annotation can be used as an alternate of destruction callback. @Resource : This annotation can be used on fields or setter methods. The @Resource annotation takes a 'name' attribute which will be interpreted as the bean name to be injected. You can say, it follows by-name autowiring semantics. |
|
| 30. |
What Does @qualifier Annotation Mean? |
|
Answer» There MAY be a SITUATION when you create more than one bean of the same type and want to wire only one of them with a property, in such CASE you can use @Qualifier annotation along with @Autowired to REMOVE the confusion by specifying which exact bean will be WIRED. There may be a situation when you create more than one bean of the same type and want to wire only one of them with a property, in such case you can use @Qualifier annotation along with @Autowired to remove the confusion by specifying which exact bean will be wired. |
|
| 31. |
What Does @autowired Annotation Mean? |
|
Answer» This annotation provides more fine-grained control over where and how autowiring should be accomplished. The @Autowired annotation can be used to autowire bean on the SETTER METHOD just LIKE @Required annotation, constructor, a property or methods with ARBITRARY names and/or multiple arguments. This annotation provides more fine-grained control over where and how autowiring should be accomplished. The @Autowired annotation can be used to autowire bean on the setter method just like @Required annotation, constructor, a property or methods with arbitrary names and/or multiple arguments. |
|
| 32. |
What Does @required Annotation Mean? |
|
Answer» This ANNOTATION simply indicates that the affected bean PROPERTY must be populated at configuration time, through an explicit property value in a bean DEFINITION or through AUTOWIRING. The CONTAINER throws BeanInitializationException if the affected bean property has not been populated. This annotation simply indicates that the affected bean property must be populated at configuration time, through an explicit property value in a bean definition or through autowiring. The container throws BeanInitializationException if the affected bean property has not been populated. |
|
| 33. |
How Do You Turn On Annotation Wiring? |
|
Answer» Annotation wiring is not TURNED on in the Spring CONTAINER by default. So, before we can USE annotation-based wiring, we will need to enable it in our Spring configuration file by CONFIGURING <context:annotation-config/>. Annotation wiring is not turned on in the Spring container by default. So, before we can use annotation-based wiring, we will need to enable it in our Spring configuration file by configuring <context:annotation-config/>. |
|
| 34. |
What Is Annotation-based Container Configuration? |
|
Answer» An alternative to XML setups is provided by annotation-based configuration which RELIES on the bytecode metadata for wiring up components instead of angle-bracket DECLARATIONS. Instead of using XML to DESCRIBE a bean wiring, the developer moves the configuration into the component CLASS itself by using annotations on the relevant class, method, or field declaration. An alternative to XML setups is provided by annotation-based configuration which relies on the bytecode metadata for wiring up components instead of angle-bracket declarations. Instead of using XML to describe a bean wiring, the developer moves the configuration into the component class itself by using annotations on the relevant class, method, or field declaration. |
|
| 35. |
Can You Inject Null And Empty String Values In Spring? |
|
Answer» Yes. Yes. |
|
| 36. |
What Are The Limitations With Autowiring? |
|
Answer» Limitations of autowiring are: Overriding possibility: You can still specify dependencies using <constructor-arg> and <property> settings which will ALWAYS OVERRIDE autowiring. Primitive data types: You cannot autowire so-called simple properties such as PRIMITIVES, Strings, and Classes. Confusing nature: Autowiring is LESS exact than explicit wiring, so if possible prefer using explicit wiring. Limitations of autowiring are: Overriding possibility: You can still specify dependencies using <constructor-arg> and <property> settings which will always override autowiring. Primitive data types: You cannot autowire so-called simple properties such as primitives, Strings, and Classes. Confusing nature: Autowiring is less exact than explicit wiring, so if possible prefer using explicit wiring. |
|
| 37. |
What Are Different Modes Of Auto Wiring? |
|
Answer» The autowiring functionality has five modes which can be USED to instruct Spring container to use autowiring for dependency injection: no: This is default setting which means no autowiring and you should use explicit BEAN reference for wiring. You have nothing to do special for this wiring. This is what you already have seen in Dependency Injection chapter. byName: Autowiring by property name. Spring container looks at the properties of the beans on which AUTOWIRE attribute is set to byName in the XML configuration file. It then tries to match and wire its properties with the beans defined by the same names in the configuration file. byType: Autowiring by property datatype. Spring container looks at the properties of the beans on which autowire attribute is set to byType in the XML configuration file. It then tries to match and wire a property if its type matches with exactly one of the beans name in configuration file. If more than one such beans exist, a fatal exception is thrown. constructor: SIMILAR to byType, but type applies to constructor arguments. If there is not exactly one bean of the constructor argument type in the container, a fatal error is raised. AUTODETECT: Spring first tries to wire using autowire by constructor, if it does not work, Spring tries to autowire by byType. The autowiring functionality has five modes which can be used to instruct Spring container to use autowiring for dependency injection: no: This is default setting which means no autowiring and you should use explicit bean reference for wiring. You have nothing to do special for this wiring. This is what you already have seen in Dependency Injection chapter. byName: Autowiring by property name. Spring container looks at the properties of the beans on which autowire attribute is set to byName in the XML configuration file. It then tries to match and wire its properties with the beans defined by the same names in the configuration file. byType: Autowiring by property datatype. Spring container looks at the properties of the beans on which autowire attribute is set to byType in the XML configuration file. It then tries to match and wire a property if its type matches with exactly one of the beans name in configuration file. If more than one such beans exist, a fatal exception is thrown. constructor: Similar to byType, but type applies to constructor arguments. If there is not exactly one bean of the constructor argument type in the container, a fatal error is raised. autodetect: Spring first tries to wire using autowire by constructor, if it does not work, Spring tries to autowire by byType. |
|
| 38. |
What Is Bean Auto Wiring? |
|
Answer» 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 without using <constructor-arg> and <PROPERTY> elements. 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 without using <constructor-arg> and <property> elements. |
|
| 39. |
How Can You Inject Java Collection In Spring? |
|
Answer» Spring offers FOUR types of collection configuration elements which are as follows: <list>: This helps in wiring i.e. injecting a list of values, allowing duplicates. <set>: This helps in wiring a set of values but without any duplicates. <MAP>: This can be used to INJECT a collection of name-value pairs where name and value can be of any type. <props>: This can be used to inject a collection of name-value pairs where the name and value are both Strings. Spring offers four types of collection configuration elements which are as follows: <list>: This helps in wiring i.e. injecting a list of values, allowing duplicates. <set>: This helps in wiring a set of values but without any duplicates. <map>: This can be used to inject a collection of name-value pairs where name and value can be of any type. <props>: This can be used to inject a collection of name-value pairs where the name and value are both Strings. |
|
| 40. |
What Are Inner Beans In Spring? |
|
Answer» A <bean/> element inside the <property/> or <constructor-arg/> elements defines a so-called inner bean. An inner bean definition does not require a defined id or name; the CONTAINER ignores these values. It also ignores the SCOPE FLAG. Inner BEANS are always anonymous and they are always scoped as prototypes. A <bean/> element inside the <property/> or <constructor-arg/> elements defines a so-called inner bean. An inner bean definition does not require a defined id or name; the container ignores these values. It also ignores the scope flag. Inner beans are always anonymous and they are always scoped as prototypes. |
|
| 41. |
Explain Bean Life Cycle In Spring Framework? |
|
Answer» Following is sequence of a bean LIFECYCLE in Spring: Instantiate - First the spring container finds the bean's definition from the XML file and instantiates the bean.. Populate PROPERTIES - Using the dependency injection, spring populates all of the properties as specified in the bean definition.. Set Bean Name - If the bean implements BeanNameAware interface, spring passes the bean's id to setBeanName() method. Set Bean factory - If Bean implements BeanFactoryAware interface, spring passes the beanfactory to setBeanFactory() method. PRE Initialization - Also called POSTPROCESS of bean. If there are any bean BeanPostProcessors associated with the bean, Spring calls postProcesserBeforeInitialization() method. Initialize beans - If the bean implements IntializingBean,its afterPropertySet() method is called. If the bean has init method declaration, the specified initialization method is called. Post Initialization - If there are any BeanPostProcessors associated with the bean, their postProcessAfterInitialization() METHODS will be called. Ready to use - Now the bean is ready to use by the application. Destroy - If the bean implements DisposableBean , it will call the destroy() method . Following is sequence of a bean lifecycle in Spring: Instantiate - First the spring container finds the bean's definition from the XML file and instantiates the bean.. Populate properties - Using the dependency injection, spring populates all of the properties as specified in the bean definition.. Set Bean Name - If the bean implements BeanNameAware interface, spring passes the bean's id to setBeanName() method. Set Bean factory - If Bean implements BeanFactoryAware interface, spring passes the beanfactory to setBeanFactory() method. Pre Initialization - Also called postprocess of bean. If there are any bean BeanPostProcessors associated with the bean, Spring calls postProcesserBeforeInitialization() method. Initialize beans - If the bean implements IntializingBean,its afterPropertySet() method is called. If the bean has init method declaration, the specified initialization method is called. Post Initialization - If there are any BeanPostProcessors associated with the bean, their postProcessAfterInitialization() methods will be called. Ready to use - Now the bean is ready to use by the application. Destroy - If the bean implements DisposableBean , it will call the destroy() method . |
|
| 42. |
Are Singleton Beans Thread Safe In Spring Framework? |
|
Answer» No, SINGLETON BEANS are not thread-safe in SPRING FRAMEWORK. No, singleton beans are not thread-safe in Spring framework. |
|
| 43. |
What Is Default Scope Of Bean In Spring Framework? |
|
Answer» The default SCOPE of BEAN is SINGLETON for SPRING framework. The default scope of bean is Singleton for Spring framework. |
|
| 44. |
What Bean Scopes Does Spring Support? Explain Them.? |
|
Answer» The Spring Framework supports following five scopes, three of which are available only if you use a web-aware APPLICATIONCONTEXT. singleton: This scopes the BEAN definition to a single instance per Spring IoC container. PROTOTYPE: This scopes a single bean definition to have any NUMBER of object instances. request: This scopes a bean definition to an HTTP request. Only valid in the context of a web-aware Spring ApplicationContext. session: This scopes a bean definition to an HTTP session. Only valid in the context of a web-aware Spring ApplicationContext. global-session: This scopes a bean definition to a global HTTP session. Only valid in the context of a web-aware Spring ApplicationContext. The Spring Framework supports following five scopes, three of which are available only if you use a web-aware ApplicationContext. singleton: This scopes the bean definition to a single instance per Spring IoC container. prototype: This scopes a single bean definition to have any number of object instances. request: This scopes a bean definition to an HTTP request. Only valid in the context of a web-aware Spring ApplicationContext. session: This scopes a bean definition to an HTTP session. Only valid in the context of a web-aware Spring ApplicationContext. global-session: This scopes a bean definition to a global HTTP session. Only valid in the context of a web-aware Spring ApplicationContext. |
|
| 45. |
How Do You Define A Bean Scope? |
|
Answer» When defining a <bean> in Spring, you have the option of declaring a scope for that bean. For example, to force Spring to produce a new bean instance each time one is needed, you should DECLARE the bean's scope attribute to be prototype. Similar WAY if you want Spring to RETURN the same bean instance each time one is needed, you should declare the bean's scope attribute to be SINGLETON. When defining a <bean> in Spring, you have the option of declaring a scope for that bean. For example, to force Spring to produce a new bean instance each time one is needed, you should declare the bean's scope attribute to be prototype. Similar way if you want Spring to return the same bean instance each time one is needed, you should declare the bean's scope attribute to be singleton. |
|
| 46. |
How Do Add A Bean In Spring Application? |
|
Answer» Check the following example: <?xml version="1.0" encoding="UTF-8"?> <BEANS xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="helloWorld" class="com.tutorialspoint.HelloWorld"> <property name="message" VALUE="HELLO WORLD!"/> </bean> </beans> Check the following example: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="helloWorld" class="com.tutorialspoint.HelloWorld"> <property name="message" value="Hello World!"/> </bean> </beans> |
|
| 47. |
How Do You Provide Configuration Metadata To The Spring Container? |
|
Answer» There are following THREE important methods to provide CONFIGURATION metadata to the Spring Container:
There are following three important methods to provide configuration metadata to the Spring Container: |
|
| 48. |
What Does A Bean Definition Contain? |
|
Answer» The BEAN DEFINITION contains the information called CONFIGURATION metadata which is NEEDED for the container to KNOW the followings:
The bean definition contains the information called configuration metadata which is needed for the container to know the followings: |
|
| 49. |
What Are Spring Beans? |
|
Answer» The objects that form the backbone of your application and that are MANAGED by the Spring IoC container are called beans. A bean is an object that is INSTANTIATED, ASSEMBLED, and otherwise managed by a Spring IoC container. These beans are created with the configuration metadata that you supply to the container, for example, in the form of XML <bean/> definitions. The objects that form the backbone of your application and that are managed by the Spring IoC container are called beans. A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. These beans are created with the configuration metadata that you supply to the container, for example, in the form of XML <bean/> definitions. |
|
| 50. |
What Is The Difference Between Bean Factory And Applicationcontext? |
|
Answer» Following are some of the differences:
Following are some of the differences: |
|