XML-Based Configuration: This type of configuration stores all of a program’s bean definitions and dependencies in an XML
file. These files are imported by providing a full file path, like on line 1 below.
<bean id="bean1" class="io.Educative.firstSpring.Bean1">
<property name="name" value="Educative"></property>
</bean>
Annotation-Based Configuration: You can instead create annotations on a class, method, or field in a bean to position it within a component class.
<beans>
<context:annotation-config/>
<!-- bean definitions go here -->
</beans>
Java-Based Configuration: This type of configuration allows you to skip <bean>
syntax and instead use the @Bean
tag to achieve the same thing. You can also create configuration classes with the @Configuration
tag, allowing you to create dependencies between beans by calling other@Bean
classes.
@Configuration
public class BeanConfig
{
@Bean
public Bean1 myBean()
{ return new Bean1(); }
}
37. What are the possible exceptions that can be thrown by Spring DAO classes?#
DataAccessResourceFailureException
CleanUpFailureDataAccessException
InvalidDataAccessApiUsageException
InvalidDataAccessResourceUsageException
UncategorizedDataAccessException
DataIntegrityViolationException
DeadLockLoserDatAccessException
OptimisticLockingFailureEexception
IncorrectUpdateSemanticsDataAccessException
TypeMismatchDataAccessException
ObjectRetrievalFailureException
DataRetrievalFailureException
38. What are the ways Hibernate can be accessed using Spring?#
Hibernate ORM is an object-relational mapping framework for Java. It is used with Spring to map object-oriented domain models to a relational database.
Hibernate can be accessed in Spring in the following two ways:
- First, extend
HibernateDAOSupport
and then apply an AOP Interceptor node
- Use Inversion of Control with Hibernate Template and Callback structures
39. Point out the difference between concern and cross-cutting concern in Spring AOP?#
A concern is the target functionality we’re trying to implement into a particular module of our application.
A cross-cutting concern is a concern that is used across the entire application rather than just in a particular module.
Data logging is a good example of a cross-cutting concern as logging is useful and desired regardless of what module it is in.
40. What are the types of transaction management available in Spring?#
Declarative transaction management: This type manages transactions using annotations or XML
configurations to separate transaction management from the program’s business code. While easy to maintain, this style is more restricted in its capabilities.
Programmatic transaction management: This type manages transactions with specifically made programs. The customization of these programs allows for more flexible management but introduces more room for error in the process.