spring3.1.1+ibatis3.1.1+struts2.2.3框架搭建报错

我的 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"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:context="http://www.springframework.org/schema/context"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.1.xsd
   http://www.springframework.org/schema/tx
   http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"
   default-autowire="byName">
 
 <!--配置文件导入 -->
 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="location">
   <value>classpath:jdbc.properties</value>
  </property>
 </bean>

 <!--  数据源 -->
 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName" value="${mysql.driver}"></property>
  <property name="url" value="${mysql.url}"></property>
  <property name="username" value="${mysql.user}"></property>
  <property name="password" value="${mysql.password}"></property>
  <property name="maxActive" value="${mysql.maxActive}"></property>
  <property name="maxIdle" value="${mysql.maxIdle}"></property>
  <property name="maxWait" value="${mysql.maxWait}"></property>
 </bean>
 
 <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
  <property name="configLocation" value="classpath:sqlmapConfig.xml" />
     <property name="dataSource" ref="dataSource" />   
 </bean>

 


 
 <bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
  <property name="sqlMapClient" ref="sqlMapClient" />
 </bean>
   
</beans>

 

 

 

 

这是启动项目报的错:

 

2012-6-26 10:41:14 org.apache.catalina.core.AprLifecycleListener init
信息: Loaded APR based Apache Tomcat Native library 1.1.20.
2012-6-26 10:41:14 org.apache.catalina.core.AprLifecycleListener init
信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
2012-6-26 10:41:16 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
信息: Using a shared selector for servlet write/read
2012-6-26 10:41:16 org.apache.coyote.http11.Http11NioProtocol init
信息: Initializing Coyote HTTP/1.1 on http-8085
2012-6-26 10:41:16 org.apache.coyote.ajp.AjpAprProtocol init
信息: Initializing Coyote AJP/1.3 on ajp-8088
2012-6-26 10:41:16 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 2056 ms
2012-6-26 10:41:16 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2012-6-26 10:41:16 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.26
2012-6-26 10:41:16 org.apache.catalina.startup.HostConfig deployDescriptor
信息: Deploying configuration descriptor host-manager.xml
2012-6-26 10:41:16 org.apache.catalina.startup.HostConfig deployDescriptor
信息: Deploying configuration descriptor manager.xml
2012-6-26 10:41:16 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory docs
2012-6-26 10:41:16 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory examples
2012-6-26 10:41:17 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2012-6-26 10:41:17 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2012-6-26 10:41:17 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory mySSI
2012-6-26 10:41:17 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
2012-6-26 10:41:19 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlMapClient' defined in class path resource [applicationContext.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: org.xml.sax.SAXParseException: Element type "sqlMap" must be declared.
 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:567)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
 at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
 at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1041)
 at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:964)
 at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
 at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
 at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
 at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
 at org.apache.catalina.core.StandardService.start(StandardService.java:519)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
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: org.xml.sax.SAXParseException: Element type "sqlMap" must be declared.
 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)
 ... 36 more
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: org.xml.sax.SAXParseException: Element type "sqlMap" must be declared.
 at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:62)
 at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:106)
 at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:95)
 at org.springframework.orm.ibatis.SqlMapClientFactoryBean.buildSqlMapClient(SqlMapClientFactoryBean.java:338)
 ... 39 more
Caused by: org.xml.sax.SAXParseException: Element type "sqlMap" must be declared.
 at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
 at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
 at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
 at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
 at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidator.java:1929)
 at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java:785)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1343)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2756)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
 at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
 at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:232)
 at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
 at com.ibatis.common.xml.NodeletParser.createDocument(NodeletParser.java:189)
 at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:59)
 ... 42 more
2012-6-26 10:41:19 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2012-6-26 10:41:19 org.apache.catalina.core.StandardContext start
严重: Context [/mySSI] startup failed due to previous errors
2012-6-26 10:41:19 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
2012-6-26 10:41:19 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
严重: A web application registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

 

