Spring understanding

Brief introduction

  • Decouple code, enterprise-class development of the complexity of the problem: the degree of coupling
  • System sub-codes:
    • Main business logic
      • Bank business
      • Insurance Business
      • ...
    • System level business logic, cross traffic
      • eg.JDBC
        1. Load the driver
        2. Create a connection
        3. Open affairs
        4. SQL operations
        5. Commit the transaction
        6. Connection release
  • Glue framework
  • Layered Java SE / EE full-stack (stop) a lightweight open source framework

Spring will be decoupled divided into two categories:

  • IoC - Inversion of Control

    Objects to be used by the Spring container unified management
    eg.UserService userService = new UserServiceImpl (); ----> Spring to be done

  • AOP - Aspect Oriented Programming

    System-level services to maximize reuse

Sprint architecture

Data Access/Integration

  • Spring JDBC lightweight implementation
  • ORM - Object Relational Mapping
    • MyBatis
    • Hibernate
  • OXM
  • ETC.
  • Transactions

Web

  • WebSocket
  • Servlet
  • Web
  • Splicing components - Portlet

AOP

Core Container

  • Beans
  • Core
  • Context
  • Game

Test

Feature

  • Non-invasive
    • API Spring Framework will not appear on the business logic

Spring and IoC

  • Dependency Injection
  • Between Spring's Bean to profile the way organizations together
  • pojo - native Java objects
  • Bean

[Gymnastics] hello-Spring

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.funtl</groupId>
    <artifactId>hello-spring</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.3.17.RELEASE</version>
        </dependency>
    </dependencies>
</project>

Example hardcoded

Spring configuration file

  • Profiles resources / srping-context.xml - 依赖注入
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="userService" class="com.funtl.hello.spring.service.impl.UserServiceImpl" />
</beans>
  • Get the Spring configuration MyTest.java - 控制反转
public class MyTest {
    public static void main(String[] args) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-context.xml");
        UserService userService = (UserService) applicationContext.getBean("userService");
        userService.sayHi();
    }
}

Guess you like

Origin www.cnblogs.com/hhhqqq/p/12582852.html