JavaEE项目实战(OA系统)之六_三大框架整合之三

  JavaEE项目实战(OA系统)之六_三大框架整合之三

  在添加完三大框架后,工程的src文件夹下出现了两个配置文件applicationContext.xml和struts.xml,它们分别是spring和struts框架的配置文件,hibernate的配置文件被整合到spring中,所以没有配置文件。


  1. 修改applicationContext.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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"
	xmlns:tx="http://www.springframework.org/schema/tx">

	<!-- 自动扫描与装配 -->
	<!-- 这里是spring支持注解的关键配置,自动扫描指定包下的所有注解,并自动装配 -->
	<context:component-scan base-package="com.hanhf.oa"></context:component-scan>

	<!-- 数据源配置 -->
	<!-- 数据源指定数据库的连接信息 -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
		<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl">
		</property>
		<property name="username" value="oa_user"></property>
		<property name="password" value="123456"></property>
	</bean>

	<!-- session工厂配置 -->
	<!-- 这里是hibernate4的配置 -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
		<property name="dataSource">
			<ref bean="dataSource" />
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.Oracle9Dialect
				</prop>
				<prop key="hibernate.show_sql">true</prop>
			</props>
		</property>

		<!-- 自动扫描实体 -->
		<!-- ER映射文件取消了,改成在实体类中使用注解 -->
		<!-- 以下配置表示自动扫描指定包下的实体类 -->
		<property name="packagesToScan" value="com.hanhf.oa" />
	</bean>

	<!-- 定义事务管理器,这里使用的是hibernate4的事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>

	<!-- 定义“注解驱动”的事务 -->
	<!-- 事务是以注解的方式声明在业务逻辑层上 -->
	<tx:annotation-driven transaction-manager="transactionManager" />
</beans>

  2. 修改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" />
	<!-- 将对象交给spring管理 -->
	<constant name="struts.objectFactory" value="spring" />
	<!-- 指定资源编码类型 -->
	<constant name="struts.i18n.encoding" value="UTF-8" />
	<!-- 指定每次请求到达,重新加载资源文件 -->
	<constant name="struts.i18n.reload" value="false" />
	<!-- 指定每次配置文件更改后,自动重新加载 -->
	<constant name="struts.configuration.xml.reload" value="false" />
	<!-- 默认后缀名 -->
	<constant name="struts.action.extension" value="action," />

	<!-- 定义一个包,struts中的包可以把若干个action组织在一起 -->
	<package name="basic" extends="struts-default">
		<!-- 全局结果页 -->
		<global-results>
			<result name="success">/manage/success.jsp</result>
			<result name="failure">/manage/failure.jsp</result>
		</global-results>
	</package>
</struts>

  至此,三大框架的整合全部完成,下面就可以开始编写一个小模块进行练习了。


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值