zoukankan      html  css  js  c++  java
  • 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。


    开发之路马虎不得啊

           

  • 相关阅读:
    java,jsp+mysql5.6搭建环境
    数据结构:栈的顺序存储结构
    开源 免费 java CMS FreeCMS1.2标签 config
    在Ubuntu中安装HP LaserJet 1020驱动
    iPad及BT4下的WEP破解实验与分析 | Network Security
    WEP&WPA Cracking on BT5/MAC [转]
    关于显示屏分辨率的问题
    Laravel5.1 路由 路由分组
    版本号/缓存刷新 laravel mix函数
    Laravel 中config的用法
  • 原文地址:https://www.cnblogs.com/yutingliuyl/p/7252752.html
Copyright © 2011-2022 走看看