Shared Flashcard Set


Multivision Week 7 Spring framework
Undergraduate 4

Additional Software Flashcards




What is Inversion of Control (IOC)?
A key characteristic of IOC is the calling code has the ability to customize the calling methods according to an external cofiguration (XML) file. IOC is heavily used in all frameworks such as Srping, Struts and EJB.
What is Dependecy Injection?
Depency Injection is a specific implementation of Inversion of Control (IOC).
What are the benefits of IOC?
  • Minimizes the 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 can also add additional services  by adding a new constructor of a setter method with little or no extra configuration.
  • Makes your application more testable by not requiring any singletons or JNDI lookup mechanisms in  unit test cases. IOC containers allow is to inject our test objects into the objects under test. 
  • Loose coupling is promoted with minimal effort and is less intrusive. 
  • Flexibility of eager loading (application context) and lazy loading (bean factory). Containers also handle system level operations. 
What is Spring?
Spring is an open source framework that was created to address the complexity of entrerprise application development. One of the chief advantages of the spring framework  is its layered architectures. This allows us to be selective about which of its components we can use to provide a cohesiuve framework for J2EE development.

What are some advantages of the Spring Framework?


  1. Spring is a layered architecture. Use only components you need.
  2. Spring enables POJO programming. There is not behind the scene magic. POJO strengths lie in continuous integration and testability.
  3. Dependency Injection and IOC simplifies JDBC
  4. No vendor lock in due to open source nature
What are some features of Spring?
  • Lightweight - Lighteight in Size and transparency. The basic version of Spring framework is about 1MB. Very low processing overhead.
  • Inversion of Control (IOC)- Loose COupling is acheived in Spring using the technique of IOC. The objects give their dependencies  instead of looking up or creating their dpendencies. 
  • Aspect Oriented Programming- Spring supports AOP and enables  cohesive development by separating business logic from system services.
  • Container- Spring contains and manages the life cycle and configuration of application objects.
  • MVC Framework -Spring comes with an MVC web application framework that is built on core Spring functionality. 
  • This framework is highly configurable via strategy interface and accomodates multiple view technology like JSP, Vleocity, Tiles, iText and POI.Other frameworks can be easily used instead of Spring MVC framework.
  • Transaction Management - Spring framework provides a generic abstraction layer for transsaction manangement. This allows the developer to add the plugable transaction managers and makes it easier to demarcate transactions without dealing with low level issues. Springs transaction support is not tied to the J2EE environments  and it can be used  in container less environments. 
  • JDBC Exception Handling: The JDBC abstraction layer of Spring offers a meaningful exception heirarchy. This simplifies error handling. It integrates well with hibernate and iBatis.
How many modules re in Spring and what are they?
  1. Core Container- THe core container provides the essential fucntionality of the Spring Framework. A primary component of the core container is  the BeanFactory. This is an implementation of the Factory pattern . The bean factory applies IOC pattern to separate an application 's configuration and dependency  specification from the actual application code. 
  2. Spring Context- It is a a configuration file that provides context information to eh Spring framework . The context includes services like JNDI, EJB, e-mail, internationalization, validation and scheduling functionality. 
  3. Spring AOP- This module integrates aspect oriented programming functionality directly to the Spring framework through the configuration management feature. Spring AOP module provides transaction management services for objects in any spring based application. We can implement declarative tranaction management with out relying on EJBs
  4. Spring DAO- This JDBC DAO abstraction layer offers exception handling heirchy for handling error messages that are givien by a multitude of database vendors. This also allows us to write less code since we do not have to have to use try/catch blocks. Checked exceptiosn become unchecked exceptions
  5. Spring ORM- This framework plugs into ORM frameworks to provide a Object Relation Tool. They all can utilize Spring's generic tranaction and DAO heirarchies. 
  6. Spring web module- The wen context module builds on top of the application context module. This provides contexts for web based applicaitons. As a result, the Spring framework supports integrations with Struts. The web module eases the tasks of handling  multiple part requests and binding request parameters to domain objects.
  7. Spring MVC framework- Full featured MVC framework is a full featured MVC implementation for building  web applications. IT is highly configurable and accomodates many view technologies like JSP, Velocity, Tiles, iText, and POI



What is a BeanFactory?

