原文链接地址是:http://www.cnitblog.com/gavinkin555/articles/35973.html

1 新建一个项目

File----->New ----->Project  在出现的对话框中选择 MyEclipse 下的 Web Project,在Project Name 输入mySpring1,其他的选项默认,再点Finish完成;

2 加入Spring 包

在myspring1 项目上点右键,选MyEclipse ---> Add Spring Capabities,再点Finish完成;

3 加入Log4j 包

菜单--->Project -->Properties-----Java Build Path 点Libraries 选项卡,再选Add External Jars 加入log4j 的jar 包 (可从网上下)http://archive.apache.org/dist/logging/log4j/1.2.8/

4 新建Action接口文件

右键点src ---->New ---->Interface (包名net.xiaxin.spring.qs)

Action.java代码

package net.xiaxin.spring.qs;

public interface Action {
 public String execute(String str);

}
5 建立Action接口的两个实现UpperAction、LowerAction

LowerAction.java

package net.xiaxin.spring.qs;

public class LowerAction implements Action { 
  
   private String message; 
   public String getMessage() { 
     return message; 
    } 
   
    public void setMessage(String string) { 
      message = string; 
    } 
    
    public String execute(String str) { 
     return (getMessage()+str).toLowerCase(); 
    } 
  }

/////
UpperAction.java

package net.xiaxin.spring.qs;

public class UpperAction implements Action { 
   
   private String message; 
   
   public String getMessage() { 
    return message; 
   } 
  
   public void setMessage(String string) { 
     message = string; 
   } 
  
   public String execute(String str) { 
    return (getMessage() + str).toUpperCase(); 
   } 
 }

6  新建log4j.properties配置文件,内容如下:

log4j.rootLogger=DEBUG, stdout 
 
log4j.appender.stdout=org.apache.log4j.ConsoleAppender 
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 
log4j.appender.stdout.layout.ConversionPattern=%c{1} - %m%n

7  Spring配置文件(bean.xml)

在myspring 上右击 --->New--->File  文件名 bean.xml

bean.xml 内容如下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans> 
     <description>Spring Quick Start</description> 
     <bean id="TheAction" 
 class="net.xiaxin.spring.qs.UpperAction">
    <property name="message"> 
<value>HeLLo</value> 
</property> 
  </bean>  
 <bean id="action2" class="net.xiaxin.spring.qs.LowerAction">
<property name="message"> 
<value>HeLLo</value> 
</property> 
  </bean> 
</beans>

8  建立测试文件SimpleTest.java

package test;

import net.xiaxin.spring.qs.Action;

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

public class SimpleTest {
 public static void main(String args[])
 {
  SimpleTest test=new SimpleTest();
  test.testQuickStart();
  
 }
 public void testQuickStart() { 
   
     ApplicationContext ctx=new  FileSystemXmlApplicationContext("bean.xml"); 
     
     Action action = (Action) ctx.getBean("TheAction"); 
     
     System.out.println(action.execute("Rod Johnson"));
     action = (Action) ctx.getBean("action2");
     System.out.println(action.execute("jecKj"));
  
  }

}

9 把SimpleTeat.java 设置成主类就可以运行了,运行结果 (红色部分是想要的结果)

FileSystemXmlApplicationContext - Publishing event in context [org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=12694833]: org.springframework.context.event.ContextRefreshedEvent[source=org.springframework.context.support.FileSystemXmlApplicationContext: display name [org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=12694833]; startup date [Wed May 31 13:30:25 CST 2006]; root of context hierarchy]
 DefaultListableBeanFactory - Returning cached instance of singleton bean 'TheAction'
 HELLOROD JOHNSON
DefaultListableBeanFactory - Returning cached instance of singleton bean 'action2'
 hellojeckj

