• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/40

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

40 Cards in this Set

  • Front
  • Back

What is IOC?

A key characteristic of IOC is the calling code has the ability to customize the calling methods according to an external configuration (XML) file. IOC is used heavily in all frameworks such as Spring, Struts, and EjB.

What is dependency injection?

Dependency injection is a specific implementation of inversion of control (IOC).

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

There are three types of dependency injection:


● Constructor Injection (e.g. Pico container, Spring etc): Dependencies are provided as constructor parameters.


● Setter Injection (e.g. Spring): Dependencies are assigned through JavaBeans properties (ex: setter methods).


● Interface Injection (e.g. Avalon): Injection is done through an interface.Note: Spring supports only Constructor and Setter Injection

What are the benefits of IOC ?

Benefits of IOC are as follows:


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


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


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


● IOC containers support eager instantiation and lazy loading of services. Containers also provide support for instantiation of managed objects, cyclical dependencies, life cycles management, and dependency resolution between managed objects etc.

What is Spring ?

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

What are some features of Spring ?

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


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


● Aspect oriented (AOP):Spring supports Aspect oriented programming and enables cohesive development by separating application business logic from system services.


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


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


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


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

Name the modules of Spring.

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


1) CoreContainer


org.springframework.core


org.springframework.beans


org.springframework.expression


org.springframework.context


org.springframework.context.support




2) Test


org.springframework.test




3) AOP


org.springframework.aop


org.springframework.aspects




4) Instrumentation


org.springframework.instrument


org.springframework.instrument.tomcat




5) Web and Remoting


org.springframework.web


org.springframework.web.portlet


org.springframework.web.servlet


org.springframework.web.struts




6) Data Access and Integration


org.springframework.jdbc


org.springframework.jms


org.springframework.orm


org.springframework.oxm


org.springframework.transaction

What is Bean Factory?

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


● BeanFactory is able to create associations between collaborating objects as they are instantiated. This removes the burden of configuration from bean itself and the beans client.


● BeanFactory also takes part in the life cycle of a bean, making calls to custom initialization and destruction methods.

What is Application Context?

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


● A means for resolving text messages, including support for internationalization.


● A generic way to load file resources.


● Events to beans that are registered as listeners.

What is the difference between BeanFactory and ApplicationContext ?

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


● ApplicationContext preinstantiates the beans (Singletons) while BeanFactory does lazy initialization.


● ApplicationContext provides a means for resolving text messages including support for I18N.


● ApplicationContext provide a generic way to load file resources such as images.


● ApplicationContext can publish events to beans that are registered as listeners.


● Certain operations on the container or beans in the container, which have to be handled in a programmatic fashion with a bean factory, can be handled declaratively in an application context.


● ResourceLoader support: Spring’s Resource interface us a flexible generic abstraction for handling low-level resources. An ApplicationContext itself is a ResourceLoader, Hence provides an application with access to deployment-specific Resource instances.


● MessageSource support: The ApplicationContext implements MessageSource, an interface used to obtain localized messages, with the actual implementation being pluggable.

What are the common implementations of the Application Context ?

The three commonly used implementation of ‘Application Context’ are


● ClassPathXmlApplicationContext : It loads context definition from an XML file located in the classpath, treating context definitions as classpath resources. The application context is loaded from the application’s classpath by using the code .ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");


● FileSystemXmlApplicationContext : It loads a context definition from an XML file in the file system. The application context is loaded from the file system by using the code .ApplicationContext context = new FileSystemXmlApplicationContext("bean.xml");


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

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

Bean life cycle in Spring Bean Factory Container is as follows:


● The spring container finds the bean’s definition from the XML file and instantiates the bean.


● Using the dependency injection, spring populates all of the properties as specified in the bean definition


● If the bean implements the BeanNameAware interface, the factory calls setBeanName() passing the bean’s ID.


● If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of itself.


● If there are any BeanPostProcessors associated with the bean, their post- ProcessBeforeInitialization() methods will be called.


● If an init-method is specified for the bean, it will be called.


● Finally, if there are any BeanPostProcessors associated with the bean, their postProcessAfterInitialization() methods will be called.

What do you mean by autowiring?

The Spring container is able to autowire relationships between collaborating beans. This means that it is possible to automatically let Spring resolve collaborators (other beans) for your bean by inspecting the contents of the BeanFactory. The autowiring functionality has four modes.


● byName


● byType


● constructor


● autodetect

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

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

What does DefaultAnnotationHandlerMapping do in Spring MVC?

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