A BeanFactory is like a factory class that contains a collection of beans. The BeanFactory holds a Bean Definition of multiple beans within itself and instatiates the bean when asked by the client(s).

  • BeanFactory is able to create associations between collaborating  objects as they are instantiated. This removes teh burdon of configuration from the bean itself and the beans client. 
  • IT also takes part ing the life cycle of a bean, making calls to custom instantiation and destruction methods.

What is an Application Context?



A bean factory is fine for simple applications but they do not take advantage of the full power of the Spring framework. For this we have to move up to a more advanced container. This is the Application Context. On the surface teh context is the same as a bean factory.  Both load bean definitiions, wore beas together, and dispense beans upon request. It also provides...

  • A means for resolving text messaging (also include internationalization). 
  • Generic way to load file resources. 
  • Event bens that are registered as listeners.
What are the differences between BeandFactory and Application Context?

Applcaition context offers much more than a BeanFactory does this includes:

  • provides a means for resolving text messages including internationalization
  • provides a generic wat to load file resources such as images
  • can publish events to besn that are registered as listeners
  • Certain operations in the container or beans in the cointainer, which have to be handled in a programmatic fashion with a bean factory can be handled declaritively  in an application context.
  • Resource Loader support: Spring resource interface is a flexible generic interface abstraction fo handling low level resources. An application context is a resource loader. It provides the application with access to deployment-specific Resource instances. 
  • MessageSource support: THe application COntext implements MessageSource an interface used to obtain localized messages, with the actual implementation being pluggable.
What are the commont implementations of the Application Context?
  • ClassPathXmlApplicationContext- load the context definitiion from an xml file located in its classpath.This treats the context definition  as a classpath resource.
ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml")
  • FileSystemAmlApplicationContext - it load the definition from the file system.
ApplicationContext context = new FileSystemAmlApplicationContext("bean.xml")
  • XmlWebApplicationContext - loads a defition from an XML file contained in the web application 
What is the typical Bean life cycle in Spring Bean Factory Container.
  • The spring container finds teh bean's definition forn the XML file and instatiates teh bean.
  • Using dependency injection, spring populates all of the properties that are specified in teh bean definition.
  • If the bean implements the BeanNameAware interfacem the factory callw the setBeanName() method passing the bean's ID.
  • Iif the bean implements the BeanFactoryAware  interface, the factory  calls teh setBeanFactory() method passing an instance of itself.
  • If there are any BeanPostProcessors asscociated with the bean, their postProcessBefore Initialization() methods will be called.
  • If an init-method is specified in the bean, it will be called.
  • If there are any BeanPostProcessors associated with the bean, ther postProcessAfterInitialization() methods will be called. 
What is meant by bean wiring?
The act of asscociations between application components (beans) within the Spring container is called bean wiring

What is meant by auto wiring?



The spring container is able to auto wore relationships between collaborating beans. This means that it is possible to automatically let spring resolve collcborators(other beans) for your bean by inspecting contents of the bean factory. Autowiring has 5 modes:

  1. no
  2. byName
  3. byType
  4. constructor
  5. autodirect
How do you integrate Struts with Spring?

Using the Context Loader Plugin

  1. Install the context LoaderPlugin in teh struts-config.xml
  2. the the "type" attribute of the action tage use: org.springFramework.we.struts.DelegatingActionProxy
  3. in action-servlet.xml, map the HTML actio to the action class and reference the injected
  4. in appContext.xml mathe injected bean to the bean class. 
  5. In the action  class install a setter for the ijected bean
