spring4.3.6.RELEASE 环境搭建

一.相关jar包下载关[官网地址]

1. spring官网地址,依次如下图找到下载地址: http://repo.spring.io/release/org/springframework/spring





2.创建一个动态web工程

3.spring相关jar包导入项目中

选择的jar包如下:需要注意的是:标红处并不是在spring jar里的,但是是必须的。



首先创建一个xml的配置文件,关于xsd如何写,可以参考spring的官方文档



    配置一个bean:

<?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 id="user" class="com.BrightSt.Entity.User">
       <property name="name" value="BrightSt"></property>
    </bean>

</beans>

user实体类

package com.BrightSt.Entity;

public class User {
	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public void show(){
		System.out.println("hello " + this.getName()+"!");
	}

}


测试Test类

package com.BrightSt.test;

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

import com.BrightSt.Entity.User;

public class Test {

	public static void main(String[] args) {
		// 如果使用ClassPathXmlApplicationContext这种方式,applicationContext.xml文件一定要在src跟目录下。
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		User u = (User)context.getBean("user");
		u.show();
	}

}

查看运行后结果:

如果看到了下面的提示信息,说明spring框架初步已搭建成功。

备注:在此只是展示spring环境的搭建,项目目录结构并没有太在意,正式项目请注意项目结构。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值