What are the seven main modules of the spring framework?

Source: Internet
Author: User

The spring Framework's seven modules 1. Spring Core:

The core package is the most fundamental part of the framework, providing IOC and dependency injection characteristics. The basic concept here is beanfactory, which provides a classic implementation of the factory pattern to eliminate the need for procedural singleton patterns and really allows you to isolate dependencies and configurations from the program logic.

2.Spring Context:

The context wrapper package, built on the core package, provides a framework for object access, some like the Jndi registrar. The context wrapper package is characterized by the beans package and adds support for internationalization (i18n), event propagation, the way resources are loaded, and the transparent creation of the context, such as through a servlet container.

3. Spring DAO:

DAO (Data Access Object) provides the abstraction layer of JDBC, which eliminates lengthy jdbc encoding and resolves database vendor-specific error codes. Also, the JDBC package provides a better declarative transaction management approach than programmatic, not only for specific interfaces, but also for all pojos (plain old Java objects).

4.Spring ORM:

The ORM package provides an integrated layer of commonly used "object/relationship" mapping APIs. These include JPA, JDO, Hibernate, and IBatis. With the ORM package, you can mix the "object/relationship" mappings with all of the spring-provided features, such as the simple declarative transaction management mentioned earlier.

5.Spring AOP:

Spring's AOP package provides an aspect-oriented programming implementation that conforms to the AOP Alliance specification, allowing you to define, for example, method interceptors (method-interceptors) and Pointcuts (pointcuts), to logically weaken the functional coupling of the Code, Clear to be separated away. Also, with the Source-level metadata feature, you can incorporate various behavioral information into your code.

6.Spring Web:

The Web package in spring provides the underlying integration features for web development, such as multi-party file uploads, and the use of servlet listeners for IOC container initialization and web-based applicationcontext. When using spring with webwork or struts, this package enables spring to be combined with other frameworks.

7.Spring Web MVC:

The MVC encapsulation package in spring provides a model-view-controller (MVC) Implementation of the Web application. The spring MVC Framework does not simply provide a traditional implementation, it provides a clear separation model between the domain model code and the Web form. Also, other features of the spring framework can be used.

What are the three core ideas in the spring framework

DI (Dependency injection), IOC (inversion of Control), AOP (plane-oriented programming)

The IOC concept and how the IOC operates in the spring container.
Ioc:inversion of control, inversion of controls. In Java development, IOC means handing out your designed classes to the system 这里写代码片 , rather than controlling them within your class, called control inversion, where instances of the called class are created and destroyed by the original invocation class control and now transformed into a container managed by spring.

How the Spring container manages the bean's life cycle (such as the Bean's initialization method, the Bean's destruction method)
Create:

<property name=”userDao” ref=”被引用bean的名称” /><property name=”username” value = “字符串”/>
There are several ways to get a connection pool in the spring framework.

When Jndi and DBCP exist at the same time, the problem will not occur, if not at the same time, please explain why
Four different ways, as follows:

1:DBCP Data source

The DBCP class package is located in/LIB/JAKARTA-COMMONS/COMMONS-DBCP.JAR,DBCP is a database connection pool that relies on the Jakarta Commons-pool object pooling mechanism, so you must also include/lib/under the Classpath Jakarta-commons/commons-pool.jar. The following is a configuration fragment that uses DBCP to configure an Oracle data source:

<bean id= "dataSource"class=" Org.apache.commons.dbcp.BasicDataSource " destroy-method=" Close ">< property name= "driverclassname"value="  Oracle.jdbc.driver.OracleDriver "/>< property name="url" value="Jdbc:oracle:thin: @localhost : 1521:orcl "/>< property name="username" value="root" />< property name="password" value="1234″ /></Bean>
2:C3P0 Data source

C3P0 is an open source JDBC data source implementation project that is published in the Lib directory with Hibernate and implements the connection and statement pools for JDBC3 and JDBC2 extension specification descriptions. The C3p0 class package is located in/lib/c3p0/c3p0-0.9.0.4.jar. Here is an Oracle data source configured using C3P0:

<bean id= "dataSource" class=" Com.mchange.v2.c3p0.ComboPooledDataSource " destroy-method=" Close ">< property name= "driverclassname"value="  Oracle.jdbc.driver.OracleDriver "/>< property name="url" value="Jdbc:oracle:thin: @localhost : 1521:orcl "/>< property name="username" value="root" />< property name="password" value="1234″ /></Bean>
3. Spring's data source implementation class (Drivermanagerdatasource)

