zoukankan      html  css  js  c++  java
  • Spring学习笔记 1. 尚硅谷_佟刚_Spring_HelloWorld

    1,准备工作

    (1)安装spring插件

            搜索https://spring.io/tools/sts/all就可以下载最新的版本

    image

          下载之后不用解压,使用Eclipse进行安装。在菜单栏最右面的Help菜单:

          image

         点击Install New Software之后,有如下界面,按次序点击找到刚才下载的安装包之后确认。

    image

           确认之后到下面这个界面之后,注意只需要选择其中的某些选项就可以了。

    image

        下面一路安装,之后重启就可以,可以看看是否安装成功,如下表示成功。

        image      

    (2)下载jar包。

           spring-framework-4.2.4.RELEASE-dist  下载地址:http://repo.spring.io/release/org/springframework/spring/

           commons-logging-1.1.1  网上自行下载。

    2,开始HelloWorld的小程序

    (1)新建项目,添加一个lib文件,把刚才下载的包中的下面这些包拷贝进去,全选jar包,右键Build Path ---〉Add to Build Path

          image

    (2)新建下面3个文件:HelloWorld.java; Main.java ;applicationContext.xml

          image

    HelloWorld.java 代码:

    package com.yfy;
    public class HelloWorld {
        private String name;    
        public void setName(String name) {
            this.name = name;
        }
        public void hello(){
            System.out.println("hello: " + name);
        }
    }

    Main.java 代码:

    package com.yfy;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    public class Main {
        public static void main(String[] args) {
            ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
            HelloWorld helloWorld =(HelloWorld) applicationContext.getBean("helloWorld");
            helloWorld.hello();
        }
    
    }

    applicationContext.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.xsd">
        <!-- 配置bean -->
        <bean id="helloWorld" class="com.yfy.HelloWorld">
            <property name="name" value="spring"></property>
        </bean>
    </beans>

    运行Main.java

    image

    下面就详细分析一下:

    image

    注:以上学习笔记参考: 尚硅谷_佟刚_Spring_HelloWorld第一课,佟刚老师讲的不错,慢慢学习。

  • 相关阅读:
    仿苹果原生头部动画
    cookie VS sessionstorge VS localstorge
    require实现单页应用程序(SPA)
    物体position:absolute后设置left:50%发生的有趣小事
    C/JS_实现选择排序
    C/JS_实现冒泡排序
    C_求质数
    C/JS_二分法查找
    JS_高程6.面向对象的程序设计(2)创建对象_3 构造函数存在的问题
    CSS_常见布局
  • 原文地址:https://www.cnblogs.com/yefengyu/p/5094427.html
Copyright © 2011-2022 走看看