2 u011252234 u011252234 于 2014.01.16 17:31 提问

maven spring和ibatis的整合遇到的问题

下面两个是我的spring-ibatis的整合,另一个是sqlmapconfig.xml
<?xml version="1.0" encoding="UTF-8"?>

<!-- 配置数据源 -->
<bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
    <property name="url" value="${jdbc_url}" />
    <property name="username" value="${jdbc_username}" />
    <property name="password" value="${jdbc_password}" />

    <!-- 初始化连接大小 -->
    <property name="initialSize" value="2" />
    <!-- 连接池最大使用连接数量 -->
    <property name="maxActive" value="20" />
    <!-- 连接池最大空闲 -->
    <property name="maxIdle" value="20" />
    <!-- 连接池最小空闲 -->
    <property name="minIdle" value="1" />
    <!-- 获取连接最大等待时间 -->
    <property name="maxWait" value="60000" />
    <property name="validationQuery" value="${validationQuery}" />
    <property name="testOnBorrow" value="false" />
    <property name="testOnReturn" value="false" />
    <property name="testWhileIdle" value="true" />

    <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
    <property name="timeBetweenEvictionRunsMillis" value="60000" />
    <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
    <property name="minEvictableIdleTimeMillis" value="25200000" />

    <!-- 打开removeAbandoned功能 -->
    <property name="removeAbandoned" value="true" />
    <!-- 1800秒,也就是30分钟 -->
    <property name="removeAbandonedTimeout" value="1800" />
    <!-- 关闭abanded连接时输出错误日志 -->
    <property name="logAbandoned" value="true" />
    <property name="filters" value="mergeStat" />
</bean> **strong text** 

 **<!-- ibatis sqlMapClient 配置  让spring来管理SqlMapClient对象-->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    <property name="configLocation" value="classpath:sqlmapconfig.xml"/>
    <property name="dataSource" ref="dataSource"/>
</bean>** 
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>

<!-- 注解方式配置事物 -->
<!-- <tx:annotation-driven transaction-manager="transactionManager" /> -->

<!-- 拦截器方式配置事物 -->
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="add*" propagation="REQUIRED" />
        <tx:method name="append*" propagation="REQUIRED" />
        <tx:method name="insert*" propagation="REQUIRED" />
        <tx:method name="save*" propagation="REQUIRED" />
        <tx:method name="update*" propagation="REQUIRED" />
        <tx:method name="modify*" propagation="REQUIRED" />
        <tx:method name="edit*" propagation="REQUIRED" />
        <tx:method name="delete*" propagation="REQUIRED" />
        <tx:method name="remove*" propagation="REQUIRED" />
        <tx:method name="repair" propagation="REQUIRED" />
        <tx:method name="delAndRepair" propagation="REQUIRED" />

        <tx:method name="get*" propagation="SUPPORTS" />
        <tx:method name="find*" propagation="SUPPORTS" />
        <tx:method name="load*" propagation="SUPPORTS" />
        <tx:method name="search*" propagation="SUPPORTS" />
        <tx:method name="datagrid*" propagation="SUPPORTS" />

        <tx:method name="*" propagation="SUPPORTS" />
    </tx:attributes>
</tx:advice>
<aop:config>
    <aop:pointcut id="transactionPointcut" expression="execution(* hyl.service..*Impl.*(..))" />
    <aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" />
</aop:config>


<!-- 配置druid监控spring jdbc -->
<bean id="druid-stat-interceptor" class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor">
</bean>
<bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut" scope="prototype">
    <property name="patterns">
        <list>
            <value>hyl.service.*</value>
        </list>
    </property>
</bean>
<aop:config>
    <aop:advisor advice-ref="druid-stat-interceptor" pointcut-ref="druid-stat-pointcut" />
</aop:config>

这是sqlmapconfig.xml的配置

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

<!DOCTYPE sqlMapConfig

PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"

"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">

<sqlMap resource="classpath:hyl/sqlMap/TUSER_SqlMap.xml" />

