Spring Study Notes (1) Concept and Configuration

1. Framework
what is a frame
Usually refers to the specification of software components to implement an industry standard or complete a specific basic task.
It also refers to a software product that provides the basic functions required by the specification in order to realize a software component specification.
Features of the frame
  1. semi-finished product
  2. Encapsulates specific processing flow and control logic
  3. Mature, continuously upgraded and improved software
Why use frames
  1. Software systems are becoming more complex
  2. High reusability, high development efficiency and quality
  3. Software designers should focus and understand the domain to make requirements analysis clearer
  4. Easy to get started, quick problem solving
2. Interface
  1. Abstraction of mediators for communication
  2. An abstract description that an entity provides itself to the outside world to separate external communication methods for internal operations so that it can modify internal
  3. without affecting the way other entities in the outside world interact with it
  4. The corresponding Java interface is a declaration, which declares which methods are publicly available.
  5. In Java 8, interfaces can have method bodies
Interface-oriented programming:
  1. In the structural design, the hierarchical calling relationship is distinguished, each layer only provides a set of interfaces to the outer layer, and each layer depends on the interface rather than the implementation class.
  2. Changes in interface implementation do not affect calls between layers, which is especially important in public services
  3. Interfaces in "Interface-Oriented Programming" are components used to hide concrete implementations and implement polymorphism
3. Spring
1.1 IOC Inversion of Control
The idea is to reverse the direction of resource acquisition.
After IOC is applied, the container actively pushes resources to the components it manages, and all the components have to do is choose an appropriate method to receive resources. This behavior is also known as the passive form of lookup
1.2 DI dependency injection
Another representation of IOC: that is, components are represented in some predefined ways (such as: setter methods)
Accept resource injection from the container
1.3 AOP Aspect-Oriented Programming
Issues specifically designed to deal with the cross-cutting concerns of the various modules in the system
1.4 Environment Construction (refer to http://www.jikexueyuan.com/course/675.html )
Spring official website: https://spring.io/projects
Click on Spring Framework and select the corresponding version of Reference
选择2.3里面的红框位置,进入下载列表,选择相应版本后,点击第一个进行下载。下载后名称如:spring-framework-4.3.7.RELEASE-dist
新建工程,导入JAR包。
   Spring 模块

 

 

1.5 环境检测
新建一个HelloWorld类
package com.lbh.spring.beans;
 
public class HelloWorld {
private String name;
 
public String getName() {
return name;
}
 
public void setName(String name) {
this.name = name;
System.out.println("setName="+name);
}
public void name() {
System.out.println("hello:"+name);
}
public HelloWorld() {
System.out.println("HelloWorld constructor...");
}
}
 
新建一个applicationContext.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-4.3.xsd">
 
  <!-- 配置bean -->
  <bean id="helloworld" class="com.lbh.spring.beans.HelloWorld">
  <property name="name" value="111"></property>
  </bean>
</beans>
新建main方法进行输出测试
package com.lbh.spring.beans;
 
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
 
public class Main {
 
/**
* @param args
*/
public static void main(String[] args) {
// HelloWorld helloworld = new HelloWorld();
// helloworld.setName("lbh");
// helloworld.name();
//1.注册配置文件2.获取bean 3.调用bean方法
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
HelloWorld helloworld = (HelloWorld) ctx.getBean("helloworld");
helloworld.name();
}
 
}
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326488808&siteId=291194637