spring3.0+struts2.1+mybatis3.2搭建

编程技术  /  houtizong 发布于 3年前   72

1.导入的相关包是:

asm-3.3.1.jar

cglib-2.2.2.jar

commons-logging-1.1.1.jar

javassist-3.17.1-GA.jar

log4j-1.2.17.jar

mybatis-3.2.2.jar

mybatis-spring-1.2.0-javadoc.jar

mybatis-spring-1.2.0-sources.jar

mybatis-spring-1.2.0.jar

ojdbc5.jar

slf4j-api-1.7.5.jar

slf4j-log4j12-1.7.5.jar

 

2.建立的package

com.ly.action(com/ly/action/UserAction.java   struts的action操作层)

com.ly.mapper(com/ly/mapper/UserMapper.java和com/ly/mapper/UserMapper.xml mapper接口和映射文件)

com.ly.model(com/ly/model/User.java  POJO类)

com.ly.service(/com/ly/service/UserService.java  service接口)

com.ly.service.impl(com/ly/service/impl/UserServiceImpl.java  service接口实现类   业务逻辑层)

 

3.myEclipse需要导入的插件有:

Struts 2 Core Libraries

Struts 2 Spring Libraries

Spring 3.0 Core Libraries

Spring 3.0 AOP Libraries

Spring 3.0 Persistence JDBC

Spring 3.0 Persistence Core

Spring 3.0 web libraries

 

4.在src/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"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">        <!--指定oracle.properties的位置--><beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="location" value="classpath:oracle.properties"></property></bean>        <!--链接oracle数据源--><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close"><property name="username" value="${jdbc.username}"></property><property name="password" value="${jdbc.password}"></property><property name="url" value="${jdbc.url}"></property><property name="driverClassName" value="${jdbc.driver}"></property></bean>        <!-spring管理sqlsessionfactory--><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource"></property>                <!--告诉spring  mapper映射文件的位置 该包下的所有xml文件--><property name="mapperLocations" value="classpath*:com/ly/mapper/**/*.xml"></property>                <!--告诉spring  POJO;类--><property name="typeAliasesPackage" value="com.ly.model"></property></bean>        <bean id="usermapper" class="org.mybatis.spring.mapper.MapperFactoryBean"><property name="sqlSessionFactory" ref="sqlSessionFactory"></property><property name="mapperInterface" value="com.ly.mapper.UserMapper"></property></bean><!--需要在userservice的实现类里添加mappper对象属性--><bean id="userserviceimpl" class="com.ly.service.impl.UserServiceImpl"><property name="usermapper" ref="usermapper"></property></bean><!--该配置后,需要在UserAction.java类里添加userservice属性--><bean id="useraction" class="com.ly.action.UserAction"><property name="userservice" ref="userserviceimpl"></property></bean><!-- 配置事物 --><bean id="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"></property></bean><!--链接其他spring配置文件--><import resource="aop.xml"/></beans>

 

aop.xml配置:

 

这一步需要右键工程名/src目录new->other->Spring->Spring Bean Definition->next-(需要修改配置文件的文件名,自定义文件名这里是aop.xml)->finish

 

 

<?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:lang="http://www.springframework.org/schema/lang" xmlns:p="http://www.springframework.org/schema/p"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsdhttp://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
 

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客