一 Spring的applicationContext.xml中的配置:
<?
xmlversion
=
"1.0"encoding
=
"UTF-8"
?>
<
beans
xmlns
="http://www.springframework.org/schema/beans"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p
="http://www.springframework.org/schema/p"
xsi:schemaLocation
="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
>
<!-- 配置由Spring IoC容器托管对象对应的被注解的类所在的包 -->
<
context:component-scan
base-package
=
"com.kedacom"
/>
<!-- 配置通过自动生成代理类实现AOP功能 -->
<aop:aspectj-autoproxy
/>
<!--DateSource 使用c3p0连接池-->
<
bean
id
="dateSource"
class
="com.mchange.v2.c3p0.ComboPooledDateSource"
destroy-method
="close"
>
<property
name
=
"user"
value
=
"root"
></property
>
<
property
name
="password"
value
="root"
></
property
>
</bean
>
<!-- SessionFactory 配置 配置Spring提供的支持注解ORM映射的
Hibernate会话工厂-->
<
bean
id
="sessionFactory"
class
="org.springframework.orm.hibernate3.annotation"
>
<
property
name
="dateSource"
ref
="dateSource"
></
property
>
<
property
name
="congifLocation"
value
="classpath:hibernate.cfg.xml"
></
property
>
</bean
>
<!-- 配置spring基于注解的声明式事务管理 -->
<
bean
id
="transactionManager"
class
="org.springframework.orm.hibernate3.HibernateTransactionManager"
>
<!-- 通过setter注入
Hibernate会话工厂 -->
<
property
name
="sessionFactory"
ref
="sessionFactory"
></
property
>
</bean
>
<tx:annotation-driven
transaction-manager
=
"transactionManager"
/>
</beans
>
二 Hibernate.cfg.xml配置:
<?
xmlversion
=
'1.0'encoding
=
'UTF-8'
?>
<!
DOCTYPEhibernate-configuration
PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
<!-- Generated by MyEclipse
Hibernate Tools. -->
<hibernate-configuration
>
<session-factory
>
<!--
数据库连接信息 ,其他的写到了spring配置文件中去 -->
<
property
name=
"dialect"
>org.hibernate.dialect.MySQLDialect
</
property
>
<!-- 其他配置 -->
<property
name
=
"show_sql"
>
true
</property
>
<
property
name=
"hbm2ddl.auto"
>update
</
property
>
<!-- 导入映射配置 -->
<
mapping
resource
="../../.hbm.xml"
/>
<
mapping
resource
="../../.hbm.xml"
/>
<
mapping
resource
="../../.hbm.xml"
/>
</session-factory
>
</hibernate-configuration
>
三 struts.xml中的配置文件:
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<!
DOCTYPE
struts
PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd"
>
<
struts
>
<!-- 配置为开发模式 -->
<
constant
name
=
"struts.devMode"
value
=
"true"
></
constant
>
<!-- 配置扩展名为action -->
<
constant
name
=
"struts.action.extension"
value
=
"action"
></
constant
>
<!-- 当struts配置文件修改时,系统是否自动重新加载该文件,默认false,开发阶段最好打开 -->
<
constant
name
=
"struts.configuration.xml.reload"
value
=
"true"
></
constant
>
<!-- 全局视图 -->
<
package
name
=
"LunTanSystem"
extends
=
"struts-default"
>
<
global-results
>
<
result
name
=
"error"
>
/error.jsp
</
result
>
<
result
name
=
"ajax"
>
/ajax.jsp
</
result
>
<
result
name
=
"noLogin"
>
/login.jsp
</
result
>
</
global-results
>
<!-- 当与action整合后,class属性写的就是Spring中bean的属性 -->
<
action
name
=
"test"
class
=
"testAction"
>
<
result
name
=
"success"
>
/test.jsp
</
result
>
</
action
>
</
package
>
</
struts
>
四 web.xml配置文件的编写:
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<web-app
version
=
"2.5"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
>
<display-name
></display-name
>
<!-- 配置Struts2的主过滤器 -->
<filter
>
<filter-name
>
struts2
</filter-name
>
<filter-class
>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class
>
</filter
>
<filter-mapping
>
<filter-name
>
struts2
</filter-name
>
<url-pattern
>
/*
</url-pattern
>
</filter-mapping
>
<!--配置Spring的监听器,用于初始化ApplicationContext.xml -->
<listener
>
<
listener-class
>org.springframework.web.context.ContextLoader
</
listener-class
>
</listener
>
<context-param
>
<
param-name
>contextConfigLocation
</
param-name
>
<
param-value
>classpath:applicationContext*.
xml
</
param-value
>
</context-param
>
<welcome-file-list
>
<welcome-file
>
index.jsp
</welcome-file
>
</welcome-file-list
>
</web-app
>