views:

132

answers:

2
<context:annotation-config/>
 <context:component-scan...

this is used for class that i need to annotated with @Repository @Service @Component...

    <context:spring-configured />
<context:component-scan...

use if i need to use @Configurable

    <tx:annotation-driven transaction-manager="transactionManager" />
<context:component-scan...

use if i need @Transactional , beside this what other metadata do I need to add in xml in order to use transaction management?

<bean
        class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

what is the need to add this in xml ? for what purpose?

+3  A: 
<tx:annotation-driven transaction-manager="transactionManager" />

In order to use transaction management you also need to declare a transactionManager to use. That declaration depends on the approach you use to access the data. For example, for plain JDBC you write:

<bean id = "transactionManager" class = "org.springframework.jdbc.datasource.DataSourceTransactionManager">
 <property name = "dataSource" ref = "dataSource" />
</bean>


<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

This declaration is used to handle @PersistenceContext and @PersistenceUnit annotations for JPA data access configuration. Hovewer, support for this annotations also included in <context:annotation-config />, so you don't need to declare it explicitly if you use <context:annotation-config />.

axtavt
+1  A: 

From spring javadoc

BeanPostProcessor that processes PersistenceUnit and PersistenceContext annotations, for injection of the corresponding JPA resources EntityManagerFactory and EntityManager. Any such annotated fields or methods in any Spring-managed object will automatically be injected.
This post-processor will inject sub-interfaces of EntityManagerFactory and EntityManager if the annotated fields or methods are declared as such. The actual type will be verified early, with the exception of a shared ("transactional") EntityManager reference, where type mismatches might be detected as late as on the first actual invocation.
Bozho