In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "Java open source framework Spring knowledge points", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Java open source framework Spring knowledge points" bar!
one。 The role of the Spring framework is lightweight: Spring is lightweight, and the basic version size is 2MB control inversion: Spring achieves loose coupling through control inversion, and objects give their dependencies instead of creating or finding dependent objects. Aspect-oriented programming AOP:Spring supports aspect-oriented programming and separates application business logic from system services. Container: Spring contains and manages the life cycle and configuration of objects in the application MVC framework: Spring-MVC transaction management: Spring provides a continuous transaction management interface that can be extended to local transactions down to global transaction JTA exception handling: Spring provides convenient API to specific technology-related exceptions II. The composition of Spring
Spring consists of seven modules:
Spring Core: the core container provides the basic functionality of the Spring framework. The main component of the core container is BeanFactory, which is the implementation of the factory pattern. BeanFactory uses the inversion of Control (IOC) mode to separate the application's configuration and dependency specifications from the actual application code.
Spring context: the Spring context is a configuration file that provides context information to the Spring framework. The Spring context includes enterprise services such as JNDI, EJB, email, internationalization, checksum and scheduling capabilities.
Spring AOP: through the configuration management feature, the Spring AOP module integrates aspect-oriented programming capabilities directly into the Spring framework. Therefore, you can easily make any object managed by the Spring framework support AOP. The Spring AOP module provides transaction management services for objects in Spring-based applications. By using Spring AOP, you can integrate declarative transaction management into your application without relying on EJB components.
The Spring DAO:JDBC DAO abstraction layer provides a meaningful exception hierarchy that can be used to manage exception handling and error messages thrown by different database vendors. The exception hierarchy simplifies error handling and greatly reduces the amount of exception code that needs to be written (such as opening and closing connections). Spring DAO's JDBC-oriented exceptions follow the general DAO exception hierarchy.
The Spring ORM:Spring framework inserts several ORM frameworks, providing object-relational tools for ORM, including JDO, Hibernate, and iBatis SQL Map. All of this follows Spring's generic transaction and DAO exception hierarchy.
Spring Web module: the Web context module is built on top of the application context module, providing context for Web-based applications. Therefore, the Spring framework supports integration with Jakarta Struts. The Web module also simplifies the work of handling multipart requests and binding request parameters to domain objects.
Spring MVC framework: the MVC framework is a full-featured MVC implementation for building Web applications. Through the policy interface, the MVC framework becomes highly configurable, and MVC hosts a number of view technologies, including JSP, Velocity, Tiles, iText, and POI.
three。 Spring containers Sping containers can be divided into two types
1. BeanFactory: (org.springframework.beans.factory.BeanFactory API definition) is the simplest container that provides basic DI support. The most commonly used BeanFactory implementation is the XmlBeanFactory class, which loads beans as defined in the XML file, and the container reads configuration metadata from the XML file and uses it to create a fully configured system or application.
2. ApplicationContext application context: (org.springframework.context.ApplicationContext) builds on top of BeanFactory and provides application-oriented services.
four。 The usual implementation of ApplicationContext
ClassPathXmlApplicationContext: loads the context definition from the XML configuration file under the classpath and treats the application context definition file as a class resource.
FileSystemXmlApplicationContext: reads the XML configuration file under the file system and loads the context definition.
XmlWebApplicationContext: read the XML configuration file under the Web application and load the context definition.
1 ApplicationContext context = new ClassPathXmlApplicationContext ("applicationContext.xml")
five。 IOC & DI
Inversion of Control is generally divided into two types: dependency injection DI (Dependency Injection) and dependency lookup (Dependency Lookup). Dependency injection is widely used.
Spring IOC helps create objects, manage objects (DI), assemble objects, configure objects, and manage the entire lifecycle of those objects.
Advantages: minimize the amount of code applied. Container testing, with minimum cost and minimum intrusiveness, enables loose coupling. The IOC container supports hungry initialization and lazy loading when loading services.
DI dependency injection is an aspect of IOC and is a common concept with many interpretations. This concept means that you don't need to use a bedstead object, but only need to describe how it is created. You don't assemble your components and services directly in the code, but describe which services the components need in the configuration file, and then an IOC container helps assemble them.
The injection mode of IOC: 1. Constructor dependency injection; 2. Setter method injection.
six。 How to provide configuration metadata to a spring container
XML profile
Annotation-based configuration
Java-based configuration @ Configuration, @ Bean
seven。 Attributes in the bean tag:
Id
Name
Class
Methods that will be called immediately after init-method:Bean instantiation
Methods that will be called before destory-method:Bean is removed and destroyed from the container
Factory-method: run we call a specified static method instead of the constructor to create an instance of a class.
The scope of scope:Bean, including singleton (default), prototype (create an instance for each call), request,session, global-session (note that the singleton bean in spring is not thread safe)
Autowired: auto-assembly byName, byType, constructor, autodetect (first explain using constructor auto-assembly, if no Bean matching the constructor is found, Spring will try to use byType auto-assembly)
eight。 Related attributes in the beans tag
Default-init-method
Default-destory-method
Default-autowire: the default is none, which applies to all Bean in the Spring configuration file. Note that this does not refer to the Spring application context, because you can define multiple profiles.
Thank you for reading, these are the contents of "what are the knowledge points of Java open source framework Spring?" after the study of this article, I believe you have a deeper understanding of what the knowledge points of Java open source framework Spring have, 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.