Spring入门笔记一之搭建环境及配置编写及简单测试

下载工具

(1)在eclipse上增加STS插件(spring tool suite)
(2)下载安装STS工具(可在https://spring.io/tools/sts/下载)
(使用idea工具也完全ok)

搭建spring环境

使用spring所需至少使用6的jar包

开发AOP特性时需要的JAR
spring-aop.jar

处理Bean的jar
spring-beans.jar

处理spring上下文的jar
spring-context.jar

spring核心jar
spring-core.jar

spring表达式
spring-expression.jar

三方提供的日志jar
commons-logging.jar

编写配置文件

(1)在项目中新建文件bean configuration 命名为applicationContext.xml

在这里插入图片描述
(2)在applicationContext.xml进行编写

例:

编写一个student类(需要有set方法)

public class Student {
   private int sno;
   private String sname;
public int getSno() {
	return sno;
}
public void setSno(int sno) {
	this.sno = sno;
}
public String getSname() {
	return sname;
}
public void setSname(String sname) {
	this.sname = sname;
}


}

在配置文件中编写

<bean id="student" class="com.Spring.Student">
    	<property name="sno" value="1"></property>
    	<property name="sname" value="zs"></property>
    </bean>

测试
在main方法中编写

ApplicationContext context  = new ClassPathXmlApplicationContext("applicationContext.xml");
Student student =(Student)context.getBean("student");

然后使用student进行测试

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值