IOC
IOC的体现
Spring实现步骤
1.创建maven项目
2.加入maven依赖
3.创建类(接口和他的实现类)
和没有使用框架一样,就是普通的类。
4.创建Spring需要使用的配置文件
声明类的信息,这些类由spring创建和管理
5.测试Spring创建的。
Spring的依赖
org.springframework spring-context 5.3.9 # Spring的bean创建 ![在这里插入图片描述](https://img-blog.csdnimg.cn/9608e4318fec4e238de8c1cbe2b383b6.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hnN2IxMTY=,size_16,color_FFFFFF,t_70) # 使用Spring容器创建对象 ![在这里插入图片描述](https://img-blog.csdnimg.cn/4b10492c8a0442aca6a1cd84b712c4c8.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hnN2IxMTY=,size_16,color_FFFFFF,t_70) # Beans文件中查看对象数量和对象名称的方法 ![在这里插入图片描述](https://img-blog.csdnimg.cn/565de8931a614b418ceebea569bc5a1f.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hnN2IxMTY=,size_16,color_FFFFFF,t_70) # Set注入 ![在这里插入图片描述](https://img-blog.csdnimg.cn/56608b5a9ece41c9b3627a1320c384b0.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hnN2IxMTY=,size_16,color_FFFFFF,t_70) # 自动注入 byname ![在这里插入图片描述](https://img-blog.csdnimg.cn/d5dd72b4f71c40ca81a4a2d952d0e892.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hnN2IxMTY=,size_16,color_FFFFFF,t_70) # 自动注入 bytype ![在这里插入图片描述](https://img-blog.csdnimg.cn/a62910b95fed4c118dc15571a5439fe7.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hnN2IxMTY=,size_16,color_FFFFFF,t_70) # 主配置文件 ![在这里插入图片描述](https://img-blog.csdnimg.cn/ce0c6e8bd12a4a2ca6013a26ff7edc06.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hnN2IxMTY=,size_16,color_FFFFFF,t_70)注解
声明组件扫描器
Component
与Component功能相似的注解
注解Autowired
注解@Resource
AOP
切面编程的理解
AOP的注解
声明自动代理生成器
JoinPoint
后置通知
环绕通知
spring+mybatis
pom文件配置
<?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>org.example</groupId>
<artifactId>spring-mybatis</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.9</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>5.3.9</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.3.9</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.12</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.yml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.yml</include>
<include>**/*.vm</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
</project>
applictaionContext.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"
xmlns:p="http://www.springframework.org/schema/p"
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:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>-->
<bean class="com.alibaba.druid.pool.DruidDataSource" id="myDataSource">
<property name="url" value="jdbc:mysql://localhost:3306/bjpowernode"></property>
<property name="username" value="root"></property>
<property name="password" value="1234"></property>
</bean>
<bean id="sqlSessionFatory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="configLocation" value="classpath:mybatis.xml"/>
</bean>
</beans>