用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容器的所有特性来实现您的命令类. ...
随机推荐
- Java基础复习之数组
Java基础复习之:数组 简介 数组(Array):多个相同数据类型按照一定顺序排列的集合,并使用一个名字命名,通过编号的方式对这些数据进行统一管理 一维数组 一维数组的声明与初始化 int[] id ...
- asp.net.core教程
asp.net.core教程(翻译自微软官方文档https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/adding- ...
- Dao、Controller、Service三层的结构划分
Java Web基础--Controller+Service +Dao三层的功能划分(摘取自网络)1. Controller/Service/DAO简介: Controller是管理业务( ...
- Part 39 AngularJS route change events
In this video we will discuss1. Different events that are triggered when a route change occurs in an ...
- 第五周PTA笔记 后缀表达式+后缀表达式计算
后缀表达式 所谓后缀表达式是指这样的一个表达式:式中不再引用括号,运算符号放在两个运算对象之后,所有计算按运算符号出现的顺序,严格地由左而右进行(不用考虑运算符的优先级). 如:中缀表达式 3(5–2 ...
- Python基础(filter)
arr = [1,2,3,1,1,3,6,9] def f1(x): if x > 2: return True arr1 = list(filter(f1,arr)) print(arr1)# ...
- python读写文件with open
简介 使用python的过程中肯定少不了读取文件的操作, 传统的形式是使用 直接打开.然后在操作.然后再关闭, 这样代码量稍微大些不说,一旦在操作步骤中出现报错,则无法进行文件的关闭: 案例一(读取) ...
- [bzoj1089]严格n元树
设f[i]表示深度不超过i的方案数,那么有f[0]=1,$f[i]=f[i-1]^{n}+1$,然后用高精度即可(注意深度恰好为d还要用f[d]-f[d-1]才是答案) 1 #include<b ...
- window10快捷键 + 浏览器常用通用快捷键
一.window10快捷键 1.win+tab 缩小版的显示出桌面打开的所有窗口,然后再结合上下左右键加enter选择想要的窗口: 如果不想选择或者保留原有显示窗口,再按win+tab 或者 ...
- linux中chage命令的基本使用
在Linux中chage命令常用于设置系统用户的账户属性 Usage: chage [options] LOGIN Options: -d, --lastday LAST_DAY set date o ...