尽管三大框架特别特别的好用,可是,当我第一次把这三个框架用maven整合到一起的时候。各种错误接踵而至,以下来做一下三大框架整合的总结:

首先是在导入三大框架的各种依赖包的时候,由于我用的是j2ee ecilpse,所以要导入j2ee的依赖包,如今这两个依赖包是这种:

 <!-- j2ee的包 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0-alpha-1</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2.1-b03</version>
</dependency>

假设这两个包的版本号不合,一部署项目就会出现一个jsp什么Exception然后后面就是一个大大的nullpointerException,当初看到这个是十分恼火的,由于之前的上面两个依赖包不是兼容的版本号,所以就报了类似的错误。所以包的导入应该像上面那样。

当然,这仅仅是第一个错误,后面的更无语,下一个错误是:在你的项目和java源代码的包上同一时候出现两个红叉,然后你一部署就出现各种错误。这时不要急,点开problems,发现是这个:Cannot change version of project facet Dynamic Web Module to 2.5,在j2eeeciplse中,这是啥意思呢?意思大概是你的web Module版本号不能是2.5的,然后我把这个错误百度一下。结果非常多,天花乱坠,事实上真正的原因是你的jdk版本号和javaweb 
配置的版本号不一致,由于eclipse会自己主动使用工具自带的jdk,然而你新建的maven项目是新的项目骨架,好的。那jdk自然就是跟不上节奏了。所以给一个正确操作的连接:依照这上面的操作就能够改变你当前项目的状况:http://blog.csdn.net/sunqing0316/article/details/43675837;这仅仅是改动当前项目的状况,要治本,当然要把我们的默认的jdk设置成我们自己的jdk,

同一时候将这个jdk默认设置成你的安装的jdk版本号,就能够解决这个问题了(链接博客里改动web.xml后要update  maven一下)。

还有就是假设某个jar包的包或者依赖包没有下载全然或者失败。可是maven并不会提示你的jar包出现了错误,一旦

出错了,他会提示一个你明明已经导入了包的一个类找不到,这时候  把pom.xml中的那个对应的jar包删除,再在网络好的情况下再下载,就不会有问题了。

遇到的最后一个问题就是三个框架的配置文件的配置问题,三个框架的配置文件一起放在source文件下:

最重要的是struts的action的class名要填spring的bean配置的你写得action:

sping的beans.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:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
">
<!-- 配置action,这里beans的id就是spring中的action -->
<bean id="studentAction" class="com.hyycinfo.ssmtest1.web.actions.StudentAction" scope="prototype">
<property name="studentBiz" ref="studentBiz"></property>
</bean>
</beans>

struts.xml:

<?xml version="1.0" encoding="UTF-8" ?

>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<constant name="struts.objectFactory" value="spring"></constant>
<package name="default" namespace="/" extends="struts-default">
<!-- 这里的class部分必须填写spring 的配置的action的id 名。这是由spring的ioc生成action对象 -->
<action name="student_*" class="studentAction" method="{1}">
<result name="success">
add_success.jsp
</result>
</action> </package>
</struts>

对的。就是这样。

以下是三个框架的整合的依赖配置:

<?xml version="1.0" encoding="UTF-8"?

>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
">
<!-- 注解的读取 -->
<context:annotation-config /> <context:component-scan base-package="com.hyycinfo" /> <!-- 使用注解的事务配置 -->
<tx:annotation-driven transaction-manager="txManager"/>
<!-- 使用spring自带的属性文件读取类完毕读取配置文件的操作 -->
<bean id="pphc"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:db.properties" />
</bean> <!-- 配置dbcp数据源... 数据库联接池 ( jndi-> tomcat的数据库联接池 ) / c3p0 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" /> <property name="maxActive" value="${jdbc.maxActive}" />
<property name="minIdle" value="${jdbc.minIdle}" />
<property name="maxIdle" value="${jdbc.maxIdle}" /> </bean> <!-- 针对mybatis的整合配置 -->
<!-- 配置sqlsessionfactory,找到项目下的mapper文件整合 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" >
<property name="dataSource" ref="dataSource"></property>
<!-- 配置全部的mapper文件的位置 -->
<property name="mapperLocations" value="classpath*:com/hyycinfo/ssmtest1/dao/*.xml"></property>
</bean>
<!-- 配置扫描器,用于扫描全部的map文件 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 配置扫描的映射文件相应的接口的文件夹 -->
<property name="basePackage" value="com.hyycinfo.ssmtest1.dao" />
<!-- 指定这个scanner所使用的sqlsessionfactory -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
<!-- 注意:一定要配置与平台(dao层的实现)有关的事务管理器 -->
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean> <!-- 配置增强 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<!-- 切入点: 这里要增加的就是切入点表达式 -->
<tx:attributes>
<!-- 查询的方法上配置仅仅读事务.. -->
<tx:method name="get*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="load*" read-only="true"/>
<tx:method name="datagrid*" read-only="true"/>
<!--其他的方法上增加事务.. -->
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice> <!-- 配置切面 -->
<aop:config>
<aop:pointcut id="service"
expression="execution(* com.hyycinfo.ssmtest1.biz.impl.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="service" />
</aop:config> </beans>

