Eclipse安装Spring Tool Suit 插件

插件链接http://download.springsource.com/release/TOOLS/update/3.8.3.RELEASE/e4.6/springsource-tool-suite-3.8.3.RELEASE-e4.6.2-updatesite.zip

其它版本参考此博客:https://blog.csdn.net/zhen_6137/article/details/79384798

添加下载好的压缩文件路径

然后,接受,完成,重启即可,出现一下界面即安装成功

编写一个helloWorld,新建一个Java Project

新建一个lib将spring必须依赖的包,导入进去,依赖的包在此处下载链接:

https://pan.baidu.com/s/1Gev5-YW_CERgTQxE2xFxNQ 
提取码:xu86

src下新建一个包,保内建立两个java文件如下

package com.atguigu.spring.beans;

public class HelloWorld {
	private String name;
	public void setName(String name){
		System.out.println("setName: " + name);
		this.name = name;
	}
	public void hello(){
		System.out.println("hello: " + name);
	}
	
	//无参构造器
	public HelloWorld(){
		System.out.println("HelloWorld's Constructor...");
	}
}

 

package com.atguigu.spring.beans;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
	public static void main(String[] args){
		//此段代码用Spring代码替换
		/*
		//创建HelloWorld的一个对象
		HelloWorld helloWorld = new HelloWorld();
		//为name属性赋值
		helloWorld.setName("atguigu");*/
		
		//1.创建Spring的IOC容器对象
		ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		
		//2.从IOC容器中获取Bean实例
		HelloWorld helloWorld = (HelloWorld) ctx.getBean("helloWorld");
		
		//3.调用hello方法
		helloWorld.hello();
	}
}

 

src下新建Spring Bean的配置文件

注意此文件必须建在src目录下,不能是包里,否则会报异常

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<!-- bean -->
	<bean id="helloWorld" class="com.atguigu.spring.beans.HelloWorld">
		<property name="name" value="Spring"></property>
	</bean>
</beans>

运行Main文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值