Question

Spring AOP advises are NOT kicking off around methods of objects returned by hibernate.

In my program, hibernate is returning list of objects of type CFolder.

What I want is when somebody calls getName() method on CFolder objects returned by the hibernate, I want Spring AOP to write "Before getName()" and "After getName()".

CFolder that represents folder

public class CFolder{
    String name;

    public String getName(){
        return name;
    }
}

Repository class that finds all the CFolders

@Service
@Repository
public class MyService implements MyServiceIfc<TypeTemplateMasterRepository> {

    @Autowired
    private CFolderRepository cfolderRepository;

    @Override
    @Transactional(readOnly=true)
    public void findAll(Class classz) throws Exception {

        List allFolders = cfolderRepository.findAll(); //Use hibernate to find all folders..
        for(int i=0; i < allFolders.size(); i++){
            CFolder cFolder = (CFolder) allFolders.get(i);
            System.out.println("The folder name is" + cFolder.getName()); //When 
        }
    }
}
Was it helpful?

Solution

Spring will only be able to proxy beans (apply AOP) which it controls, basically AOP will only work for beans inside the ApplicationContext.

If you want other objects intercepted you will need to use AspectJ and revert to either loadtime or compile time weaving of your aspects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top