加粗的是后台提示的错误,嵌套错误:下面是错误的提示
[org.springframework.context.support.ClassPathXmlApplicationContext]Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@bfea1d: startup date [Thu Jan 16 17:17:54 CST 2014]; root of context hierarchy
[org.springframework.beans.factory.xml.XmlBeanDefinitionReader]Loading XML bean definitions from class path resource [spring.xml]
[org.springframework.beans.factory.xml.XmlBeanDefinitionReader]Loading XML bean definitions from class path resource [spring-ibatis.xml]
[org.springframework.beans.factory.config.PropertyPlaceholderConfigurer]Loading properties file from class path resource [config.properties]
[org.springframework.beans.factory.support.DefaultListableBeanFactory]Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1bbd7b2: defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,dataSource,sqlMapClient,transactionManager,transactionAdvice,org.springframework.aop.config.internalAutoProxyCreator,transactionPointcut,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,druid-stat-interceptor,druid-stat-pointcut,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#1,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy
[com.alibaba.druid.pool.DruidAbstractDataSource]maxIdle is deprecated
[com.alibaba.druid.pool.DruidDataSource]{dataSource-1} inited
[org.springframework.beans.factory.support.DefaultListableBeanFactory]Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1bbd7b2: defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,dataSource,sqlMapClient,transactionManager,transactionAdvice,org.springframework.aop.config.internalAutoProxyCreator,transactionPointcut,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,druid-stat-interceptor,druid-stat-pointcut,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#1,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy
[com.alibaba.druid.pool.DruidDataSource]{dataSource-1} closed
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlMapClient' defined in class path resource [spring-ibatis.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [sqlmapconfig.xml]; nested exception is com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: java.io.IOException: Could not find resource classpath:hyl/sqlMap/TUSER_SqlMap.xml
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:591)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93)
at hyl.test.Test.main(Test.java:13)
Caused by: org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [sqlmapconfig.xml]; nested exception is com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: java.io.IOException: Could not find resource classpath:hyl/sqlMap/TUSER_SqlMap.xml
at org.springframework.orm.ibatis.SqlMapClientFactoryBean.buildSqlMapClient(SqlMapClientFactoryBean.java:341)
at org.springframework.orm.ibatis.SqlMapClientFactoryBean.afterPropertiesSet(SqlMapClientFactoryBean.java:291)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 12 more
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: java.io.IOException: Could not find resource classpath:hyl/sqlMap/TUSER_SqlMap.xml
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:62)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:62)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:55)
at org.springframework.orm.ibatis.SqlMapClientFactoryBean.buildSqlMapClient(SqlMapClientFactoryBean.java:338)
... 15 more
Caused by: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: java.io.IOException: Could not find resource classpath:hyl/sqlMap/TUSER_SqlMap.xml
at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:123)
at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:84)
at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:102)
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:72)
at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:60)
... 18 more
Caused by: java.io.IOException: Could not find resource classpath:hyl/sqlMap/TUSER_SqlMap.xml
at com.ibatis.common.resources.Resources.getResourceAsStream(Resources.java:110)
at com.ibatis.common.resources.Resources.getResourceAsStream(Resources.java:95)
at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser$10.process(SqlMapConfigParser.java:249)
at com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:121)
... 22 more

下面的是我TUSER_SqlMap.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >









select ID, NAME, PWD, CREATEDATATIME, MODIFYDATATIME
from TUSER
where ID = #id:VARCHAR#


delete from TUSER
where ID = #id:VARCHAR#


insert into TUSER (ID, NAME, PWD, CREATEDATATIME, MODIFYDATATIME)
values (#id:VARCHAR#, #name:VARCHAR#, #pwd:VARCHAR#, #createdatatime:DATE#,
#modifydatatime:DATE#)


insert into TUSER


ID


NAME


PWD


CREATEDATATIME


MODIFYDATATIME

)

values


#id:VARCHAR#


#name:VARCHAR#


#pwd:VARCHAR#


#createdatatime:DATE#


#modifydatatime:DATE#

)



update TUSER


NAME = #name:VARCHAR#


PWD = #pwd:VARCHAR#


CREATEDATATIME = #createdatatime:DATE#


MODIFYDATATIME = #modifydatatime:DATE#


where ID = #id:VARCHAR#


update TUSER
set NAME = #name:VARCHAR#,
PWD = #pwd:VARCHAR#,
CREATEDATATIME = #createdatatime:DATE#,
MODIFYDATATIME = #modifydatatime:DATE#
where ID = #id:VARCHAR#

