concept service layer in category java

appears as: service layer, service layer, The service layer
Spring Roo in Action

This is an excerpt from Manning's book Spring Roo in Action.

  • Services—Provide an abstraction of business functionality, and are usually coarsegrained, performing a task that may interact with a number of objects in the repository layer. Transactional boundaries are usually defined in the service layer.
  • You could code this logic directly in a web-based controller, for simple applications. And Roo actually will do this automatically, using the web scaffolding feature we discuss in chapter 5. But you can also take advantage of your Spring platform and define business methods so that you can expose services to your web and other client tiers in a more organized fashion. Now let’s use that technique to define a service layer in your Roo application.

    AspectJ in Action, Second Edition

    This is an excerpt from Manning's book AspectJ in Action, Second Edition.

    This limitation dictates the architecture utilized. For example, you can’t apply transaction management and security at the domain entities level, because domain entities typically aren’t Spring beans. In practice, this means you need to employ a service layer, expose the service objects as Spring beans, and apply crosscutting at that level. In chapter 16, we’ll examine the use of AspectJ-based crosscutting to overcome this limitation.

    Listing 11.1. Enforcement of layered architecture
    package ajia.architecture; public aspect LayeringViolation { declare error : SystemArchitecture.dataLayerCall() && !SystemArchitecture.inRepositoryLayer() : "Only the repository layer is allowed to access the data layer"; declare error : SystemArchitecture.repositoryLayerCall() && !SystemArchitecture.inRepositoryLayer() && !SystemArchitecture.inServiceLayer() : "Only the service layer is allowed to access the repository layer"; declare error : SystemArchitecture.serviceLayerCall() && !SystemArchitecture.inServiceLayer() && !SystemArchitecture.inWebLayer() : "Only the UI layer is allowed to access the service layer"; declare error : SystemArchitecture.webLayerCall() && !SystemArchitecture.inWebLayer() : "Only the UI layer is allowed to access itself"; }

    As shown in the figure, the authentication system stores an Authentication object inside a SecurityContext. The SecurityContextHolder holds on to one SecurityContext object per scope, which may be a thread-local, an inheritable thread-local, or global. The thread-local scope is the default and most useful in web applications. The authenticated user may then be accessed by other parts of the system. For example, a service layer may access the principal authenticated by the web layer so that it can determine whether the user has appropriate privileges for the invoked services. You’ll use this fact to access the principal from security-related aspects.

    Figure 15.3. Securing the service layer using proxy-based AOP and Spring Security. An aspect consists of a pointcut and an advice. The advice delegates to a support class, which then performs the same task as in figure 15.2.