Spring AOP is implemented in pure Java. There is no need for a special compilation process. Spring AOP does not need to control the class loader hierarchy, and is thus suitable for use in a Servlet container or application server.
Spring AOP是用纯的java实现的。不需要任何个性的实现过程。Spring AOP不需要控制类加载器,并且它适用于Servlet容器或者应用服务器。
Spring AOP currently supports only method execution join points (advising the execution of methods on Spring beans). Field interception is not implemented, although support for field interception could be added without breaking the core Spring AOP APIs. If you need to advise field access and update join points, consider a language such as AspectJ.
Spring AOP当前只支持方法执行的连接点(通知Spring beans的方法执行)。字段的拦截没有实现,虽然支持字段的拦截,可以在不破坏核心Spring AOP API的情况下添加。如果你需要通知字段获取和根性连接点,可以考虑一种类似AspectJ的语言。
Spring AOP's approach to AOP differs from that of most other AOP frameworks. The aim is not to provide the most complete AOP implementation (although Spring AOP is quite capable); it is rather to provide a close integration between AOP implementation and Spring IoC to help solve common problems in enterprise applications.
用Spring AOP的方式实现AOP不同于大多数其他的AOP框架。它的目标不是提供一种最完整的AOP实现(虽然Spring AOP已经非常的强大);它更倾向于在AOP实现和Spring IoC之间提供一种封闭的整合,从而帮补解决企业应用中的哪些通用的问题。
Thus, for example, the Spring Framework's AOP functionality is normally used in conjunction with the Spring IoC container. Aspects are configured using normal bean definition syntax (although this allows powerful "autoproxying" capabilities): this is a crucial difference from other AOP implementations. There are some things you cannot do easily or efficiently with Spring AOP, such as advise very fine-grained objects (such as domain objects typically): AspectJ is the best choice in such cases. However, our experience is that Spring AOP provides an excellent solution to most problems in enterprise Java applications that are amenable to AOP.
例如,Spring框架的AOP功能通常与Spring Ioc容器结合使用。Aspects使用通用的bean 定义的语法来配置(虽然它允许强大的自动代理的方式):与其他的AOP实现相比,这是一个很重要的不同点。有些事情如果你不使用Spring AOP,将很难或者不能高效的去做,例如通知细粒度的对象(如典型的业务对象):而在这种情况下AspectJ是最好的选择。然而,我们的经验是,Spring AOP为企业级Java应用中大多数问题提供了一个优秀的解决方案,这些问题在AOP中很容易控制。
Spring AOP will never strive to compete with AspectJ to provide a comprehensive AOP solution. We believe that both proxy-based frameworks like Spring AOP and full-blown frameworks such as AspectJ are valuable, and that they are complementary, rather than in competition. Spring 2.0 seamlessly integrates Spring AOP and IoC with AspectJ, to enable all uses of AOP to be catered for within a consistent Spring-based application architecture. This integration does not affect the Spring AOP API or the AOP Alliance API: Spring AOP remains backward-compatible. See the following chapter for a discussion of the Spring AOP APIs.
Spring AOP从来没有为与AspectJ竞争提供一个综合的AOP而纠结。我们相信这样两种基于代理的框架如Spring AOP和成熟的AspectJ都是有存在价值的,并且他们是相互补充的,而不是相互竞争的关系。Spring 2.0将Spring AOP和IoC与AspectJ无缝整合,从而是AOP的全部使用在一系列的基于Spring的应用框架中适应能力更强。这个整合没有影响到Spring AOP的API或者AOP Alliance API:Spring AOP保持着向后兼容。
One of the central tenets of the Spring Framework is that of non-invasiveness; this is the idea that you should not be forced to introduce framework-specific classes and interfaces into your business/domain model. However, in some places the Spring Framework does give you the option to introduce Spring Framework-specific dependencies into your codebase: the rationale in giving you such options is because in certain scenarios it might be just plain easier to read or code some specific piece of functionality in such a way. The Spring Framework (almost) always offers you the choice though: you have the freedom to make an informed decision as to which option best suits your particular use case or scenario.
One such choice that is relevant to this chapter is that of which AOP framework (and which AOP style) to choose. You have the choice of AspectJ and/or Spring AOP, and you also have the choice of either the @AspectJ annotation-style approach or the Spring XML configuration-style approach. The fact that this chapter chooses to introduce the @AspectJ-style approach first should not be taken as an indication that the Spring team favors the @AspectJ annotation-style approach over the Spring XML configuration-style.
See Section 9.4, “Choosing which AOP declaration style to use” for a more complete discussion of the whys and wherefores of each style.
Spring框架的一个核心原则就是非侵入性;这就是说你不会被强制引入框架的个性类和接口到你自己的业务领域模型。然而在Spring框架的一些地方给了你引入Spring框架特性的依赖到你的代码中:给你这些东西的原因是,在一些特定的场景,以这种方式编码可能更加的可读性.Spring框架大多数情况下给你一些选择,这样你就可以自由的做一个合理的决定,用来适应一些特定的情况和场景。
你需要选择使用AspectJ还是Spring AOP或者二者都用,而且你也要选择使用@AspectJ注解方式或者Spring Xml配置风格的方式。事实上本章节选择使用@AspectJ注解,首先要避免被认为是一种@AspectJ注解优于Spring Xml配置风格的暗示。