zoukankan      html  css  js  c++  java
  • Hello spring

    步骤:导入相关jar包(记得选中jar包,右键build path)   

          commons-logging-1.2.jar
          spring-aop-4.1.6.RELEASE.jar
          spring-aspects-4.1.6.RELEASE.jar
          spring-beans-4.1.6.RELEASE.jar
          spring-context-4.1.6.RELEASE.jar
          spring-context-support-4.1.6.RELEASE.jar
          spring-core-4.1.6.RELEASE.jar
          spring-expression-4.1.6.RELEASE.jar
          spring-instrument-4.1.6.RELEASE.jar
          spring-jdbc-4.1.6.RELEASE.jar
          spring-orm-4.1.6.RELEASE.jar
          spring-test-4.1.6.RELEASE.jar
          spring-tx-4.1.6.RELEASE.jar
          spring-web-4.1.6.RELEASE.jar
          spring-webmvc-4.1.6.RELEASE.jar

             编写spring配置文件(名称可以自定义)

    (废话少说-----:)

    Hello.java

    package com.yikuan.cn;

    public class Hello {
    private String name;
    public void setName(String name) {
    this.name = name;
    }
    public void show(){
    System.out.println("hello,"+name);
    }
    }

    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.xsd">
    <!-- bean就是java对象,由spring容器来创建和管理 -->
    <bean name="hello" class="com.yikuan.cn.Hello">
    <property name="name" value="张三"/>
    </bean>
    </beans>

    Test1.java

    package com.yikuan.cn.test;

    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;

    import com.yikuan.cn.Hello;

    public class Test1 {
    public static void main(String[] args) {
    //解析beans.xml文件,生成管理相应的bean对象
    ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
    Hello hello = (Hello) context.getBean("hello");
    hello.show();
    }
    }

  • 相关阅读:
    237. Delete Node in a Linked List
    430. Flatten a Multilevel Doubly Linked List
    707. Design Linked List
    83. Remove Duplicates from Sorted List
    160. Intersection of Two Linked Lists
    426. Convert Binary Search Tree to Sorted Doubly Linked List
    142. Linked List Cycle II
    类之间的关系
    初始化块
    明确类和对象
  • 原文地址:https://www.cnblogs.com/yikuan-919/p/9501469.html
Copyright © 2011-2022 走看看