目录结构:

搭建项目:
1.创建web项目
2.创建各种包.
com.atguigu.surveypark.dao.impl
com.atguigu.surveypark.model
com.atguigu.surveypark.service.impl
com.atguigu.surveypark.struts2.action
com.atguigu.surveypark.util
3.引入类库
[struts2]
asm-3.3.jar
asm-commons-3.3.jar
asm-tree-3.3.jar
commons-fileupload-1.3.jar
commons-io-2.0.1.jar
commons-lang3-3.1.jar
commons-logging-1.1.3.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
log4j-1.2.17.jar
ognl-3.0.6.jar
struts2-core-2.3.15.1.jar
xwork-core-2.3.15.1.jar
[hibernate]
antlr-2.7.7.jar
hibernate-commons-annotations-4.0.2.Final.jar
hibernate-core-4.2.3.Final.jar
hibernate-entitymanager-4.2.3.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
javassist-3.15.0-GA.jar
hibernate-ehcache-4.2.3.Final.jar
[spring]
org.springframework.aop-3.1.0.CI-1162.jar
org.springframework.asm-3.1.0.CI-1162.jar
org.springframework.aspects-3.1.0.CI-1162.jar
org.springframework.beans-3.1.0.CI-1162.jar
org.springframework.context-3.1.0.CI-1162.jar
org.springframework.context.support-3.1.0.CI-1162.jar
org.springframework.core-3.1.0.CI-1162.jar
org.springframework.expression-3.1.0.CI-1162.jar
org.springframework.jdbc-3.1.0.CI-1162.jar
org.springframework.orm-3.1.0.CI-1162.jar
org.springframework.transaction-3.1.0.CI-1162.jar
org.springframework.web-3.1.0.CI-1162.jar
com.springsource.net.sf.cglib-2.2.0.jar
com.springsource.org.aopalliance-1.0.0.jar
com.springsource.org.aspectj.tools-1.6.6.RELEASE.jar
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
[struts2-spring插件]
struts2-spring-plugin-2.3.15.1.jar
[数据源]
com.springsource.com.mchange.v2.c3p0-0.9.1.2.jar
[驱动程序]
mysql-connector-java-5.0.8-bin.jar
3.配置项目
[struts2 + web]
[web-inf/web.xml]
<!-- 配置struts2的过滤器 -->
<filter>
<filter-name>action</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>action</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
[confi/struts.xml]
<?xml version="1.0"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="surveyparkPkg" extends="struts-default" namespace="/">
</package>
</struts>
[spring--config/beans.xml]

由图的依赖可知:应该先配置数据源,配置数据源之前可以先创建数据库。
1.创建数据库:lsn_surveypark001
2.配置config/bean.xml
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<!-- 分散配置 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverclass}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="maxPoolSize" value="${c3p0.pool.size.max}" />
<property name="minPoolSize" value="${c3p0.pool.size.min}" />
<property name="initialPoolSize" value="${c3p0.pool.size.ini}" />
<property name="acquireIncrement" value="${c3p0.pool.size.increment}" />
</bean>
</beans>
[jdbc.properties]
jdbc.driverclass=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://locallhost:3306/lsn_surveypark001
jdbc.username=root
jdbc.password=root
c3p0.pool.size.max=10
c3p0.pool.size.min=2
c3p0.pool.size.ini=3
c3p0.pool.size.increment=2
4.测试数据源
public class TestDataSource {
@Test
public void getConnection() throws SQLException{
ApplicationContext ac = new ClassPathXmlApplicationContext("beans0.xml");
DataSource ds = (DataSource) ac.getBean("dataSource");
System.out.println(ds.getConnection());
}
}
ssh 整合,布布扣,bubuko.com
ssh 整合
原文:http://blog.csdn.net/coslay/article/details/34536113