2017-10-10 103 views
0

我有两个项目,一个是真正的项目,第二个是一个示范项目尝试Javers框架具有类似的设置和类似的环境。在演示项目中,Javers的审计线索运行良好,但是在实际项目中实施后,Javers无法工作。Javers:@annotation(org.javers.spring.annotation.JaversAuditable)在一些项目不工作

我已经调查的过程中好几天,发现这个假设 “Javers在实际项目中无法检测到切入点(更精确地检测不到标注)”:

@AfterReturning("@annotation(org.javers.spring.annotation.JaversAuditable)")(在JaversAuditableAspect)

因为当我创建一个具有相同切入点简单的方面:

@AfterReturning("execution(* com.xxx.StatusRepository.*(..))") 

的方面是执行,而当我试着打@annotation(org.javers.spring.annotation.Ja versAuditable)与另一切入点(@Before,@After,@AfterThrowing和@Around)没有一个切入点被击中。

是否有任何其他线索或选项,这样我可以试试吗?

这里是我的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:context="http://www.springframework.org/schema/context" 
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
    "> 

    <tx:annotation-driven/> 

    <import resource="classpath:META-INF/spring/mbp-infra.xml" /> 
    <import resource="classpath:META-INF/spring/mbp-util.xml" /> 
    <import resource="classpath*:META-INF/spring/**/*-codelist.xml" /> 

    <context:component-scan base-package="com.nttdata.mbp.domain" /> 

    <!-- AOP. --> 
    <bean id="resultMessagesLoggingInterceptor" 
     class="org.terasoluna.gfw.common.exception.ResultMessagesLoggingInterceptor"> 
      <property name="exceptionLogger" ref="exceptionLogger" /> 
    </bean> 
    <aop:config proxy-target-class="true"> 
     <aop:advisor advice-ref="resultMessagesLoggingInterceptor" 
        pointcut="@within(org.springframework.stereotype.Service)" /> 
    </aop:config> 

    <aop:aspectj-autoproxy/> 

    <!-- check that the aop is running --> 
    <bean id = "myAspect" class = "com.nttdata.mbp.domain.util.AOPTest" /> 

</beans> 

这里是我的依赖关系:

<!-- == Javers == --> 
<dependency> 
    <groupId>org.javers</groupId> 
    <artifactId>javers-core</artifactId> 
    <version>3.5.1</version> 
</dependency> 

<dependency> 
    <groupId>org.javers</groupId> 
    <artifactId>javers-spring</artifactId> 
    <version>3.5.1</version> 
</dependency> 

<dependency> 
    <groupId>org.javers</groupId> 
    <artifactId>javers-persistence-jdbc</artifactId> 
    <version>1.0.3</version>  
</dependency> 

<dependency> 
    <groupId>org.javers</groupId> 
    <artifactId>javers-persistence-sql</artifactId> 
    <version>3.5.1</version> 
</dependency> 

<dependency> 
    <groupId>org.polyjdbc</groupId> 
    <artifactId>polyjdbc</artifactId> 
    <version>0.6.4</version> 
</dependency> 
<!-- == End Javers == --> 

===更新===

这里是我的javers bean配置

@Configuration 
public class AuditContext { 

    @Bean 
    public Javers javers() { 
     JaversRepository javersRepository = SqlRepositoryBuilder 
              .sqlRepository() 
              .withConnectionProvider(getConnectionProvider()) 
              .withDialect(DialectName.MYSQL).build(); 
     return JaversBuilder.javers() 
       .registerJaversRepository(javersRepository) 
       .build(); 
    } 

    @Bean 
    public ConnectionProvider getConnectionProvider() { 
     return new AuditConnectionProvider(); 
    } 

    @Bean 
    public AuthorProvider getAuthorProvider() { 
     return new SpringSecurityAuthorProvider(); 
    } 

    @Bean 
    public CommitPropertiesProvider getCommitPropertiesProvider() { 
     return new CommitPropertiesProvider() { 
      @Override 
      public Map<String, String> provide() { 
       return ImmutableMap.of("key", "ok"); 
      } 
     }; 
    } 

    @Bean 
    public JaversAuditableAspect javersAuditableAspect() { 
     return new JaversAuditableAspect(javers(),getAuthorProvider(),getCommitPropertiesProvider()); 
    } 

    @Bean 
    public JaversSpringDataAuditableRepositoryAspect javersSpringDataAuditableAspect() { 
     return new JaversSpringDataAuditableRepositoryAspect(javers(),getAuthorProvider(),getCommitPropertiesProvider()); 
    } 
} 

回答

0

https://javers.org/documentation/spring-integration/ 描述所有你需要做的就是通过声明这个bean,使JaVers'方面:

@Bean 
public JaversAuditableAspect javersAuditableAspect() { 
    return new JaversAuditableAspect(javers(), authorProvider(), commitPropertiesProvider()); 
} 

并启用@AspectJ支持。

Spring配置的完整例子可以在这里找到https://javers.org/documentation/spring-integration/#spring-jpa-example (我们没有在XML中的例子,我建议升级到Java配置)

+0

对不起,我不提它,我已经更新了我的文章与配置类,我也检查了注释'System.out.println(target.getClass()。getMethod(“insert”,Case.class).isAnnotationPresent(JaversAuditable.class));'和结果是真实的,但它仍然没有工作,我不知道了。 – Richant

+0

几天后,我和我的朋友在寻找这个问题,今天上午,他来到办公室,终于找到了原因。这是因为我们团队中的某个人将spring-mvc.xml文件中的组件扫描从''>更改为'',只是丢失了“.app”这个词。我们不关注这个文件,因为一切正常,我们也没有“.app”包。直到这个简单的不同导致问题@annotation切入点(感谢Javers,我们从它那里得到一个新的教训)。 – Richant

相关问题