<context:annotation-config/>
<context:component-scan...
这用于我需要用 @Repository @Service @Component 注释的类...
<context:spring-configured />
<context:component-scan...
如果我需要使用@Configurable则使用
<tx:annotation-driven transaction-manager="transactionManager" />
<context:component-scan...
如果我需要 @Transactional 就使用,除此之外我还需要在 xml 中添加哪些其他元数据才能使用事务管理?
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
需要在xml中添加这个吗?出于什么目的?
最佳答案
<tx:annotation-driven transaction-manager="transactionManager" />
为了使用事务管理,您还需要声明要使用的transactionManager。该声明取决于您用来访问数据的方法。例如,对于普通 JDBC,您可以编写:
<bean id = "transactionManager" class = "org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name = "dataSource" ref = "dataSource" />
</bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
此声明用于处理 JPA 数据访问配置的 @PersistenceContext 和 @PersistenceUnit 注释。然而,对此注释的支持也包含在 <context:annotation-config />
中。 ,因此如果您使用 <context:annotation-config />
则不需要显式声明它.
关于java - 了解spring xml注释元数据吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1961251/