The first spring project

Disclaimer: This article is a blogger original article, reproduced, please attach Bowen link! https://blog.csdn.net/f2764052703/article/details/90311881

What is the spring

Spring framework is due to the complexity of software development created. Spring is the basic JavaBean used to do things previously only be done by EJB. However, Spring is not limited to the use of server-side development. The vast majority of Java applications can benefit from the simplicity, testability and loose coupling from the perspective of Spring.

◆ Objective: To address the complexity of enterprise application development

◆ function: instead of using the basic JavaBean EJB, and provides more enterprise applications

◆ Range: Any Java application

Spring is a lightweight inversion of control (IOC) and the facing section (AOP) of the container frame.

Spring mind:

  1. JAVA EE development should be more simple.
  2. Use interface rather than class, it is better programming practice. Spring uses the interface complexity is reduced to almost zero.
  3. It provides a better framework for the application configuration JavaBean.
  4. More emphasis on object-oriented design, rather than existing technologies such as JAVA EE.
  5. Minimize unnecessary abnormal capture.
  6. Make the application easier to test.

Spring goals:

  1. Easy pleasant to use Spring.
  2. Application code does not rely on Spring APIs.
  3. Spring does not compete with existing solutions, but works to merge them.

Spring basic components:

  1. The most complete lightweight core framework.
  2. General management abstraction layer affairs.
  3. JDBC abstraction layer.
  4. Integrated Toplink, Hibernate, JDO, and iBATIS SQL Maps.
  5. AOP functionality.
  6. Flexible MVC Web application framework.

spring framework Baidu Encyclopedia

The first project to build a spring

  1. Using the idea to create a Maven project
  2. Importing spring foundation jar package in the project
    <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
      <scope>provided</scope>
    </dependency>
    
    <!--spring-corejar:spring的核心jar包-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>5.1.6.RELEASE</version>
    </dependency>
    
    <!--spring-context:spring上下文所依赖的jar-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>5.1.6.RELEASE</version>
    </dependency>
    
    <!--spring-beans:spring处理bean所依赖的jar-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>5.1.6.RELEASE</version>
    </dependency>
    
    <!--spring-expression:spring表达式所依赖的jar-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-expression</artifactId>
      <version>5.1.6.RELEASE</version>
    </dependency>
    
    <!--spring-aop:spring开发aop所依赖的jar包-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aop</artifactId>
      <version>5.1.6.RELEASE</version>
    </dependency>
    
    <!--日志-->
    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.1.1</version>
    </dependency>
    
  3. Create a spring configuration file to manage the spring of bean
    <?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 class="scope.bean1" id="bean1"></bean>
    
    </beans>
    
  4. Use ApplicationContextget xml configuration
    	ApplicationContext app = new ClassPathXmlApplicationContext("scope/spring.xml");
        bean1 b = (bean1) app.getBean("bean1");
        b.see();
    

Guess you like

Origin blog.csdn.net/f2764052703/article/details/90311881