这个问题困扰我一周了,希望各位能帮助下,若需要我的项目请与我联系:QQ632105841,再次谢谢!

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
maven+spring+springMVC+iBatis的整合
pom.XMl的配置 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 mcm.yuehou.maicaim hehe war 0.0.1-SNAPSHOT hehe Maven Webapp http://maven.ap
Maven整合Spring-MVC+IBatis
---------------------------------------------------------------------------------------------------------大神绕道-------------------------------------------------------------------------------------------
maven 整合spring springmvc ibatis
maven 整合spring springmvc ibatis
maven+ibatis+spring mvc环境搭建
一、创建新的maven项目:         二、目录结构: 三、建立各个包及类: User.java package com.demo.entity; public class User { private Integer id; private String userName; private String password; pu
Spring与iBATIS的集成
Spring与iBATIS的集成 <br>iBATIS似乎已远离众说纷纭的OR框架之列,通常人们对非常流行的Hibernate情有独钟。但正如Spring A Developer's Notebook作者Bruce Tate 和Justin Gehtland所说的那样,与其他的OR框架相比,iBATIS独辟蹊径“iBATIS不是试图从根本上掩盖SQL,实际上,它是在拥抱SQL。”<br><br>但别犯愁:SQL本身具备了一些重要的功能,并且通过模板的使用,在Spring应用中采用iBATIS显得轻而易举。在此摘录中,两位作者将和你一起安装iBATIS并将其集成进你的Spring应用中。他们也阐明了怎样取得你已编写的SQL语句及把他们映射给iBATIS使用的Bean。最后,还讨论了iBATIS的优缺点,及为什么是这样的一种方式,即所谓的“在完全OR与JDBC之间的一个幽雅的折衷。”<br><br>就象Developer's Notebook 系列中所有的书一样,你将由直接的且实用的方式获得信息,这些信息包含了完成你工作所需的细节。换言之:“一切来自实战,没有讲义。”
系统架构搭建-Maven Spring Ibatis
文章待续: 前序工作:     eclipse 编码设置:http://blog.csdn.net/wodwl/article/details/7737620     eclipse 自动补全设置:http://blog.csdn.net/wodwl/article/details/7717938     eclipse xml提示设置:http://blog.csdn.net/w
Java - maven+ibatis+spring mvc环境搭建
1.准备工作: 要搭建者这样的一个框架 a.首先要创建一个maven的项目,然后转成web项目 具体的教程参考我以前的一个文章: Java-Eclipse使用maven搭建spring mvcb.要安装好mysql数据库 安装教程: http://blog.csdn.net/linpeng_1/article/details/699486822.开启搭建详细的教程: 教程地址:http:
spring2.5+struts2+ibatis整合jar包
struts 2应用只需要下列几个必须的jar:  commons-logging-1.0.4.jar  freemarker-2.3.8.jar  ognl-2.6.11.jar  struts2-core-2.0.11.jar  xwork-2.0.4.jar ibatis2 应用只需要下列几个必须的jar:  commons-collections.jar  commons-
Spring MVC + Ibatis架构原理分析
<br />1: spring框架介绍<br />Spring框架是一个分层架构,由7个定义好的模块组成。Spring模块构建在核心容器上,核心容器定义了创建、配置和管理bean的方式。<br />每个模块的功能如下:<br />核心容器:核心容器提供Spring框架的基本功能。核心容器的主要组件是BeanFactory,它是工厂模式的实现,BeanFactory使用控制反转(IoC)模式将应用程序的配置和依赖性规范与实际的应用代码分开。<br />Spring上下文:Spring上下文是一个配置文件,向S
idea搭建的spring+springMVC+ibatis+maven框架
由于最近需要用到IntelliJ IDEA 来写ssm项目,而之前自己用的一直是eclipse,网上找了很多都没有找到相关资源,有教程但是自己跟着搭建发现运行不了。所以自己就抽时间搭建了一下,并且测试了多次没有问题。现在分享出来供大家学习使用,仅供新手学习,大神勿喷!下载后解压后用idea打开就可以用。我用的idea版本是IntelliJ IDEA 15.0.2。