• +91 9971497814
  • info@interviewmaterial.com

Spring Interview Questions Answers

Question 1 : Can you name a tool which could provide the initial ant files and directory structure for a new spring project.

Answer 1 : Appfuse or equinox.

Question 2 : How does Spring supports DAO in hibernate?

Answer 2 : Spring’s HibernateDaoSupport class is a convenient super class for Hibernate DAOs. It has handy methods you can call to get a Hibernate Session, or a SessionFactory. The most convenient method is getHibernateTemplate(), which returns a HibernateTemplate. This template wraps Hibernate checked exceptions with runtime exceptions, allowing your DAO interfaces to be Hibernate exception-free. Example:  public class UserDAOHibernate extends HibernateDaoSupport {   public User getUser(Long id) { return (User) getHibernateTemplate().get(User.class, id); } public void saveUser(User user) { getHibernateTemplate().saveOrUpdate(user); if (log.isDebugEnabled()) { log.debug(“userId set to: “ + user.getID()); } } public void removeUser(Long id) { Object user = getHibernateTemplate().load(User.class, id); getHibernateTemplate().delete(user); }   }

Question 3 : How do you configure spring in a web application?

Answer 3 : It is very easy to configure any J2EE-based web application to use Spring. At the very least, you can simply add Spring’s ContextLoaderListener to your web.xml file:   <listener>     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>

Question 4 : What are the key benifits of Hibernate?

Answer 4 : These are the key benifits of Hibernate: Transparent persistence based on POJOs without byte code processing  Powerful object-oriented hibernate query language Descriptive O/R Mapping through mapping file. Automatic primary key generation  Hibernate cache : Session Level, Query and Second level cache. Performance: Lazy initialization, Outer join fetching, Batch fetching

Question 5 : What are the different IOC containers available?

Answer 5 : Spring is an IOC container. Other IOC containers are HiveMind, Avalon, PicoContainer.

Question 6 : What are the advantages of spring framework?

Answer 6 : Spring has layed architecture. Use what you need and leave you don't need now. Spring Enables POJO Programming. There is no behind the scene magic here. POJO programming enables continous integration and testability. Dependency Injection and Inversion of Control Simplifies JDBC (Read the first question.) Open source and no vendor lock-in.

Question 7 :  How do you define hibernate mapping file in spring?

Answer 7 : Add the hibernate mapping file entry in mapping resource inside Spring’s applicationContext.xml file in the web/WEB-INF directory.    <property name="mappingResources">     <list>         <value>org/appfuse/model/User.hbm.xml</value>     </list> </property>  

Question 8 : How is a typical spring implementation look like?

Answer 8 : For a typical Spring Application we need the following files    1. An interface that defines the functions. 2. An Implementation that contains properties, its setter and getter methods, functions etc., 3. A XML file called Spring configuration file. 4. Client program that uses the function.

Spring Contributors


Share your email for latest updates


Our partners