S2SH整合以及图片上传(1)之spring搭建

    如若转载,请说明出处:http://blog.csdn.net/z1826378013/article/details/79437134

    相关jar包下载

    本套文章项目源码下载在本套文章的最后一篇文章结尾处:S2SH整合以及图片上传项目下载链接

    关于S2SH,主要是struts2+spring+hibernate开发。

    对于S2Sh整合开发来说,一个具体的操作流程,能够有效地解决一些由于粗心而造成的问题。

    此处我采用的流程是spring --> hibernate --> struts2.

    其中对应各个开发框架的版本为:spring4.3.14,hibernate4.3.11,struts2.3.32,mysql5.0.4。

    首先,我们先来搭建第一个框架,spring。

    第一步,在IDE开发环境中新建一个web项目,如下所示:

    

    第二步,在新建的web项目的/TestUpload/WebRoot/WEB-INF/lib目录中,粘贴如下图所示的spring的开发jar包:

    

    第三步,编写一个applicationContext.xml文件,放置到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" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="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.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 配置测试bean -->

</beans>

    第四步,在src目录下,新建一个测试用的包,在其中编写两个类,TestPojo以及TestSSH:

       

    TestPojo内容如下所示:

package com.ssh.test;

public class TestPojo {

	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}

    TestSSH内容如下所示:

package com.ssh.test;

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

public class TestSSH {

	public static void main(String[] args) {

		//获取applicationContext
		ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
		TestPojo testPojo = (TestPojo) ac.getBean("testPojo");
		System.out.println(testPojo.getName());

	}

}

    接着要在applicationContext.xml中配置一个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:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="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.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 配置测试bean -->
<bean id="testPojo" class="com.ssh.test.TestPojo">
    <property name="name" value="Test Spring" />
</bean>

</beans>

    在上面配置的bean中,配置TestPojo的name属性的值为Test Spring,方便后续测试。

    第五步,测试spring,结果如下,则成功配置好了spring:

    

S2SH整合以及图片上传(2)之hibernate搭建(1)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值