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.