What do you mean by bean wiring ?

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

What does the ViewResolver do in Spring MVC?

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

How do you turn ON annotation support in Spring MVC?

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

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

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


@Controller This registers the class as a controller and must be used in conjunction with tag in the XML to automatically discover and register the controllers as Spring beans.


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

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

To turn ON autowiring use the tag in the spring xml.This will enble @Autowired, @Inject (JSR-330), and @Resource (JSR-250).

How does the @Autowired annotation work?

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

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

By default, in the spring.xml tells the container to look for classes that are annotated with one of the following:@Component The class defines a Spring component.@Controller The class defines a Spring MVC controller.@Repository The class defines a data repository such as a DAO implementation class.@Service The class defines a service.

How do you integrate Struts with Spring?

Using ContextLoaderPlugIn:


● Install the ContextLoaderPlugin in struts-config.xml


● In the "type" attribute of the action tag use: org.springframework.web.struts.DelegatingActionProxy.


● In action-servlet.xml map the HTML action to the action class and reference the injected bean.


● In appContext.xml map the injected bean to a bean class.


● In the action class install a setter for the injected bean.

What ORMs does Spring support ?

Spring supports the following ORMs :


● Hibernate


● iBatis


● JPA (Java Persistence API)


● TopLink


● JDO (Java Data Objects)


● OJB

What are the ways to access Hibernate using Spring?

There are several ways to achieve this; however, the two popular approaches to Spring’s Hibernate integration are:


● Hibernate Contextual Sessions (newer)


● HibernateTemplate (older)

How do you integrate Spring and Hibernate using Contextual Sessions?

There are two popular approaches to this declarative, POJO-based integration:1) XML approach:


● Create the DaoImpl class with a setter for the Session Factory.


● Wire up the following beans: DataSource, SessionFactory, HibernateTransactionManager, and DaoImpl class.


● Bind each CRUD method to a transaction in the appContext.xml. Define the AOP configuarion using the tags and the transaction advice using the tags and the transaction properties (propagation, isolation, and rollback) for each method with the tags.2) Annotation approach:


● Create the annotated (@Repository) DaoImpl class with an annotated (@Inject) sessionFactory.


● Wire up the following beans: DataSource, SessionFactory, and HibernateTransactionManager in the appContext.xml


● Use to find the annotated classes.


● Include a PersistenceExceptionTranslationPostProcessor bean definition to convert platform specific exceptions to a richer set of Spring runtime data access exceptions.


● Bind and annotate (@Transactional) each CRUD method to a transaction in the DaoImpl class and use the tag in appContext.xml.

Define HibernateTemplate.

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

What benefits does the HibernateTemplate provide?

The benefits of the Hibernate Template are:


● HibernateTemplate, a Spring Template class simplifies interactions with Hibernate Session. ● Common functions are simplified to single method calls.


● Sessions are automatically closed.


● Exceptions are automatically caught and converted to runtime exceptions.

How did you integrate Spring and Hibernate using Template Injection?

Follow this three-step process:


● Wire up the following beans in the spring.xml: DataSource, SessionFactory, HibernateTransactionManager, and DaoImpl class.


● Place a setter for the HibernateTemplate in the DaoImpl class and


● Create an anonymous inner class to implement the doInHibernate method of the Callback interface and place the desired Template CRUD method there. Pass the inner class object to the Template execute method to invoke the desired CRUD operation.

What are Bean scopes in Spring Framework ?

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




1) singleton - scopes a single bean definition to a single object instance per Spring IoC container.




2) prototype - scopes a single bean definition to any number of object instances.




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




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




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

What is AOP?

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

How is AOP used in Spring?

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

What do you mean by Aspect ?

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

What do you mean by join point?

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

What do you mean by Advice?

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

What are the types of Advice?

Types of advice:


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


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


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


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


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


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

What are the types of the transaction management Spring supports?

Spring Framework supports:


● Programmatic transaction management.


● Declarative transaction management.

What are the benefits of the Spring Framework transaction management?

The Spring Framework provides a consistent abstraction for transaction management that delivers the following benefits:


● Provides a consistent programming model across different transaction APIs such as JTA, JDBC, Hibernate, JPA, and JDO.


● Supports declarative transaction management.


● Provides a simpler API for programmatic transaction management than a number of complex transaction APIs such as JTA.


● Integrates very well with Spring’s various data access abstractions.

When to use programmatic and declarative transaction management ?

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

What is Spring's jdbc template?

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




JdbcTemplate template = new JdbcTemplate(myDataSource);