zoukankan      html  css  js  c++  java
  • springframework3.2.0环境搭建

    spring环境搭建:

    1. 引入libs文件夹中的jar包(可不引入javadoc和sources)
    2. 创建一个HelloWorld类
      package com.gcflowers.spring.model;
      public class HelloWorld {
          public String sayHello(){
              return "HelloWorld";
          }
      }
    3. 在src目录下创建beans.xml(beans可为其他)此xml文件为spring的主要文件包含了需要管理的对象,其中定义的bean相当于使用new关键字创建的对象
      此文件相当于把类交给了spring来统一管理
      <?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="com.gcflowers.spring.model.HelloWorld"/>
             
      </beans>
    4. 写一个单元测试类TestWorld
      package com.gcflowers.spring.test;

      import org.junit.Test;
      import org.springframework.beans.factory.BeanFactory;
      import org.springframework.context.support.ClassPathXmlApplicationContext;

      import com.gcflowers.spring.model.HelloWorld;


      public class Testspring {
          //根据配置文件beans.xml生成一个BeanFactory的对象,默认是在src目录下查找
          private BeanFactory factory = new ClassPathXmlApplicationContext("beans.xml");
          
          @Test
          public void testHelloWorld(){
              //factory根据id来new一个对象
              HelloWorld hello = factory.getBean("helloWorld",HelloWorld.class);
              System.out.println(hello.sayHello());
          }
      }
    5. 运行junit可以看到控制台输出Hello World。
  • 相关阅读:
    BasKet Note Pads 1.0 颁发
    为OpenOffice 2.4装置3D幻化结果
    Dolphin:KDE 中的文件操持器
    MySQL Administrator:MySQL 数据库经督工具
    gISOMount-ISO 映像文件挂载东西
    Seahorse:让加密更等闲
    Gmail Notifier:又一个 Gmail 邮件通知步调
    EasyTAG-音频文件 Tag 编辑器
    KAlarm:看护提示挨次
    文泉驿点阵宋体 0.8(嬴政)正式发布
  • 原文地址:https://www.cnblogs.com/charleszhang1988/p/3045849.html
Copyright © 2011-2022 走看看