What ORMS does Spring support?
  • Hibernate
  • Ibatis
  • JPA (Java Persistence API
  • TopLink
  • JDO(Java Data Objects)
  • OJB
What are the ways to access Hibernate using Spring?
  • Dependency injection with the HibernateTemplate and Callback. (OutDated)
  • Extending the HibernateDaoSupport and applying the AOP interceptor
  • Hibernate Contextual Sessions
How do you integregrate Spring and Hibernate using contextual sessions?

Old way:

  • Create an DaoImpl class with a setter for the SessionFactory
  • Wire up the following beans: data source, SessionFactory, HibernateTransactioManager, TransactionProxyFactoryBean and the target (DaoImpl class)
  • Bind Each CRUD method to a transaction in the TransactionProxyFactoryBean.

New way:

  • Create DaoImpl Class with a setter for the SessionFactory
  • Wire up the following beans: data source, SessionFactory, HibernateTransactionManager, the DaoImpl class
  • Bind each CRUD method to the transaction in the spring.xml. Define the AOP configuration using the aop:config tag, the transaction advice using the tx:advice tag  and the transaction properties (propagation, isolation and rollback for each method with the tx:method tag.
Define Hibernate Template
HibernateTemplate is a helper class that provides different methods for querying and retreiving data from the database. It also converts Hibernate Exceptions into Unchecked exceptions.
What are the benefits of the HibernateTemplate?
  • Simplifies interactions with Hibernate Session.
  • Common fucntions are simplified into simple method calls
  • Sessions are automatically closed
  • Exceptions are automatically caught and converted into runtime exceptions (stack traces are more verbose)


How did you integrate Spring and hibernate using Template Injection?
  • Wire up for beans in the spring XML
    • Data source
    • Local Session Factory
    • Hibernate Template
    • Dao Implementation Class
  • Place setter int eh Template in the DAO implementation Class
  • Carea an annonymous inner class to implement the doInHibernate method of the Callback interface and place the desired CRUD method here. Pass the inner class object to the Template and execute method to invoke the desired CRUD operation. 
What are the Bean Scopes in Spring?
  • Singleton- Scopes a single bean into a single object instance per Spring IoC Container (default scope)
  • prototypeScopes a single bean to any number of object instances. 
  • request- Scopes a single bean into the lifecycle of an HTTP request. That is each HTTP request will have its own instance of the  bean created from a single reference.
  • session- Scopes a single bean into the lifecycle of an HTTP session.
  • global session -  Scopes a single bean into the lifecycle of an HTTP global session.
What is AOP
Aspect oriented Programming is a technique that allows programmers to mudularize cross cutting concerns. This is basically  a behavior that cuts accross the typical divisions of responsibility. Thi core construct is the aspect which emcapsulates 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 dsclarative EJB services. THe must important service is declarative transaction management which builds on Spirings transaction abstraction. This allows isers to implement custom aspects complementing their use of OOP with AOP.
What is meant by Aspect.
It is the modularization of a crosscutting concern.Aspects are implemented by using regular classes(schema based approach) or annotated with @Aspect (@AspectJ style).
What is meant by a join point?
The point during the execution of a program, such as the execution of a method or the handling of an excepption. In Spring AOP a join point always represents a method.
What is meant by advice?
Action taken by an easpect at a particular join point.
What are the types of advice?
  • Introduction: cannot be used with any pointcut, as t it applies ot classrather than method level. You can only use introduction with IntroductionAdvisor
  • Before advice- Advice executes just before the join point.It does not have the ability to prevent execution flow unless it throws an exception. 
  • After returning advice - Advice exectues after the join point executes properly.
  • After throwing advice- executes only if methods exits from exception being thrown.
  • After (finally) advice
  • Around advice- surrounds the join point. Executes before and after execution of join point. 
What are the tpyes of transaction management that Spring supports?
  • Programmatic transaction management
  • Declarative transaction management
What are the benefits of teh Spring Framework transaction management?

The spring framework provides consistent abstraction for transaction management that delivers the following:

  • Provides a consistent programming model accross different transaction APIs (JTA, JDBC, JPA, Hibernate and JDO).
  • Support declarative transaction management
  • Provides a simpler API for programmatic transaction management than a number of complex transaction APIs such as JTA
  • Integrates well with Spring's data access abstractions
When woudd you use programmatic and declarative transaction management?
  • Programmatic transaction is a good ide only if you have a small number of transactional operations.
  • If your application has numerous transaction operations, the declaritive transaction is worthwhile. It ikeeps the transaction management out of the business logic. 
Explain Spring DAO support.

The DAO support in sPring is aimed at making it easy to work with the data access technologies like JDBC, HIbernate and JDo in a cinsistent manner. This allows one to switch between persistence technologies easily while allowing one to code with worrying about catching exceptions that are specific to each technology.


What is Spring's JDBC template?

It is the central class to interact with the database through the JDBC. JdbcTemplate provides many convenience methods for doing thins such as coinverting database data int primitives or objects, executing prepared and callable statements and providing custom error handling.


JdbcTemplate template = new JdbcTemplate(myDataSource)

Supporting users have an ad free experience!