zoukankan      html  css  js  c++  java
  • Java 2.Spring的Helloword

    一、创建web项目

    二、引用jar包

    三、引入日志配置文件

    四、创建Java类

    五、创建bean容器

    名字和路径没有特殊要求。

    ApplicationContext.xml 放在src上

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

    六、配置bean对象

            <!-- bean: 是容器创建Person的对象 -->
            <!-- name:相当于变量名person p = new person(); -->
            <!-- class: 类的全限定名 -->
            
            <bean name="p" class="com.Spring.pojo.Person"></bean>
    

     七、测试用例

    package com.Spring.pojo;
    
    import org.junit.Test;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class IOCTest {
    	@SuppressWarnings("resource")
    	@Test
    	public void testCreatePerson() {
    		//创建容器
    		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    		//查找对象
    		Person p=(Person) context.getBean("p");
    		
    		System.out.println(p);
    	}
    
    }
    
  • 相关阅读:
    LOJ
    LOJ
    LOJ
    一种树形背包的时间复杂度证明
    [机器学习]第四、五周记录
    [机器学习]第三周记录
    [家里训练20_02_16]C
    [机器学习]第二周记录
    wireshark无响应的问题
    [机器学习]第一周记录
  • 原文地址:https://www.cnblogs.com/yuzhenfu/p/12144398.html
Copyright © 2011-2022 走看看