用Myclipse开发Spring(转)
原文链接地址是: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 IDEA 安装 及 IDEA开发 spring的环境搭建
摘要: 主要讲解使用 IDEA 开发 Spring MVC 的环境搭建,Maven的简单教学. 参考1:https://my.oschina.net/gaussik/blog/385697 参考2:h ...
- 在maven中开发Spring需要的jar依赖
在maven中开发Spring需要的jar依赖 <properties> <spring.version>4.0.6.RELEASE</spring.version> ...
- 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建四:配置springmvc
在用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建三:配置spring并测试的基础上 继续进行springmvc的配置 一:配置完善web.xml文件
- 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建三:配置spring并测试
这一部分的主要目的是 配置spring-service.xml 也就是配置spring 并测试service层 是否配置成功 用IntelliJ IDEA 开发Spring+SpringMVC+M ...
- 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建二:配置MyBatis 并测试(2 配置spring-dao和测试)
用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建二:配置MyBatis 并测试(1 搭建目录环境和依赖) 四:在\resources\spring 下面 ...
- 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建二:配置MyBatis 并测试(1 构建目录环境和依赖)
引言:在用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建一 的基础上 继续进行项目搭建 该部分的主要目的是测通MyBatis 及Spring-dao ...
- 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建一:建立MAVEN Web项目
一:创建maven web项目er
- 开发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: ...
- 开发Spring Shell应用程序
2 开发Spring Shell应用程序 向shell提供命令非常简单,需要学习的注解很少.该命令的实现风格与使用依赖注入的应用程序的开发类相同,您可以利用Spring容器的所有特性来实现您的命令类. ...
随机推荐
- SimpleNVR流媒体服务系统录像功能解析
录像的回放与观看是许多人在使用视频监控时必不可少的需求.人不可能每时每刻都观看视频,而录像能对摄像机的视频信息进行存储,方便用户的后期回放查看,因此,SimpleNVR的录像功能应运而生. ...
- 子查询之 exists 和 in
exists exists用于检查一个子查询是否至少会返回一行数据(即检测行的存在),返回值为boolean型,true或false 语法 exists subquery /* 参数: subquer ...
- dart系列之:dart语言中的特殊操作符
dart系列之:dart语言中的特殊操作符 目录 简介 普通操作符 类型测试操作符 条件运算符 级联符号 类中的自定义操作符 总结 简介 有运算就有操作符,dart中除了普通的算术运算的操作符之外,还 ...
- 关于Python中用户输入字符串(与变量名相同)无法作为变量名引用的理解以及解决方案
在用户登录账号时,我需要在字典中查找是否存在其账号名称以及密码是否正确. 所以,我想将用户输入的账号赋值给变量,在字典中查找是否有此指值. 代码如下: 1 Ya = {'姓名': 'Ya', 'pas ...
- Visual Studio中使用Macros插件给代码添加注释、时间和以及自动脚本
title: Visual Studio中使用Macros插件给代码添加注释.时间和以及自动脚本 date: 2020-09-11 sidebarDepth: 2 tags: 代码 Visual st ...
- 【JVM】JVM 概述、内存结构、溢出、调优(基础结构+StringTable+Unsafe+ByteBuffer)
什么是 JVM ? 定义 Java Virtual Machine - java 程序的运行环境(java 二进制字节码的运行环境) 好处 一次编写,到处运行 自动内存管理,垃圾回收功能 数组下标越界 ...
- [源码解析] PyTorch 分布式(8) -------- DistributedDataParallel之论文篇
[源码解析] PyTorch 分布式(8) -------- DistributedDataParallel之论文篇 目录 [源码解析] PyTorch 分布式(8) -------- Distrib ...
- [bzoj4557]侦察守卫
令g[i][j]表示覆盖了i的子树中距离i大于等于j的所有点,f[i][j]表示覆盖了i的子树和子树外距离i小于等于j的所有点,有递推式$f[i][j]=min(f[i][j]+g[son][j],f ...
- [luogu4548]歌唱王国
(可以参考hdu4652,因此推导过程比较省略) 类似的定义$f_{i}$和$g_{i}$,同样去插入$len$个字符,但注意到并不是任意一个位置都可以作为结尾,$i+j$可以作为结尾当且仅当$s[0 ...
- 测试平台系列(80) 封装Redis客户端
大家好~我是米洛! 我正在从0到1打造一个开源的接口测试平台, 也在编写一套与之对应的完整教程,希望大家多多支持. 欢迎关注我的公众号测试开发坑货,获取最新文章教程! 回顾 上一节我们编写了Redis ...