JAVA-WEB的SSH(Spring Hibernate Struts)环境搭建一(Spring)

一,开发环境

       工具:eclipse

      Spring:4.3.1

      Commons-logging:1.1.1

二,建立工程

      a,新建动态web工程:file-new-dynamic web project

      b,复制spring的jar包到工程:

                    jar包位置:spring-framework-4.3.1.RELEASE\libs,下的所有jar包

                    拷贝至:项目的WebContent/WEB-INF/lib

      c,复制Commons-logging的jar包到工程

                  jar包位置:commons-logging-1.1.1目录下,只需commons-logging-1.1.1.jar一个即可

                 拷贝至:项目的WebContent/WEB-INF/lib

      d,至此环境已建立完成

三,测试spring环境

      a,建立测试bean

             1,新建包org.com.xsx.beans

             2,在包下新建class:User.java

                   

package org.com.xsx.beans;

public class UserBean {
	private int id;
	private String account;
	private String password;
	private String name;
	private String sex;
	private int age;
	private String email;
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getAccount() {
		return account;
	}
	public void setAccount(String account) {
		this.account = account;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
}

            3,在src下新建spring配置文件,右键-new-others-Spring-Spring Bean Configuration File,并配置一个id为TestUser的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"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:jdbc="http://www.springframework.org/schema/jdbc"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">

	<bean id="test_user" class="org.com.xsx.beans.UserBean">
		<property name="account" value="xsx"></property>
		<property name="password" value="xsx127"></property>
	</bean>
</beans>

          4,新建包org.com.xsx.Test,并新建Test.java,进行Units测试

 

package org.com.xsx.unit;


import org.com.xsx.beans.UserBean;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestUnits {
	
	private ApplicationContext ctx = null;
	
	private UserBean user = null;
	
	{
		ctx = new ClassPathXmlApplicationContext("ApplicationContextBean.xml");
		user = ctx.getBean(UserBean.class);
	}
	
	@Test
	public void test1(){
		System.out.println("账号:"+user.getAccount());
		System.out.println("密码:"+user.getPassword());
	}
}

           5,右键ran as--JUnit Test,没报错,即证明spring环境建立完成,成功则显示一下信息
八月 13, 2016 6:22:55 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@61baa894: startup date [Sat Aug 13 18:22:55 CST 2016]; root of context hierarchy
八月 13, 2016 6:22:55 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [ApplicationContextBean.xml]
账号:xsx
密码:xsx127

           



           

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值