ioc;控制反转
aop:面向切面编程
1---------------spring包名------------
---------------spring包名-------------
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
--------------------------------------------------------------------
2------------ Beans.xml配置头文件(包含自动注解)------------
---------------- Beans.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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 注解支持-->
<context:component-scan base-package=""/>自动扫描托管类与 @Component 对用应---以xml文件配置spring
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");//以xml配置时候new
<context:annotation-config/>允许自动注解<!-- 注解支持-->
</beans>
-----------------------------------------------------------------------
3-------------部分注解--------------------
-------------部分注解--------------------
1.@Configuration
//这是一个配置类用来以java代码作为spring配置文件使用
2. ApplicationContext context = new AnnotationConfigApplicationContext(anno.class);
//以java配置时候new
3.@Component
组件 //说明Component被spring托管的组件
衍生出:
dao【@Reposit】
service【@Service】
controller【@Controller】
//三个功能一样
4. @ComponentScan("")
// java配置中使用;对比 <context:component-scan base-package=""/>自动扫描托管类与 5.@Component
//对用应------以xml文件配置spring
6. @import(...class)
//导入java配置文件
7. @Autowired
// 自动导入类 //自动装配依赖通过类型。
-如果@Autowired不能自动装配唯一,需要@Qualifier(value="")
8. @Nullable
//字段标记了这个注解,说明这个字段可以为null
9. @Resoure
//自动装配通过名字。类型
10. @Value("")
//注入值
11.@Scope("")
//值有prototype和single。。多例和单例实现