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程序

  • 相关阅读:
    vim 命令替换重复命令
    Python环境安装
    MySQL 查看show profile
    XSS攻击与CSRF攻击与防御
    HTTPS的原理
    PHP curl的请求步骤
    【论文阅读】HRNet
    【学习笔记】gRPC-python
    【Linux学习笔记】Linux基础
    【Golang学习笔记】入门:结构体、方法与接口
  • 原文地址:https://www.cnblogs.com/jeremy-blog/p/4023743.html
Copyright © 2011-2022 走看看