0

I am trying to intercept calls to my Repository.save method. This is basically explained Here and Here. The only problem is it simply doesn't work. I am obviously missing something but after many hours I'm at a loss for what.

I am using Spring 4.1.6 and AspectJ 1.8.5.

Code:

Interesting Annotations from my configuration class:

@Configuration
@EnableWebMvc
@EnableAspectJAutoProxy
@EnableJpaRepositories(
   basePackageClasses=com.xxx.admin.repository.ComponentScan.class)
@ComponentScan(basePackageClasses=      
   {com.xxx.admin.domain.ComponentScan.class
    ,com.xxx.admin.model.ComponentScan.class
    ,com.xxx.admin.service.ComponentScan.class})
@EnableTransactionManagement
@EnableLoadTimeWeaving(aspectjWeaving = EnableLoadTimeWeaving.AspectJWeaving.ENABLED )`

Target Repository:

@Repository
public interface UserRepository extends PagingAndSortingRepository<User, UserId> {

@Transactional(readOnly=true)
Page<User> findAll(Pageable pageable);

@SuppressWarnings("unchecked")
@Transactional
public User save(User user);
}

The Aspect:

@Aspect
public class RepositorySaveAspect {

// Define the JoinPonit
//"org.springframework.data.repository.Repository+.*(..))")
//com.xxx.admin.repository.

//@Pointcut("execution(* com.xxxx.admin.repository.UserRepository.save(..))")
//@Pointcut("execution(* com.xxxx.admin.repository.*Repository+.*(..))")
//@Pointcut("execution(* org.springframework.data.repository.PagingAndSortingRepository+.*(..))")
@Pointcut("execution(public !void org.springframework.data.repository.CrudRepository+.*(..))")
public void repositorySavePoints() {
}

As you can see I tried several different types of Pointcut. But none of them work. I suspect I've missed something to do with proxying. Advice(pun intended) appreciated.

Community
  • 1
  • 1
Terry
  • 911
  • 10
  • 26
  • did you get this resolved, I have a very similar issue right now. – Seamus McMorrow Jun 12 '15 at 11:32
  • I did not. I created a test project with no spring just asprxtJ and a pointcut on the Interface+ works. I'm thinking it has something to do with there being no implementation in the scope of the project, but that's just a guess. And doesn't explain why the linked example claims to work. It may be an actual bug in aspectJ? – Terry Jun 12 '15 at 12:29
  • 1) I don't think you need `@EnableLoadTimeWeaving` in this case (not with current version of spring). 2) Try annotating your `RepositorySaveAspect` with `@Component` 3) The pointcut that works for me is `@Pointcut("execution(* org.springframework.data.repository.*.save(..)) && args(entity)") public void repoSave(Object entity) {}` – Michal Mar 20 '17 at 23:07

0 Answers0