2012-04-30 31 views
2

我试图仅使用XML语法来配置spring,并将原生资源异常转换为DataAccessException。根据文档,我总是需要将@Repository放在存储库bean上,并声明PersistenceExceptionTranslationPostProcessor bean。我认为这里应该是定义某种使用AOP的过滤器的方式,它将执行异常转换,但在文档中找不到类似的内容。这个想法是引入约定,例如“对于所有以Dao结尾的应用来说,应用本地例外翻译”。有任何想法吗?@Repository的XML替代方案,用于将DataAccessException的本机异常转换为

+0

将'@Repository'注释应用到dao类而不是服务层bean。对服务层bean使用'@Service' –

+0

我希望使用任何注释来实现相同的WITHOUT,只能使用XML配置。注释工作正常,我只想了解另一种方法,或者确保没有这种方法。在这种情况下,Springs团队声称XML支持的方式与anntations不正确相同。 – alebu

回答

0

到@Repository annotaion的Spring XML配置类似的样子:

<?xml version="1.0" encoding="UTF-8"?> 
    <beans xmlns="http://www.springframework.org/schema/beans" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" 
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> 
... 
     <bean id="translationInterceptor" class="org.springframework.dao.support.PersistenceExceptionTranslationInterceptor" /> 

     <aop:config> 
      <aop:advisor advice-ref="translationInterceptor" pointcut="within(org.example.spring.dao..*Dao)" /> 
     </aop:config> 
... 
    </beans> 

切入点 “内(org.example.spring.dao .. *道)” 适用拦截器在位于包有机类的方法。 example.spring.dao及其子包以“Dao”后缀结尾