zoukankan      html  css  js  c++  java
  • idea spring helloworld

    由于近期在学习JAVA的一些基础知识,发现出现只停留在一些简单的方法上的感觉。今天特定向下一个目标spring学习一下。今天自学了一下idea下学习spring的helloworld开始。

    1:下载common-logging JAR包

      http://mirrors.shu.edu.cn/apache/commons/logging/binaries/   

           下载并解压丢到 D:/java/common-logging/lib目录下

    2:新建demo项目

      step1:选择spring框架

           step2:选择项目地址

          

           step3:下载spring框架相应版本lib

          

    3:导入common-logging库

      

    4:编码

      step1 :在src目录下新建一个package   cc.freshair

           step2:在src/cc.freshair目录下建立两个类(HelloWorld.php   ,MainApp.java)

       HelloWorld.java

    package cc.freshair;
    
    /**
     * 描述:
     * <p>
     * Author: dxh20012012001@sina.com
     * Created: 2018/5/20
     * Version: V1.0
     */
    public class HelloWorld {
        private String name;
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public void sayHello() {
            System.out.println("Hello World");
        }
    }

    MainApp.java

    package cc.freshair;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    /**
     * 描述:
     * <p>
     * Author: dxh20012012001@sina.com
     * Created: 2018/5/20
     * Version: V1.0
     */
    public class MainApp {
        public static void main(String[] args) {
            ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-config.xml");
            HelloWorld helloWorld = (HelloWorld) applicationContext.getBean("HelloWorld");
            helloWorld.sayHello();
            System.out.println(helloWorld.getName());
        }
    }

           step3:修改src/spring-config.xml文件添加一个bean映射   

    <?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 id="HelloWorld" class="cc.freshair.HelloWorld">
    <property name="name" value="Spring"></property>
    </bean>

    </beans>

      step4:整体结构

           5:运行

           参考来源:

         极客学院(HelloWorld)   http://wiki.jikexueyuan.com/project/spring/hello-world-example.html

  • 相关阅读:
    DIV 设置垂直居中
    JavaScript--什么是函数
    JavaScript--引用JS外部文件
    JavaScript--如何插入JS
    CSS-类和ID选择器的区别
    CSS-ID选择器
    CSS类选择器
    CSS样式介绍
    HTML--使用mailto在网页中链接Email地址
    HTML--form表单中的label标签
  • 原文地址:https://www.cnblogs.com/amuge/p/9064547.html
Copyright © 2011-2022 走看看