Spring itself also provides a simple data source implementation class Drivermanagerdatasource, which is located in the Org.springframework.jdbc.datasource package. This class implements the Javax.sql.DataSource interface, but it does not provide a mechanism for pooling connections, and it simply creates a new connection each time a call to getconnection () gets a new connection. Therefore, this data source class is better suited for use in unit testing or simple standalone applications because it does not require additional dependency classes.

<bean id= "dataSource" class=" Org.springframework.jdbc.datasource.DriverManagerDataSource " destroy-method=" Close "> < property name= "driverclassname"value="  Oracle.jdbc.driver.OracleDriver "/>< property name="url" value="Jdbc:oracle:thin: @localhost: 1521:ORCL "/>< property name="username" value="root" />< property name="password" value="1234″ /></Bean>
4. Get the Jndi data source

If the application is configured on a high-performance application server, such as WebLogic or WebSphere, we may prefer to use the data source provided by the application server itself. The data source for the application server is used by Jndi open callers, and spring specifically provides the Jndiobjectfactorybean class that references the Jndi resource. The following is a simple configuration:

<bean id=”dataSource”class=”org.springframework.jndi.JndiObjectFactoryBean”><property name=”jndiName” value=”java:comp/env/jdbc/oracle”/></bean>

Specifies the referenced Jndi data source name by Jndiname.

What objects must be injected into the template when using spring's jdbctemplate to manipulate the data, and the template should not manually close the database connection
Injecting DataSource data source objects

Do not manually close the database connection, JdbcTemplate will help us close the database connection

JdbcTemplate's queryForList method gets the list collection, which is why each object in the list collection is of the data type, and how the El expression is used in the JSP page.
Each object is a JAVA.UTIL.MAP type of data, the EL expression is used to take a value

What are the benefits of the concept of AOP and the use of AOP mechanisms? There are several ways to implement AOP in Java programming
The concept of AOP is aspected oriented programming aspect programming.

Benefit: AOP breaks the program down into various aspects or concerns. This makes it possible to modularize, quite horizontally on the slitting. It solves crosscutting (crosscut) issues such as transactions, security, logging, and other crosscutting concerns that are not well addressed by OOP and procedural methods.

There are several ways to implement AOP:
    1. In Spring 1.2, AOP is implemented through Proxyfactorybean, which is achieved through dynamic proxies, aspect must inherit Methodbeforeadvice,methodafteradvice, etc.

    2. Spring 2.0 AOP needs to be changed to the FBI class, and it does not need to implement some interfaces

    3. Three using annotations (@AspectJ) to implement AOP

There are several transaction processing in the spring framework. Please explain the difference between the two separately
The transaction management that spring provides can be divided into two categories: programmatic and declarative.

Programming, more flexible, but the code is large, there are more duplicate code;

Declarative is more flexible than programmatic.

What is the total interface for a programmatic transaction? What are the core class objects of spring transactions that need to be used with programmatic transactions
Total interface

Platformtransactionmanager interface,

Core class:

//事务属性定义//代表了当前的事务,可以提交,回滚。PlatformTransactionManager核心接口的子类

Spring's declarative transactions can generate proxy interfaces for ordinary classes, can you use Try/catch in your code to catch exceptions, and if not, explain why
No. Spring's declarative transactions generate proxies for the implementation class. You cannot use Try/catch in your code, because exceptions are caught in the code, and the spring container cannot catch exceptions.

When using Transactionproxyfactorybean to generate transactional physics for a bean, the settings for which property values are required:

<bean name=”baseTransactionProxy”class=”org.springframework.transaction.interceptor.TransactionProxyFactoryBean”>
⑴<!– The transaction manager into the transaction agent Bean –>< property name="TransactionManager" ref="TransactionManager" ></Property >⑵<!– set transaction Properties –>< property name="Transactionattributes"><props>⑶<!– All methods adopt required 's transaction strategy -><prop key="*">Propagation_required</prop></props></Property >⑷<!– set the target bean for the transaction agent Bean –>< property name="target" ref="Userdao"></Property ></Bean>⑸<!– target Bean –><Beanname="Userdao" class="Com.dao.userDao">    < property name="DataSource" ref="DataSource" /></Property ></Bean>

What are the seven main modules of the spring framework?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.