zoukankan      html  css  js  c++  java
  • Spring-helloWorld

    Spring的helloWorld程序
    1配置Spring的开发环境,只需要把下面几个包添加到lib文件夹下面即可:

    2编写Bean类,并为其属性提供setter方法,

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

    3添加在src目录下新建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">
    
    
    </beans>

    4在ApplicationContext.xml文件里配置我们写好的Bean类

        
        <bean id="helloWorld" class="com.jeremy.spring.beans.HelloWorld"> 
        <property name="name" value="Spring"></property>
        
        </bean>
        

    5测试

    @Test
        public void testMain(){
            //1获取ApplicationContext(IOC)容器
            ApplicationContext applicationContext=new ClassPathXmlApplicationContext("ApplicationContext.xml");
            
            //2从ApplicationContext容器里获取Bean实例
            HelloWorld helloWorld=(HelloWorld) applicationContext.getBean("helloWorld");
            
            //3利用获取到的Bean实例调用Bean的方法
            helloWorld.helloworld();
        }

    以上就是Spring的HelloWold程序

  • 相关阅读:
    android一些细节问题
    Android Suspend/resume 过程分析.
    在NDK上建立自己的项目
    ListView加载特效
    Android Log Analysis转
    Android系统默认设置
    一步步分析Log
    Android Framework 分析
    编译安装MariaDB10.0.21
    mariadb多源复制 muiltil source replication
  • 原文地址:https://www.cnblogs.com/jeremy-blog/p/4023743.html
Copyright © 2011-2022 走看看