Q: What are the different advice types in spring?
Around : Intercepts the calls to the target method
Before : This is called before the target method is invoked
After : This is called after the target method is returned
Throws : This is called when the target method throws and exception
Around : org.aopalliance.intercept.MethodInterceptor
Before : org.springframework.aop.BeforeAdvice
After : org.springframework.aop.AfterReturningAdvice
Throws : org.springframework.aop.ThrowsAdvice
Q: What are the different types of AutoProxying?
BeanNameAutoProxyCreator
DefaultAdvisorAutoProxyCreator
Metadata autoproxying
Q: What is the Exception class related to all the exceptions that are thrown in spring applications?
DataAccessException -
org.springframework.dao.DataAccessException
Q: What kind of exceptions those spring DAO classes throw?
The spring’s DAO class does not throw any technology related exceptions such as SQLException. They throw exceptions which are subclasses of DataAccessException.
Q: What is DataAccessException?
DataAccessException is a RuntimeException. This is an Unchecked Exception. The user is not forced to handle these kinds of exceptions.
Q: How can you configure a bean to get DataSource from JNDI?
Q: How can you create a DataSource connection pool?
${db.url}
${db.username}
Q: How JDBC can be used more efficiently in spring framework?
JDBC can be used more efficiently with the help of a template class provided by spring framework called as JdbcTemplate.
Q: How JdbcTemplate can be used?
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 template = new JdbcTemplate(myDataSource);
A simple DAO class looks like this.
public class StudentDaoJdbc implements StudentDao {
private JdbcTemplate jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
} more..
}
Q: How do you write data to backend in spring using JdbcTemplate?
The JdbcTemplate uses several of these callbacks when writing data to the database. The usefulness you will find in each of these interfaces will vary. There are two simple interfaces. One is PreparedStatementCreator and the other interface is BatchPreparedStatementSetter.
Q: Explain about PreparedStatementCreator?
PreparedStatementCreator is one of the most common used interfaces for writing data to database. The interface has one method createPreparedStatement().
PreparedStatement createPreparedStatement
(Connection conn) throws SQLException;
When this interface is implemented, we should create and return a PreparedStatement from the Connection argument, and the exception handling is automatically taken care off. When this interface is implemented, another interface SqlProvider is also implemented which has a method called getSql() which is used to provide sql strings to JdbcTemplate.
Q: Explain about BatchPreparedStatementSetter?
If the user what to update more than one row at a shot then he can go for BatchPreparedStatementSetter. This interface provides two methods
setValues(PreparedStatement ps, int i) throws SQLException;
int getBatchSize();
The getBatchSize() tells the JdbcTemplate class how many statements to create. And this also determines how many times setValues() will be called.
Q: Explain about RowCallbackHandler and why it is used?
In order to navigate through the records we generally go for ResultSet. But spring provides an interface that handles this entire burden and leaves the user to decide what to do with each row. The interface provided by spring is RowCallbackHandler. There is a method processRow() which needs to be implemented so that it is applicable for each and everyrow.
void processRow(java.sql.ResultSet rs);
Questions Source : http://www.javabeat.net/2009/02/spring-framework-interview-questions/