首页 > 其他分享 >Spring 概述-入门案列

Spring 概述-入门案列

时间:2022-12-06 15:15:05浏览次数:70  
标签:入门 Spring jar 案列 add userTest AOP

Spring 概述-入门案列

介绍

  • Spring 是轻量级的开源的 JavaEE 框架

  • Spring 可以解决企业应用开发的复杂性

  • Spring 有两个核心部分:IOCAOP
    (1)IOC:控制反转,把创建对象过程交给 Spring 进行管理

    (2)AOP:面向切面,不修改源代码进行功能增强

  • Spring 特点
    (1)方便解耦,简化开发

    (2)AOP 编程支持

    (3)方便程序测试

    (4)方便和其他框架进行整合(MyBatis、Hibernate)

    (5)方便进行事务操作

    (6)降低 API 开发难度(对 JDBC 做了封装)

Spring5 入门案例

下载 Spring5

下载地址

https://repo.spring.io/ui/native/release/org/springframework/spring/

需要的 jar 包

maven 仓库地址

https://mvnrepository.com/


下载 commons-logging.jar

创建 java 项目

将下载好的 jar 包引入项目中

编写测试类

/**
 * @author zjh
 */
public class UserTest {

    public void add(){
        System.out.println("Add...");
    }
}

编写配置文件

<?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">

    <!--配置 User 对象创建-->
    <bean id="userTest" class="com.zjh.spring.UserTest"/>
</beans>

利用获取bean的方式测试add方法

/**
 * 测试通过bean 获取 add方法
 */
@Test
public void testAdd() {
    // 加载 spring 配置文件
    ApplicationContext context =
            new ClassPathXmlApplicationContext("bean.xml");

    // 获取配置创建的对象
    UserTest userTest = context.getBean("userTest", UserTest.class);
    System.out.println(userTest);
    userTest.add();
}

结果

标签:入门,Spring,jar,案列,add,userTest,AOP
From: https://www.cnblogs.com/zjh0420/p/16951656.html

相关文章

  • Springboot优雅进行字段检验
    Springboot优雅进行字段检验1、ControllerVSService推荐与业务无关的放在controller层中进行校验,而与业务相关的放在service层中校验。2、常用校验工具类使用Hiberna......
  • springboot2 搭建日志收集系统存入mongodb + redis+mq+线程池+xxljobs
    我们看到了高效批量插入mongodb速度还不错,那么我们的系统日志收集怎么做呢。当然当前文件日志收集效果也不错,比如前面博文写的elkf搭建日志收集系统。但我们系统中总是有......
  • 二叉树入门到进阶(下一篇讲红黑树)——c语言刷题合集
    目录二叉树概念二叉树的遍历方式DFS(前序中序后序遍历)144.二叉树的前序遍历递归解法迭代解法94.二叉树的中序遍历145.二叉树的后序遍历层序遍历--队列的作用102.二叉......
  • C语言学习入门 (八) 结构体和枚举
    结构体它允许内部的元素是不同类型的结构体的定义//结构体类型:struct{charintfloat};//定义一个结构体变量,定义变量时才分配存储空间structPersonstructchar *name;int}......
  • springboot2 mongodb 高效批量入库--环境搭建
    当今使用微服务越来越多,每个服务都需要记录日志,那么记录到mysql中已完全不合适了。那么就记录到mongo中吧。想要速度快,那么一定要使用批量保存,做过尝试入库10万数据,逐条插......
  • C语言学习入门 (二) 语句和运算符
    C语言的基本语句跟Java中的差不多循环语句(dowhile、while、for)条件语句(if 、if-else、switch)goto语句 (比如在循环外定义一个标记Exit:; 在循环内可以用gotoExit;......
  • Spring用XML方式使用事务
    项目开始前需要新建数据库(数据库使用mysql8.0以上的版本)#创建数据库CREATEdatabaseuserdb;#创建数据表CREATETABLEuserdb.t_account(idintNOTNULL,usernamev......
  • SpringBoot整合Netty+WebSocket
    SpringBoot整合Netty+WebSocket构建环境pom.xml<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w......
  • 钉钉小程序与企业微信小程序快速入门
    最近开发了一款关于钉钉小程序与企业微信小程序企业办公工具,api跟微信小程序差不多,但应用载体不同,或多或少有些异同,由于临时学习开发,简单记录一下:钉钉小程序快速入门: ......
  • SpringBoot 接口并发限制(Semaphore)
    可以使用JMeter辅助测试https://blog.csdn.net/weixin_45014379/article/details/124190381@RestController@RequestMapping({"/Test"})publicclasstest{L......