0

Spring AOP 建议不要围绕 hibernate 返回的对象的方法启动。

在我的程序中,休眠返回 CFolder 类型的对象列表。

我想要的是当有人在休眠返回的 CFolder 对象上调用 getName() 方法时,我希望 Spring AOP 编写“在 getName() 之前”和“在 getName() 之后”。

CFolder 代表文件夹

public class CFolder{
    String name;

    public String getName(){
        return name;
    }
}

查找所有 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 
        }
    }
}
4

1 回答 1

0

Spring 将只能代理它控制的 bean(应用 AOP),基本上 AOP 仅适用于ApplicationContext.

如果您想拦截其他对象,您将需要使用 AspectJ 并恢复到加载时间或编译时间编织您的方面。

于 2013-10-02T06:46:22.083 回答