所以啊,得到一个教训!

在使用各种工具开发时。一定要确保开发环境的一致性:

第一:通用一个自己安装的jdk环境。

第二:tomcat。mysql,eclipse等的开发工具安装一定要按流程走,环境变量一定要配好,不能由于“能用”就不去配环   境变量。

第三:eclipse的工具的设定:首先字符集把工作空间的所有设定为utf-8;

jdk的默认设定所有改成默认的自己安装的版本号的jdk,确定不用eclipse自带的jdk。

开发之路马虎不得啊

spring-struts-mybatis整合错误集锦的更多相关文章

  1. 框架篇:Spring+SpringMVC+Mybatis整合开发

    前言: 前面我已搭建过ssh框架(http://www.cnblogs.com/xrog/p/6359706.html),然而mybatis表示不服啊. Mybatis:"我抗议!" ...

  2. spring, spring mvc, mybatis整合文件配置详解

    转自:http://www.cnblogs.com/wxisme/p/4924561.html 使用SSM框架做了几个小项目了,感觉还不错是时候总结一下了.先总结一下SSM整合的文件配置.其实具体的用 ...

  3. Spring+springmvc+Mybatis整合案例 annotation版(myeclipse)详细版

    Spring+springmvc+Mybatis整合案例 Version:annotation版 文档结构图: 从底层开始做起: 01.配置web.xml文件 <?xml version=&qu ...

  4. Spring+springmvc+Mybatis整合案例 xml配置版(myeclipse)详细版

    Spring+springmvc+Mybatis整合案例 Version:xml版(myeclipse) 文档结构图: 从底层开始做起: 01.配置web.xml文件 <?xml version ...

  5. Spring与Mybatis整合的MapperScannerConfigurer处理过程源码分析

    前言 本文将分析mybatis与spring整合的MapperScannerConfigurer的底层原理,之前已经分析过java中实现动态,可以使用jdk自带api和cglib第三方库生成动态代理. ...

  6. Mybatis学习--spring和Mybatis整合

    简介 在前面写测试代码的时候,不管是基于原始dao还是Mapper接口开发都有许多的重复代码,将spring和mybatis整合可以减少这个重复代码,通过spring的模板方法模式,将这些重复的代码进 ...

  7. 九 spring和mybatis整合

    1       spring和mybatis整合 1.1     整合思路 需要spring通过单例方式管理SqlSessionFactory. spring和mybatis整合生成代理对象,使用Sq ...

  8. Mybatis学习(7)spring和mybatis整合

    整合思路: 需要spring通过单例方式管理SqlSessionFactory. spring和mybatis整合生成代理对象,使用SqlSessionFactory创建SqlSession.(spr ...

  9. SpringMVC, Spring和Mybatis整合案例一

    一  准备工作 包括:spring(包括springmvc).mybatis.mybatis-spring整合包.数据库驱动.第三方连接池. 二  整合思路 Dao层: 1.SqlMapConfig. ...

  10. MyBatis学习七:spring和MyBatis整合

    <\mybatis\day02\16mybatis和spring整合-sqlSessionFactory配置.avi;> MyBatis学习七:spring和MyBatis整合.逆向工程 ...

随机推荐

  1. [暑假集训--数论]hdu2136 Largest prime factor

    Everybody knows any number can be combined by the prime number. Now, your task is telling me what po ...

  2. vmware虚拟机无法ping通主机,也无法联网

  3. How to use rowspan and colspan in tbody using datatable.js?

    https://stackoverflow.com/questions/27290693/how-to-use-rowspan-and-colspan-in-tbody-using-datatable ...

  4. 01.mp4v2应用—mp4转h264

    1.h264文件基本功能 NAL 头 0x00 0x00 0x00 0x01 sps :nal+0x67开头 pps :nal+0x68开头 I帧 0x65 开头 ...... 2.mp4v2提取26 ...

  5. Chrome扩展修改页面代码执行环境的方法

    Chrome的扩展程序可以通过content scripts向页面中注入js代码,所注入的js代码能够对页面中所有的DOM对象进行操作.由于Chrome在js执行环境上对页面代码和content sc ...

  6. C# 用实例来理解IComparable和IComparer

    通过Array的Sort方法来理解的 Sort方法要 通过对象去继承IComparable接口来实现排序(当然也有其它办法),我想入门这可能就是对这句话有点不理解,在下面会有注释 using Syst ...

  7. delphi 内存泄露 分析

  8. JS和jquery加载的区别

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. 介绍Node.JS

    几年前,完全放弃Asp.net,彻底脱离微软方向.Web开发,在公司团队中,一概使用Node.js.Mongodb.Git,替换Asp.net mvc.Sql server和Tfs.当时来看,这是高风 ...

  10. Fresco使用之OOM问题记录

    最近友盟上5.0以上系统报出很多OOM异常,看下日志看到facebook的时候就知道一定是Fresco使用不当导致了OOM. java.lang.OutOfMemoryError: Failed to ...