Select Category 
 

Spring Interview Questions Answers

Spring Interview Question - 1 : -

How do you configure spring in a web application?

Spring Interview Answer - 1 : -

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>

 

Spring Interview Question - 2 : -

How does Spring supports DAO in hibernate?

Spring Interview 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);
}
 
}
 

Spring Interview Question - 3 : -

What are the key benifits of Hibernate?

Spring Interview Answer - 3 : -

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

 

Spring Interview Question - 4 : -

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

Spring Interview Answer - 4 : -

Appfuse or equinox.
 

Spring Interview Question - 5 : -

 How do you define hibernate mapping file in spring?

Spring Interview Answer - 5 : -

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>
 

 

Spring Interview Question - 6 : -

What are the different IOC containers available?

Spring Interview Answer - 6 : -

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

Spring Interview Question - 7 : -

How is a typical spring implementation look like?

Spring Interview Answer - 7 : -

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 Interview Question - 8 : -

What are the advantages of spring framework?

Spring Interview Answer - 8 : -

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.