maven+spring+mybatis+struts1+oracle中使用到的配置文件

applicationContext.xml的配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context-3.2.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
	http://www.springframework.org/schema/tx
	http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">


	<!-- Oracle数据库配置 -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName" value="oracle.jdbc.OracleDriver">
		</property>
		<property name="url" value="jdbc:oracle:thin:127.0.0.1:1521:ORCL">
		</property>
		<property name="username" value="system"></property>
		<property name="password" value="123456"></property>
	</bean>


	<!-- 使用工厂模式 -->
	<bean id="SqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource"></property>
		<!-- 使用别名 -->
		<property name="typeAliasesPackage" value="com.fei.entity"/>
		<property name="mapperLocations">
			<list>
				<value>classpath:com/fei/mapper/*.xml</value>
			</list>
		</property>
	</bean>
	<!-- 自动扫描Mapper -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.fei.mapper"></property>
		<property name="sqlSessionFactory" ref="SqlSessionFactory"></property>
	</bean>

	<!-- 定义事务管理器 -->
	<bean id="txManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<tx:annotation-driven />
	<tx:advice id="txAdvice" transaction-manager="txManager">
		<tx:attributes>
			<tx:method name="find*" propagation="SUPPORTS" />
			<tx:method name="add*" propagation="REQUIRED" />
			<tx:method name="del*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
		</tx:attributes>
	</tx:advice>
	<!-- 定义切面 -->
	<aop:config>
		<aop:pointcut id="serviceMethod" expression="execution(* com.fei.services..*(..))" />
		<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod" />
	</aop:config>

	<!-- 开启自动扫描服务 -->
	<context:component-scan base-package="com.fei.services" />
		
	<!--开启了自动扫描,下面的Service层的Bean就不需要进行配置了,在Service层使用@Service @Resource注解就可以了
	<bean id="OrderService" class="com.fei.services.OrderServiceImpl">
		<property name="orderMapper" ref="orderMapper"></property>
	</bean>
	-->
	
	<!-- 这是整合的struts1的bean ,name的值与action中的path值需要对应 -->
	<!-- 还可以使用右键spring》new bean 的方式添加使用P值注入 -->
	<bean name="/add" class="com.fei.struts.action.AddAction">
		<property name="orderService" ref="orderServiceImpl" />
	</bean>
</beans>

struts-config.xml中的配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">


<struts-config>
	<data-sources />
	<!-- input值需要封装到的类 -->
	<form-beans>
		<form-bean name="addForm" type="com.fei.entity.Order" />
	</form-beans>

	<!-- 一下两个节点没有进行配置。但是是比较常见的两个节点,所以特别说明一下 -->
	<!-- 全局异常 -->
	<global-exceptions />
	<!-- 全局跳转 -->
	<global-forwards />

	<action-mappings>		
		<action attribute="addForm" input="add.jsp" name="addForm"
			path="/add" scope="request" parameter="opr"
			type="org.springframework.web.struts.DelegatingActionProxy">
			<forward name="SUCCESS" path="/success.jsp" redirect="true" />
		</action>
    	<action path="/login" type="org.springframework.web.struts.DelegatingActionProxy">
     		<!-- 跳转网页 -->
	    	<forward name="SUCCESS" path="/add.jsp" redirect="true" />
    	</action>
	
	</action-mappings>
	<!-- 默认生成的资源路径 -->
	<message-resources parameter="com.fei.struts.ApplicationResources" />
	
	<!-- 配置为Spring托管 -->
	<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
		<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />
	</plug-in>
	<!-- 配置类型转换器 -->
	<!--<plug-in className="com.fei.converter.DateConverter"/>-->
	<!-- <set-property property="cancellable" value="false" /> -->
	<!-- type="org.springframework.web.struts.DelegatingActionProxy"-->
</struts-config>

另外需要注意几点:

1    在services实现类或者在action中,创建的对象属性,都是使用的接口属性。如果使用实例类会报错

2    属性需要get,set封装

3    mapper.xml中,封装的数据数据库要和实体类一致,如果不同,需要使用resultMap进行关联collection是一对多,就是属    性里面是list或者别的集合类型,association是多对一,就是指一个对象类型的属性

4    还有在JSP页面使用JSTL的话,除了pom.xml添加依赖,还需要在JSP页面页头进行如下声明才可以使用:

<%@ page isELIgnored="false"%>
后面pom的依赖我在另一个帖子中进行贴出


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值