新建Spring项目
方法一选择File菜单 -》New -》 Other... -》Spring -》 SpringProject
方法二选择File菜单 -》New -》JavaProject。项目创建完成后,选中项目,右键菜单 -》Spring Tools -》add Spring project nature
添加项目需要的库文件:spring-2.5.6.jar、commons-logging.jar、log4j-1.2.15.jar
在项目的src下,创建log4j的配置文件:log4j.xml,内容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration PUBLIC
"http://logging.apache.org/log4j/docs/api/org/apache/log4j/xml/log4j.dtd"
"http://logging.apache.org/log4j/docs/api/org/apache/log4j/xml/log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.SimpleLayout" />
</appender>
<root>
<level value="info" />
<appender-ref ref="console" />
</root>
</log4j:configuration>
新建Java类,创建一个简单的JavaBean
package org.study.spring.beans;
import java.util.Date;
public class SimpleBean {
private Integer beanId;
private String beanName;
private Date createDate;
public Integer getBeanId() {
return beanId;
}
public void setBeanId(Integer beanId) {
this.beanId = beanId;
}
public String getBeanName() {
return beanName;
}
public void setBeanName(String beanName) {
this.beanName = beanName;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
}
新建Spring配置文件:
选择File菜单 -》New -》 Other... -》Spring -》 Spring Bean Configuration File -》选择配置文件的保存目录(项目下的src),设置文件名(appcontext.xml) -》选择需要用到的xsd namespace(因为是一个简单功能,选择beans一项即可)
创建bean
方法一:选择File菜单 -》New -》 Other... -》Spring -》 Spring Bean Definition-》选择Spring配置文件,配置bean的Id(currentDate)、Class(java.util.Date)
选择File菜单 -》New -》 Other... -》Spring -》 Spring Bean Definition-》选择Spring配置文件,配置bean的Id(simpleBeanId)、Name(simpleBeanName)、Class(org.study.spring.beans.SimpleBean) -》设置属性值,这个地方不错,属性有代码提示功能
方法二:调用outline视图
方法三:打开配置文件,根据代码提示
创建客户端代码:
package org.study.spring.beans;
import java.text.DateFormat;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
public class ClientApp {
private static final Logger logger = Logger.getLogger(ClientApp.class);
/**
* @param args
*/
public static void main(String[] args) {
BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(
"appcontext.xml"));
SimpleBean simpleBean = (SimpleBean) beanFactory
.getBean("simpleBeanId");
logger.info(simpleBean.getBeanName()
+ "创建时间:"
+ DateFormat.getDateTimeInstance().format(
simpleBean.getCreateDate()));
}
}
选择Window菜单-》Show View -》Other... -》Spring -》 Spring Explorer (能够校验,并以图形等多种形式来展示bean的定义及其相互关系)
分享到:
相关推荐
描述中提到的“eclipse4.7.1a版本需要的springsource-tool-suite插件,含有eclipse安装spring教程”,意味着这个压缩包不仅包含SpringSource Tool Suite的相关组件,还提供了一份Eclipse安装Spring的指导文档。...
标题 "springsource-tool-suite-3.9.7.RELEASE-e4.8.0-updatesite" 提供的信息表明这是一个SpringSource Tool Suite的更新站点,版本号为3.9.7 RELEASE,基于Eclipse 4.8.0版本。SpringSource Tool Suite(STS)是专...
启动SpringSource Tool suit 没法启动的处理方法
标题 "springsource-tool-suite-3.7.2.RELEASE-e4.5.1-updatesite.zip" 提供的信息表明,这是一个SpringSource Tool Suite (STS) 的更新站点压缩包,具体版本为3.7.2.RELEASE,适配Eclipse Mars 4.5.1版本。...
在【标题】中提到的"Spring框架所需要的jar包(SpringSource tool suite)环境下",意味着这个压缩包包含了在SpringSource Tool Suite中开发Spring项目所必需的核心库。这些jar包涵盖了Spring框架的各个模块,包括但...
SpringSource Tool Suite (STS) 是一个专为开发Spring框架应用而设计的集成开发环境(IDE)。这个压缩包“springsource-tool-suite-3.9.8.RELEASE-e4.11.0-updatesite.zip”是针对SpringSource Tool Suite的3.9.8版本...
标题中的“springsource-tool-suite-3.9.5.RELEASE-e4.7.3a-updatesite”指的是SpringSource Tool Suite的一个特定版本,这是一个集成开发环境(IDE),专为Spring框架和相关技术提供强大的支持。它基于Eclipse ...
标题 "springsource-tool-suite-3.9.10.RELEASE-e4.12.0-updatesite.zip" 暗示我们正在处理的是SpringSource Tool Suite的一个更新站点包,版本为3.9.10.RELEASE,它基于Eclipse 4.12.0。这个工具套件是专为Spring...
《SpringSource Tool Suite 3.9.4.RELEASE与Eclipse集成详解》 SpringSource Tool Suite(STS)是一款由SpringSource公司开发的基于Eclipse的集成开发环境,专门用于简化Spring框架及其相关技术的开发工作。这个...
标题中的“springsource-tool-suite-3.4.0.RELEASE-e4.3.1-updatesite.zip”指的是SpringSource Tool Suite(STS)的一个特定版本,即3.4.0.RELEASE,它针对的是Eclipse集成开发环境的4.3.1版本。SpringSource Tool ...
SpringSource Tool Suite (STS) 是一个基于Eclipse的集成开发环境,专为Spring框架和相关技术提供优化。这个资源是SpringSource Tool Suite的3.9.9.RELEASE版本,适用于Eclipse 4.9(也称为 Oxygen.3a Release)。在...
标题中的"**springsource-tool-suite-3.6.4.RELEASE-e4.4.2-updatesite.zip**"是一个SpringSource Tool Suite的更新站点压缩包,版本为3.6.4.RELEASE,基于Eclipse 4.4.2(Luna)版本。这个工具套件是专为简化Spring...
springsource-tool-suite-3.9.5.RELEASE-e4.8.0-updatesite springsource-tool-suite-3.9.5版本与eclipse4.8.0版本匹配
标题中的“springsource-tool-suite-3.6.3.RELEASE-e4.4.1-updatesite.zip”指的是SpringSource Tool Suite的一个特定版本,即3.6.3.RELEASE,它基于Eclipse 4.4.1(Luna)构建的更新站点(update site)包。...
标题中的“eclipse4.10.0版本可用的springsource-tool-suite-3.9.9.RELEASE-e4.10.0-updatesite.zip”揭示了这是一款专为Eclipse 4.10.0版本设计的SpringSource Tool Suite(STS)插件包,其版本号为3.9.9.RELEASE。...
《SpringSource Tool Suite 3.9.5.RELEASE与Eclipse 4.8.0集成详解》 SpringSource Tool Suite(简称STS)是一款强大的集成开发环境(IDE),专门针对Spring框架进行优化,为开发者提供了丰富的工具和功能,极大地...
SpringSource Tool Suite 基于 Spring IDE ,提供了其它的一些特性,如 基于Spring dm Server 的osgi 开发,及其它一些 Spring 项目的支持,如Spring Roo, Spring Batch等
《SpringSource Tool Suite 3.9.3.RELEASE在Eclipse 4.7.3中的安装与使用详解》 SpringSource Tool Suite(STS)是一款基于Eclipse IDE的高度集成开发环境,专为Spring框架的开发而设计。这个工具集提供了一系列...
标题中的“springsource-tool-suite-3.9.7.RELEASE-e4.9.0-updatesite”是指SpringSource Tool Suite的一个版本,这是由Pivotal Software开发的集成开发环境(IDE),专为Spring框架的开发设计。这个版本是3.9.7,...