aa1aa3
爱上一条鱼 木有demo啊 贴个别人的 http://download.csdn.net/detail/jkjlovezy_4/3519436http://download.csdn.net/detail/yigengu/3636433
7 年多之前 回复
lsd747490952
lsd747490952 把分给你了,asyty有没有这样的demo呀,要有发我一份:747490952@qq.com
7 年多之前 回复
lsd747490952
lsd747490952 我弄的也有点晕了,有空再试试吧,谢谢你了!
7 年多之前 回复
aa1aa3
爱上一条鱼 你在找找和maper有关的类看看木有有错吧
7 年多之前 回复
aa1aa3
爱上一条鱼 话说你demo.xml那个 头部换成 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 然后吧 话说你spring里有配置org.mybatis.spring.mapper.MapperFactoryBean这个类么。。怎么会在这个类里报错的。。。
7 年多之前 回复
lsd747490952
lsd747490952 <bean id="sqlMapClient" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="configLocation" value="classpath:sqlmapConfig.xml" /> <property name="dataSource" ref="dataSource" /> </bean> <bean id="sqlMapClientTemplate" class="org.mybatis.spring.mapper.MapperFactoryBean"> <property name="sqlMapClient" ref="sqlMapClient" /> </bean> 后来在网上找的,换成它了,里面有这个类,但这样就是DAO指定注入了,我手里有个低版本的SSI,搭新的是想测测性能,和做为自己做的功能总结到这框里.先这样吧,不成,我就用ibatis2.5了,谢谢大家了.
7 年多之前 回复
aa1aa3
爱上一条鱼 之前一直说sqlmapConfig.xml的配置有问题。。然后你一直没贴这个文件的配置 =。=
7 年多之前 回复
aa1aa3
爱上一条鱼 参考下这个 http://nirvana1988.iteye.com/blog/971246
7 年多之前 回复
aa1aa3
爱上一条鱼 囧哩个囧 还木搞定 贴sqlmapConfig.xml的配置吧。。
7 年多之前 回复
works001
works001 你可以看下:http://www.cnblogs.com/wushiqi54719880/archive/2011/07/27/2117944.html
7 年多之前 回复
works001
works001 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
7 年多之前 回复

5个回答

[code="java"]



[/code]
这个类里sqlMapClientTemplate有setSqlMapClient这个方法么?java代码里调用下sqlMapClientTemplate.getSqlMapClient()或者setSqlMapClient看看

错误信息是说SqlMapClientTemplate里属性sqlMapClient的set方法不对啊

试下:
把ibatis头部

[code="java"]<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">[/code]

改为

[code="java"]<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">[/code]

[code="java"] Error creating bean with name 'sqlMapClient' defined in class path resource [applicationContext.xml][/code] --》 sqlMapClient这个类类初始化挂了么。。。
[code="java"]
NestedIOException: Failed to parse config resource: class path resource [sqlmapConfig.xml];[/code] --》 class path resource [sqlmapConfig.xml]这xml初始化挂了

[code="java"] Element type "sqlMap" must be declared.[/code] --》 sqlMap必须声明

sqlmapConfig.xml头上加上这个试试

[code="java"]<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">[/code]

头部的 http://mybatis.org/dtd/mybatis-map-3-config.dtd 没找到啊

不是应该是xxxxx PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN"

"http://ibatis.apache.org/dtd/ibatis-3-config.dtd"

aa1aa3
爱上一条鱼 给个例子好了 http://lyb520320.iteye.com/blog/5866283.0的话 头也应该是ibatis 怎么会是myibatis。。。。
7 年多之前 回复
aa1aa3
爱上一条鱼 去掉不报错 所以说是sqlmapConfig.xml有问题啊 不是过改这个xml的头么 不行?。。。
7 年多之前 回复

ibatis的xml文件解析不正确,

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!