用Myclipse开发Spring(转)的更多相关文章

  1. 1 IDEA 安装 及 IDEA开发 spring的环境搭建

    摘要: 主要讲解使用 IDEA 开发 Spring MVC 的环境搭建,Maven的简单教学. 参考1:https://my.oschina.net/gaussik/blog/385697 参考2:h ...

  2. 在maven中开发Spring需要的jar依赖

    在maven中开发Spring需要的jar依赖 <properties> <spring.version>4.0.6.RELEASE</spring.version> ...

  3. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建四:配置springmvc

    在用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建三:配置spring并测试的基础上 继续进行springmvc的配置 一:配置完善web.xml文件

  4. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建三:配置spring并测试

    这一部分的主要目的是 配置spring-service.xml  也就是配置spring  并测试service层 是否配置成功 用IntelliJ IDEA 开发Spring+SpringMVC+M ...

  5. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建二:配置MyBatis 并测试(2 配置spring-dao和测试)

    用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建二:配置MyBatis 并测试(1 搭建目录环境和依赖) 四:在\resources\spring 下面 ...

  6. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建二:配置MyBatis 并测试(1 构建目录环境和依赖)

    引言:在用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建一   的基础上 继续进行项目搭建 该部分的主要目的是测通MyBatis 及Spring-dao ...

  7. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建一:建立MAVEN Web项目

    一:创建maven web项目er

  8. 开发Spring过程中几个常见异常(三):java.lang.ClassCastException: com.sun.proxy.$Proxy4 cannot be cast to com.edu.aop.ArithmeticCalculatorImpl at com.edu.aop.Main.main(Main.java:11)

    这个异常是在开发Spring案例时遇到的. 贴一下完整异常信息: Exception in thread "main" java.lang.ClassCastException: ...

  9. 开发Spring Shell应用程序

    2 开发Spring Shell应用程序 向shell提供命令非常简单,需要学习的注解很少.该命令的实现风格与使用依赖注入的应用程序的开发类相同,您可以利用Spring容器的所有特性来实现您的命令类. ...

随机推荐

  1. split,cdn,shell脚本,tmux,记一次往国外服务器传大文件的经历

    需求是这样的:将一个大概680M的Matlab数据文件传到国外某所大学的服务器上,服务器需要连接VPN才能访问,由于数据文件太大,而且如果我直接ssh连过去或者用ftp传输,那么中间很可能中断. ps ...

  2. Linux常用命令和快捷键整理:(2)常用快捷键

    前言: Linux常用快捷键和基本命令整理,先上思维导图: linux常用命令请见:https://www.cnblogs.com/yinzuopu/p/15516499.html 基本快捷键的使用 ...

  3. Fiddler抓包工具学习及使用

    一.Fiddler工作原理 Fiddler是位于客户端和服务器端之间的代理,客户端发送请求,fiddler会拦截该请求,再转发到服务器端,服务器端处理请求做出的响应,也要被fiddler拦截,fidd ...

  4. 一文了解cookie

    @ 目录 什么是Cookie? Cookie 的作用 Cookie原理 Cookie的分类 会话 Cookies 永久性 Cookies Cookie 的属性 name value Domain Pa ...

  5. js 实现匀速移动

    js 实现匀速移动 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  6. 如何系统学习C 语言(下)之 文件篇

    我们所编写的程序源代码以及编译生成的可执行文件都属于文件.所以文件的实质就是存储在外部存储介质上的一段连续的二进制数据. c 语言程序对文件的处理采用文件流的形式,程序运行在内存中,而文件是存储在外部 ...

  7. 单线程 Redis 为什么这么快,看看这篇就知道了

    Redis 作为一种 KV 缓存服务器,有着极高的性能,相对于 Memcache,Redis 支持更多种数据类型,因此在业界应用广泛. 记得刚毕业那会参加面试,面试官会问我 Redis 为什么快,由于 ...

  8. 用户案例 | 腾讯小视频&转码平台云原生容器化之路

    作者 李汇波,腾讯业务运维高级工程师,目前就职于TEG 云架构平台部 技术运营与质量中心,现负责微信.QQ社交类业务的视频转码运维. 摘要 随着短视频兴起和快速发展,对于视频转码处理的需求也越来越多. ...

  9. MySQL语法练习一

    DESC t_dept ALTER TABLE t_dept ADD descri VARCHAR(20) ALTER TABLE t_dept ADD decribe VARCHAR(20) FIR ...

  10. 【Rancher相关问题】Rancher 2.5.8 及以下版本,提示Alert: Component controller-manager,scheduler is unhealthy.

    问题描述 如图,Rancher2.5.8版本提示 controller-manager,scheduler 不健康,管理的k8s集群版本1.21.1 解决方法 在Master节点执行如下命令: sed ...