Cross-cutting concerns

Cross-cutting concerns are concerns that are typically common to multiple layers of an application--logging, security, and transaction management, among others. Let's quickly discuss some of these:

  • Logging: Audit logging at multiple layers can be implemented using Aspect-Oriented Programming (Spring AOP or AspectJ).
  • Security: Security is typically implemented using the Spring Security framework. As discussed in the previous chapter, Spring Security makes the implementation of security very simple.
  • Transaction management: Spring Framework provides a consistent abstraction for transaction management. More importantly, Spring Framework provides great support for declarative transaction management. The following are some of the transaction APIs that the Spring Framework supports:
    • The Java Transaction API (JTA) is a standard for transaction management. It is a part of Java EE's specifications.
    • JDBC.
    • JPA (including Hibernate).
  • Error handling: Most abstractions provided by Spring use unchecked exceptions so unless required by business logic, it is sufficient to implement error handling in the layer that is exposed to the client (user or other application). Spring MVC provides Controller Advice to implement consistent error handling across the application.

The Spring Framework plays a major role in application architecture. Spring IoC is used to wire beans from different layers together. Spring AOP is used to weave cross-cutting concerns around the beans. Added to these is the fact that Spring provides great integration with frameworks in different layers.

In the next section, we will quickly review some of the important problems Spring has solved in the last decade or so.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset