原文链接地址是: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. Linux基础三:用户和组

    三.用户和组 1.概念 (1).用户概念: 用户是用来运行某一些进程.拥有某一些文件或目录. 在Linux里面,用户分成三大类:root用户.系统用户.普通用户. 用户是用UID来唯一标识身份的,且r ...

  2. Django笔记&教程 0-2 框架版本与相关工具

    Django 自学笔记兼学习教程第0章第2节-- 框架版本与相关工具 点击查看教程总目录 1 版本 python: 3.6.5 Django: 2.2.11 (有些地方我也会对比下各种版本的区别) 安 ...

  3. Python 常见运算符表达式

    常见运算符表达式    1.算数运算符    2.逻辑运算符    3.比较运算符    4.成员运算符    5.位运算符    6.身份运算符a.赋值运算符 =    格式:变量= 表达式     ...

  4. [hdu7026]Might and Magic

    (以下默认$A_{0},D_{0},P_{0},K_{0}$都为非负整数) 显然存活轮数$S=\lceil\frac{H_{0}}{C_{p}\max(A_{1}-D_{0},1)}\rceil$​​ ...

  5. [bzoj5508]甲苯先生的字符串

    首先定义状态f[i][j]表示长度为i的串以j为结尾有多少符合条件的串,发现$f[i][j]=\sum f[i-1][k]$(j和k可以相邻),这个用矩阵乘法优化一下即可. 1 #include< ...

  6. mybatis-参数如何测试

    mybatis参数非常多测试的时候定位bug一直是个问题,如果老用大部分时间来定位一个错误的参数,太浪费时间了...

  7. 最难忘的一次bug:谢谢实习时候爱学习的自己

    前言 时间的车轮一直向前不停,试图在时光洪流中碾碎一些久远的记忆.虽然记忆中的人离我越来越远,但是故事却越来越深刻. 当在博客园看到这次的正文题目是"最难忘的bug",脑海里瞬间浮 ...

  8. Codeforces 708E - Student's Camp(前缀和优化 dp)

    Codeforces 题目传送门 & 洛谷题目传送门 神仙 *3100,%%% 首先容易注意到 \(\forall i\in[1,m]\),第 \(i\) 行剩余的砖块一定构成一个区间,设其为 ...

  9. Topcoder 14719 - RatingProgressAward(最小割)

    题面传送门 神仙最小割--好久没写过网络流了,故写题解以祭之( 首先考虑一个非常 trivial 的问题:如果知道排列顺序之后怎样计算最大值,用脚趾头想一下就能知道是原序列的最大子段和,因为每个课程之 ...

  10. char *p、char p[]、字符串的几个题目

    总结一下遇到的关于char *p.char p[]和字符串的题目: 例一:(指针的指针) 1 void getmemory(char **p) 2 { 3 p = (char *)malloc(100 ...