Spring

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>


在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值