zoukankan      html  css  js  c++  java
  • Eclipse IDE下的Spring框架使用简单实例

    Eclipse IDE下的Spring框架使用简单实例


    1 准备
    Java jdk安装。

    Eclipse软件安装。
    根据系统安装32/64版本,选择Eclipse IDE for Java Developers 进行在线安装。

    Spring框架下载。 

    Commons_Logging包下载

    2 配置工作
    在项目栏右键,Build Path->Config Build Path 选择Librarys -> Add External Jars导入Spring 与Commons_Logging的jar包

    3 示例程序
    在src文件夹下创建com.manongjc包,在包中分别创建HelloWorld类与MainApp类,代码如下:

    //HelloWorld类
    package com.manongjc;

    public class HelloWorld {
       private String message;

       public void setMessage(String message){
          this.message  = message;
       }

       public void getMessage(){
          System.out.println("Your Message : " + message);
       }
    }

    //MainApp类
    package com.manongjc;

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

    public class MainApp {
       public static void main(String[] args) {
          ApplicationContext context =
                 new ClassPathXmlApplicationContext("Beans.xml");

          HelloWorld obj = (HelloWorld) context.getBean("helloWorld");

          obj.getMessage();
       }
    }

    在src文件夹下创建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-3.0.xsd">

    <bean id="helloWorld" class="com.manongjc.HelloWorld">
    <property name="message" value="Hello World!"/>
    </bean>

    </beans>

    选中MainApp,点击运行,可以在Console里看到输出的日志。

  • 相关阅读:
    磁盘IO工作机制
    java 的IO类库的基本架构
    诡异的NPE--三目运算自动类型转换
    WIN2008服务器不能复制粘贴怎么办
    用nrm一键切换npm源
    Linux常用命令大全(非常全!!!)
    整理 node-sass 安装失败的原因及解决办法
    win10完美去除小箭头
    JS中slice,splice,split的区别
    Win10环境下Redis和Redis desktop manager 安装
  • 原文地址:https://www.cnblogs.com/mingzhang/p/7615593.html
Copyright © 2011-2022 走看看