spring-struts-mybatis整合错误集锦
尽管三大框架特别特别的好用,可是,当我第一次把这三个框架用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整合错误集锦的更多相关文章
- 框架篇:Spring+SpringMVC+Mybatis整合开发
前言: 前面我已搭建过ssh框架(http://www.cnblogs.com/xrog/p/6359706.html),然而mybatis表示不服啊. Mybatis:"我抗议!" ...
- spring, spring mvc, mybatis整合文件配置详解
转自:http://www.cnblogs.com/wxisme/p/4924561.html 使用SSM框架做了几个小项目了,感觉还不错是时候总结一下了.先总结一下SSM整合的文件配置.其实具体的用 ...
- Spring+springmvc+Mybatis整合案例 annotation版(myeclipse)详细版
Spring+springmvc+Mybatis整合案例 Version:annotation版 文档结构图: 从底层开始做起: 01.配置web.xml文件 <?xml version=&qu ...
- Spring+springmvc+Mybatis整合案例 xml配置版(myeclipse)详细版
Spring+springmvc+Mybatis整合案例 Version:xml版(myeclipse) 文档结构图: 从底层开始做起: 01.配置web.xml文件 <?xml version ...
- Spring与Mybatis整合的MapperScannerConfigurer处理过程源码分析
前言 本文将分析mybatis与spring整合的MapperScannerConfigurer的底层原理,之前已经分析过java中实现动态,可以使用jdk自带api和cglib第三方库生成动态代理. ...
- Mybatis学习--spring和Mybatis整合
简介 在前面写测试代码的时候,不管是基于原始dao还是Mapper接口开发都有许多的重复代码,将spring和mybatis整合可以减少这个重复代码,通过spring的模板方法模式,将这些重复的代码进 ...
- 九 spring和mybatis整合
1 spring和mybatis整合 1.1 整合思路 需要spring通过单例方式管理SqlSessionFactory. spring和mybatis整合生成代理对象,使用Sq ...
- Mybatis学习(7)spring和mybatis整合
整合思路: 需要spring通过单例方式管理SqlSessionFactory. spring和mybatis整合生成代理对象,使用SqlSessionFactory创建SqlSession.(spr ...
- SpringMVC, Spring和Mybatis整合案例一
一 准备工作 包括:spring(包括springmvc).mybatis.mybatis-spring整合包.数据库驱动.第三方连接池. 二 整合思路 Dao层: 1.SqlMapConfig. ...
- MyBatis学习七:spring和MyBatis整合
<\mybatis\day02\16mybatis和spring整合-sqlSessionFactory配置.avi;> MyBatis学习七:spring和MyBatis整合.逆向工程 ...
随机推荐
- Ionic2中使用第三方插件极光推送
不同于Ionic1中插件的调用,Ionic2提供了Ionic Native.Ionic Native封装了一些常见的插件(如:Camera.Barcode Scanner等),这些插件的使用方式在官方 ...
- 用session设置访问权限
在web.xml中 <session-config> <session-timeout>15</session-timeout> </session-conf ...
- 在vue中使用sass
首先安装node-sass和sass-loader cnpm install node-sass && sass-loader --save 在webpack.config.js 的m ...
- css 文字垂直居中问题
CSS 文字垂直居中问题 问题:在 div 中文字居中问题: 当使用 line-height:100%%; 时,文字没有居中,如下: html: <div id="header_log ...
- Ant自动打包
在ant的官网http://ant.apache.org进行下载后apache-ant-1.8.2包 解压(存放的路径不要有中文字符) 把ant里的lib设置到环境变量:E:\Android\apac ...
- 在类中写reponse语句
原文发布时间为:2009-06-18 -- 来源于本人的百度文章 [由搬家工具导入] 在类文件中不能直接使用response.write,需要使用 System.Web.HttpContext.Cur ...
- Selenium2+python自动化(学习笔记2)
from selenium import webdriverdriver = webdriver.Ie()driver.get=("http://www.baidu.com")dr ...
- Linux 6.x 下Oracle 11g R2 安装配置
Oracle 11g R2 数据库安装硬件配置要求: 最小内存 1 GB of RAM 虚拟内存容量,这个oracle也有要求,不用担心此时的swap分区不够oracle的要求 .虚拟内存swap如何 ...
- LeetCode OJ-- Substring with Concatenation of All Words ***
https://oj.leetcode.com/problems/substring-with-concatenation-of-all-words/ 找S中子串,每个元素都在T中出现了,且所有T中元 ...
- cocoapods集成三方库遇到的坑
什么都不想说直接上图 这是最近在管理三方库时遇到头疼的问题,刚开始一直怀疑是cocoapods或者ruby的版本问题但是升级到最新版还是同样的错误,后来又怀疑是资源文件的问题但是在同一时间不同地点集成 ...