求助:spring 整合ibatis启动报错
严重: Context initialization failedorg.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from S[color=#FF0000]ervletContext resource [/WEB-INF/sqlMapConfig.xml]; nested exception is java.net.ConnectException: Connection timed out: connect
at [/color]org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:408)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:509)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:427)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:215)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
... 23 more
--------------------编程问答-------------------- 补充一下: 连mysql 数据库 --------------------编程问答-------------------- 连接本机mysql --------------------编程问答-------------------- 严重: 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 'userDao' defined in file [D:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\MyStrutsTest\WEB-INF\classes\applicationContext-daos.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.hoo.dao.impl.UserDao]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.hoo.dao.impl.UserDao.<init>()
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:965)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
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:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
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:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.hoo.dao.impl.UserDao]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.hoo.dao.impl.UserDao.<init>()
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:70)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958)
... 28 more
Caused by: java.lang.NoSuchMethodException: com.hoo.dao.impl.UserDao.<init>()
at java.lang.Class.getConstructor0(Class.java:2706)
at java.lang.Class.getDeclaredConstructor(Class.java:1985)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:65)
... 29 more
2012-3-8 11:08:04 org.apache.catalina.core.ApplicationContext log
信息: Set web app root system property: 'webapp.root' = [D:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\MyStrutsTest\]
2012-3-8 11:08:04 org.apache.catalina.core.ApplicationContext log
信息: Initializing log4j from [D:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\MyStrutsTest\WEB-INF\log4j.properties]
2012-3-8 11:08:04 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2012-3-8 11:08:04 org.apache.catalina.core.StandardContext start
严重: Context [/MyStrutsTest] startup failed due to previous errors
2012-3-8 11:08:04 org.apache.catalina.core.ApplicationContext log
信息: Shutting down log4j
2012-3-8 11:08:04 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
2012-3-8 11:08:04 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2012-3-8 11:08:04 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2012-3-8 11:08:04 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/62 config=null
2012-3-8 11:08:04 org.apache.catalina.startup.Catalina start
信息: Server startup in 4662 ms
我的Spring3+mybatis3+struts2报错,大侠给看看呗 --------------------编程问答-------------------- 连接超时,你数据库服务开了没? --------------------编程问答-------------------- Could not instantiate bean class [com.hoo.dao.impl.UserDao]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.hoo.dao.impl.UserDao.<init>
你的错误是在这
不能实例化 com.hoo.dao.impl.UserDao, 没有定义初始化构造器。 --------------------编程问答--------------------
有没有详细步骤什么的? --------------------编程问答--------------------
Could not instantiate bean class [com.hoo.dao.impl.UserDao]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.hoo.dao.impl.UserDao.<init>
你的错误是在这
不能实例化 com.hoo.dao.impl.UserDao, 没有定义初始化构造器。 --------------------编程问答-------------------- public class UserDao extends SqlSessionTemplate implements IUserDao {
// public Integer deleteById(Integer userId) {
// dao.setMapperClass(UserMapper.class);
// user.setUserId(userId);
// try {
// dao.remove(user);
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// return 1;
// }
public UserDao(SqlSessionFactory sqlSessionFactory) {
super(sqlSessionFactory);
// TODO Auto-generated constructor stub
}
默认的构造函数不行啊,有错,不知道为什么 --------------------编程问答--------------------
数据库可以连的,没问题 --------------------编程问答--------------------
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">--------------------编程问答--------------------
<property name="driverClassName">
<value>net.sourceforge.jtds.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:jtds:sqlserver://localhost:1433/bmsh</value>
</property>
<property name="username">
<value>sa</value>
</property>
<property name="password">
<value>yourgame</value>
</property>
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>classpath:SqlMapConfig.xml</value>
</property>
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<?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">
<sqlMapConfig>
<settings cacheModelsEnabled="true" enhancementEnabled="true" lazyLoadingEnabled="true"
maxRequests="32" maxSessions="10" maxTransactions="5" useStatementNamespaces="true" />
<sqlMap resource="com/lhq/prj/bms/po/xml/Company.xml" />
<sqlMap resource="com/lhq/prj/bms/po/xml/Dept.xml" />
<sqlMap resource="com/lhq/prj/bms/po/xml/Duty.xml" />
<sqlMap resource="com/lhq/prj/bms/po/xml/User.xml" />
<sqlMap resource="com/lhq/prj/bms/po/xml/Book.xml" />
<sqlMap resource="com/lhq/prj/bms/po/xml/LoanLog.xml" />
<sqlMap resource="com/lhq/prj/bms/po/xml/Subject.xml" />
<sqlMap resource="com/lhq/prj/bms/po/xml/Category.xml" />
</sqlMapConfig>
<sqlMap namespace="User">
<typeAlias alias="user" type="com.lhq.prj.bms.po.User" />
<typeAlias alias="page" type="com.lhq.prj.bms.core.Page" />
<parameterMap class="user" id="pm_user_without_id">
<parameter property="emplName" javaType="string" jdbcType="VARCHAR" />
<parameter property="emplNo" javaType="string" jdbcType="VARCHAR" />
<parameter property="mobilePhone" javaType="string" jdbcType="VARCHAR" />
<parameter property="易做图" javaType="string" jdbcType="VARCHAR" />
<parameter property="age" javaType="integer" jdbcType="NUMBER" />
<parameter property="userName" javaType="string" jdbcType="VARCHAR" />
<parameter property="password" javaType="string" jdbcType="VARCHAR" />
<parameter property="companyId" javaType="integer" jdbcType="NUMBER" />
<parameter property="companyName" javaType="string" jdbcType="VARCHAR" />
<parameter property="deptId" javaType="integer" jdbcType="NUMBER" />
<parameter property="deptName" javaType="string" jdbcType="VARCHAR" />
<parameter property="dutyId" javaType="integer" jdbcType="NUMBER" />
<parameter property="dutyName" javaType="string" jdbcType="VARCHAR" />
<parameter property="manager" javaType="boolean" jdbcType="BIT" />
<parameter property="remark" javaType="string" jdbcType="VARCHAR" />
</parameterMap>
这些都是正确的配置 具体楼主可以自己修改 --------------------编程问答-------------------- 你配置文件是setter注入,類裏面卻是constructor注入。
注入失敗 --------------------编程问答--------------------
好的,我去试下 --------------------编程问答--------------------
不行啊,没有用啊 --------------------编程问答-------------------- spring实例化的时候貌似要有默认的构造函数才行,你在UserDao里面加个空的构造方法试试 --------------------编程问答--------------------
试过检查没? --------------------编程问答-------------------- 找到原因
配置文件放错地方,sqlMapConfig.xml当成bean定义文件加载了 --------------------编程问答-------------------- 注入 失败 连接超时 你看下是否 该提供的get set是否都提供了 看下配置文件是否都配对了 做事情认真详细点 往往小问题 很容易忽略
补充:Java , Java EE