• 01spring简介入门


    官方网站
    http://projects.spring.io/spring-framework/

    http://projects.spring.io/spring-framework/


    http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/overview.html#overview-modules
    在中间找到

    jar文件下载 http://repo.spring.io/release/org/springframework/spring


    http://repo.spring.io/release/org/springframework/spring/4.3.9.RELEASE/
    ../
    spring-framework-4.3.9.RELEASE-dist.zip 07-Jun-2017 19:29 65.54 MB
    spring-framework-4.3.9.RELEASE-dist.zip.md5 07-Jun-2017 19:29 32 bytes
    spring-framework-4.3.9.RELEASE-dist.zip.sha1 07-Jun-2017 19:29 40 bytes
    spring-framework-4.3.9.RELEASE-docs.zip 07-Jun-2017 19:29 33.78 MB
    spring-framework-4.3.9.RELEASE-docs.zip.md5 07-Jun-2017 19:29 32 bytes
    spring-framework-4.3.9.RELEASE-docs.zip.sha1 07-Jun-2017 19:29 40 bytes
    spring-framework-4.3.9.RELEASE-schema.zip 07-Jun-2017 19:29 386.28 KB
    spring-framework-4.3.9.RELEASE-schema.zip.md5 07-Jun-2017 19:29 32 bytes
    spring-framework-4.3.9.RELEASE-schema.zip.sha1 07-Jun-2017 19:29 40 bytes


    1、建立maven项目,打开pom.xml文件加入spring容器框架依赖
    <!-- springframework dependency -->
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.3.9.RELEASE</version>
    </dependency>

    2、建立spring容器的配置文件
    src/main/resources/applicationContext.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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">

    <!-- spring容器 默认使用的是单例模式 -->
    <bean id="h" name="/hello" class="com.Hello" scope="singleton" />
    <bean id="d" class="java.util.Date"/>
    </beans>

    3、编写测试代码
    src/test/java/com.Demo.java

    package com;
    import com.fz.Hello;
    import org.junit.Test;
    import org.springframework.beans.factory.BeanFactory;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import java.util.Date;
    /**
    * Created by webrx on 2017-07-01.
    */
    public class Demo {
    @Test
    public void sp(){
    //ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
    BeanFactory factory = new ClassPathXmlApplicationContext("beans.xml");
    Hello h1 = factory.getBean("h",Hello.class);
    Hello h2 = factory.getBean("h",Hello.class);
    Hello h3 = factory.getBean("h",Hello.class);
    Hello h4 = factory.getBean("h",Hello.class);
    System.out.println(h1==h2);
    Date d = factory.getBean("d",Date.class);
    System.out.println(d.toLocaleString());
    }
    }

    怕什么真理无穷,进一步有一步的欢喜
  • 相关阅读:
    Coursera self-driving2, State Estimation and Localization Week2, kalman filter 卡尔曼滤波
    Coursera Self-driving1, introduction
    Coursera, Big Data 5, Graph Analytics for Big Data, Week 5
    初创电商公司Drop的数据湖实践
    什么是LakeHouse?
    Apache Hudi 0.5.1版本重磅发布
    Apache Hudi使用问题汇总(一)
    ApacheHudi常见问题汇总
    写入Apache Hudi数据集
    Hudi基本概念
  • 原文地址:https://www.cnblogs.com/Mkady/p/7201205.html
Copyright © 2020-2023  润新知