Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the advantages of the transaction support model of the Spring framework

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what are the advantages of the thing support model of the Spring framework". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the advantages of the thing support model of the Spring framework".

Comprehensive transaction support is one of the most compelling reasons for using Spring Framework. The Spring framework provides a consistent abstraction for transaction management and has the following advantages:

A consistent programming model for cross-domain API, such as Java transaction API (JTA), JDBC, Hibernate, Java persistence API (JPA).

Support declarative things.

Simpler programmatic transaction management than complex things API.

Excellent integration with Spring data storage abstraction.

The following sections describe the transactional features and techniques of the Spring framework:

The advantages of the transaction support model of the Spring framework describe why you abstract transactions using the Spring framework instead of EJB container-managed transactions (CMT) or choose to drive local transactions through proprietary API such as Hibernate.

Understanding the Spring framework transaction abstraction provides an overview of core classes and describes how to configure and obtain DataSource instances from various sources.

Synchronizing resources with transactions describes how application code ensures that resources are created, reused, and cleaned up correctly.

Declarative transaction management describes support for declarative transaction management.

Programmatic transaction management covers support for programmatic (that is, explicitly coded) transaction management.

Transaction binding events describe how application events are used in transactions.

This chapter also discusses best practices, application server integration, and solutions to common problems.

1.1 advantages of the transaction support model of the Spring framework

Traditionally, Java EE developers have two choices in transaction management: global or local transactions, both of which have great limitations. The next two sections review global and local transaction management, and then discuss how the transaction management support of the Spring framework addresses the limitations of the global and local transaction models.

1.1.1 Global things

Global transactions allow you to use multiple transaction resources, usually relational databases and message queues. The application server manages global transactions through JTA, while JTA is a tedious API (partly because of its exception model). In addition, you usually need to derive JTA UserTransaction from JNDI, which means you also need to use JNDI to use JTA. The use of global transactions limits any potential reuse of application code because JTA is usually only available in the application server environment.

Previously, the preferred way to use global transactions was through EJB CMT (Container managed transactions). CMT is a form of declarative transaction management (unlike programmatic transaction management). Although you must use JNDI to use EJB itself, EJB CMT eliminates the need for transaction-related JNDI lookups. It eliminates most, but not all, of the need to write Java code to control transactions. The major drawback is that CMT is associated with JTA and the application server environment. Moreover, this feature is available only if you choose to implement business logic in EJB (or at least behind the scenes of a transactional EJB). The shortcomings of EJB are so great that it is not an attractive proposal, especially when faced with a compelling alternative to declarative transaction management.

1.1.2 Local things

Local transactions are resource-specific, such as transactions associated with JDBC connections. Local transactions may be easier to use, but they have one obvious drawback: they cannot work across multiple transaction resources. For example, code that manages transactions using JDBC connections cannot run in a global JTA transaction. Because the application server is not involved in transaction management, it cannot help ensure correctness between multiple resources. It is worth noting that most applications use a single transaction resource. Another disadvantage is that local transactions invade the programming model

1.1.3 consistent programming model of the Spring framework

Spring solves the shortcomings of global and local things. It enables application developers to use a consistent programming model in any environment. You only need to write code once to benefit from different transaction management strategies in different environments. The Spring framework provides declarative and programmatic transaction management. Most users prefer declarative transaction management, which we recommend in most cases.

Programmatic transaction management allows developers to use the Spring framework transaction abstraction, which can be run on any basic transaction infrastructure. Using the preferred declarative model, developers typically write little or no code related to transaction management, so they do not rely on the Spring framework transaction API or any other transactional API.

Do you need an application server for transaction management?

The transaction management support of the Spring framework changes the traditional rules about when enterprise Java applications need an application server.

In particular, you don't need an application server purely for declarative transactions over EJB. In fact, even if your application server has powerful JTA capabilities, you may decide that the declarative transactions of the Spring framework provide more functionality and a more efficient programming model than EJB CMT.

In general, the JTA functionality of the application server is required only if your application needs to handle transactions across multiple resources, which is not necessary for many applications. Many high-end applications use a single highly scalable database (such as Oracle RAC) instead. Stand-alone transaction managers such as Atomikos Transactions and JOTM are other options. Of course, you may need other application server features, such as Java message Service (JMS) and Java EE Connector Architecture (JCA).

The Spring framework allows you to choose when to extend the application to a fully loaded application server. The only option to no longer use EJB CMT or JTA is to write code using local transactions (such as transactions on JDBC connections), and you face a lot of work if you need to run the code in a global, container-managed transaction. With the Spring framework, only some Bean definitions (not the code) in the configuration file need to be changed.

Thank you for your reading, these are the contents of "what are the advantages of the thing support model of the Spring framework". After the study of this article, I believe you have a deeper understanding of the advantages of the thing support model of the Spring framework, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report