zoukankan      html  css  js  c++  java
  • 1、Spring Framework入门

    • 该程序使用工具为IDEA,Eclipse配置同理
    • 该程序是一个Maven程序,通过Maven导包

    步骤:

    1. 导入相关jar包
    2. 创建spring上下文配置
    3. 测试

    导包

    ​ 通过该图了解到spring的核心容器是通过Beans、Core、Context以及SpEl 这四个组件构成的

    只需添加spring-context依赖

    <!-- 容器包-->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.0.0.RELEASE</version>
    </dependency>
    

    就会添加相关的jar

    创建项目

    直接点击next即可;

    输入GroupId(组名)→ ArtifactId(项目名)→ 一路点击next即可;

    配置

    创建配置spring配置文件(注意是在resources目录下创建)

    resources代表项目的类路径(ClassPath)

    创建效果如下:

    测试

    添加junit依赖

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
    

    创建测试类

    public class iocTest {
        /**
         * 通过类路径下的spring配置文件获取ioc对象
         * ClassPathXmlApplicationContext就是从类路径下获取xml文件的应用上下文
         * 当前配置文件直接放置于类路径下(resources目录)直接传入配置文件名即可
         */
        ApplicationContext ioc = new ClassPathXmlApplicationContext("ioc.xml");
        /**
         * 打印ioc对象
         */
        @Test
        public void test01(){
            System.out.println(ioc.getId());
        }
    }
    

    测试结果没有报错,则说明容器对象ioc创建成功

  • 相关阅读:
    The type new View.OnClickListener(){} must implement the inherited abstract method View.Onclicklis
    vue开发环境跨域
    浅析deep深度选择器
    模块化
    highlight-current-row无效的解决方法
    element-ui的table 在页面缩放时,出现的问题
    css变量
    节流和防抖
    promise详解
    正则表达式详解
  • 原文地址:https://www.cnblogs.com/Ryuichi/p/13246898.html
Copyright © 2011-2022 走看看