简体   繁体   English

在Java应用程序中创建的代理中有多少使用Spring核心,Hibernate,Spring AOP?

[英]How many proxies created in Java application use Spring core, Hibernate, Spring AOP?

I'm reading about Java proxy and as we know Spring Core, Hibernate, Spring AOP, Ehcache is an implement of it. 我正在阅读有关Java代理的信息,我们知道Spring Core,Hibernate,Spring AOP,Ehcache是​​它的实现。 I have got confused cause SpringCore will create a proxy, Hibernate will create a proxy and SpringAOP or Ehcache will do the same if we use all of them in a Java project. 我很困惑,因为SpringCore将创建一个代理,Hibernate将创建一个代理,如果我们在Java项目中使用所有它们,SpringAOP或Ehcache将执行相同的操作。

How many proxies will create? 将创建多少个代理? Can someone help me out this problem and give me some example? 有人可以帮我解决这个问题并举一些例子吗?

Each of those frameworks create any variable number of proxies all based upon certain design choices and configurations. 这些框架中的每一个都基于特定的设计选择和配置创建任意数量的代理。 That said, the only way to have any idea would be to profile your application. 就是说,唯一有想法的方法就是分析您的应用程序。

Most frameworks that use proxies leverage them for similar reasons. 大多数使用代理的框架出于类似原因也利用它们。 These proxies are meant to act as placeholders that look like an object our code knows about and works with; 这些代理旨在充当占位符,看起来就像我们的代码了解并使用的对象; however the internal implementation details are hidden, often supplemented with framework specific business logic. 但是,内部实现细节是隐藏的,通常会补充特定于框架的业务逻辑。

For example, hibernate may expose a lazily-loaded collection of objects as a collection of proxies. 例如,休眠可能会将延迟加载的对象集合公开为代理集合。 Each proxy looks like the object our application expects in that collection; 每个代理看起来像我们的应用程序在该集合中期望的对象; however, the internal state of that proxy is often not yet loaded until first accessed. 但是,该代理的内部状态通常要等到首次访问后才加载。 In this case, the proxy saves on memory consumption, result-set parsing and database bandwidth, and a plethora of other things. 在这种情况下,代理节省了内存消耗,结果集解析和数据库带宽,以及许多其他事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM