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里看到输出的日志。

  • 相关阅读:
    postgres 如何把多行数据,合并一行,返回json字符串
    linux 安装中文字体(生成图片中文乱码解决)
    postgis 自相交数据检测 修复
    C# Winform程序如何获取运行路径, 控制台也可以
    Excel: Access is denied
    change the theme in VS2005 or VS2008
    接下来的一点计划
    wordwrap, breakword
    T SQL + 正则表达式
    神奇的Css + DIV,滚动的Grid
  • 原文地址:https://www.cnblogs.com/mingzhang/p/7615593.html
Copyright © 2011-2022 走看看