0 0

spring3.0+myBatis3.0.6整合???3

如题哪位会的 能给我讲讲么。本人第一次整合以前都是用的ssh 谢谢 不胜感激。。。

问题补充:
dunedain 写道
要mybatis-spring-1.0.x.jar(我用的是mybatis-spring-1.0.1.jar)
	<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="mapperLocations" value="classpath*:**/*Dao.xml" />
	</bean>

	<bean id="testDao" class="com.foo.TestDao">
		<property name="sqlSessionFactory" ref="sqlSessionFactoryBean" />
	</bean>


import com.cyou.base.web.mvc.dao.orm.BaseSqlSessionDaoSupport;

public class TestDao extends BaseSqlSessionDaoSupport{

}


我是这样用的,还有其他整合方法,看下官方文档吧

你好我整合报错了。我用的是spring3.0.6 myBatis3.0.6 mybatis-spring-1.0.3
整合保存严重: 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 'sqlSessionFactory' defined in ServletContext resource [/WEB-INF/classes/ApplicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [MyBatis_contextConfig.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
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:293)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
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:282)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
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:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:926)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:889)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
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:578)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.io.FileNotFoundException: class path resource [MyBatis_contextConfig.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:286)
at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:268)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 36 more

问题补充:
dunedain 写道
要mybatis-spring-1.0.x.jar(我用的是mybatis-spring-1.0.1.jar)
	<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="mapperLocations" value="classpath*:**/*Dao.xml" />
	</bean>

	<bean id="testDao" class="com.foo.TestDao">
		<property name="sqlSessionFactory" ref="sqlSessionFactoryBean" />
	</bean>


import com.cyou.base.web.mvc.dao.orm.BaseSqlSessionDaoSupport;

public class TestDao extends BaseSqlSessionDaoSupport{

}


我是这样用的,还有其他整合方法,看下官方文档吧

我吧我的配置文件复制给你看看是哪里错了。
//MyBatis配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD SQL Map Config 3.0//EN" 
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
<typeAlias alias="TestTableEntity"
type="main.java.com.entity.TestTable" />
</typeAliases>
<mappers>
<mapper resource="main/java/com/mapper/TestTableMapper.xml" />
</mappers>
</configuration>
//spring 配置文件
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- spring配置文件 -->
<!--读取connectJDBC.properties文件所在的位置 -->
<bean
class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="locations"
value="WEB-INF/classes/connectJDBC.properties">
</property>
</bean>
<!-- 读取connectJDBC.properties文件,配置数据源 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc_driver}"></property>
<property name="url" value="${jdbc_url}"></property>
<property name="username" value="${jdbc_userName}"></property>
<property name="password" value="${jdbc_passWord}"></property>
<!-- 数据库连接池配置 -->
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="main/java/com/myBatis/MyBatis_contextConfig.xml"></property>
<property name="mapperLocations" value="main/java/com/mapper/TestTableMapper.xml"></property>
<property name="dataSource" ref="dataSource"></property>
</bean>
</beans>
  结构图我也发了 帮忙看看 不胜感激
2012年2月02日 18:58
  • 大小: 22.4 KB

2个答案 按时间排序 按投票排序

0 0

采纳的答案

java.io.FileNotFoundException: class path resource [MyBatis_contextConfig.xml] cannot be opened because it does not exist 是找不到MyBatis_contextConfig.xml这个文件,试试这样<property name="configLocation" value="classpath:main/java/com/myBatis/MyBatis_contextConfig.xml"></property>,确认一下发布后能在这个路径中能找到文件

2012年2月11日 11:40
0 0

要mybatis-spring-1.0.x.jar(我用的是mybatis-spring-1.0.1.jar)

	<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="mapperLocations" value="classpath*:**/*Dao.xml" />
	</bean>

	<bean id="testDao" class="com.foo.TestDao">
		<property name="sqlSessionFactory" ref="sqlSessionFactoryBean" />
	</bean>


import com.cyou.base.web.mvc.dao.orm.BaseSqlSessionDaoSupport;

public class TestDao extends BaseSqlSessionDaoSupport{

}


我是这样用的,还有其他整合方法,看下官方文档吧

2012年2月05日 16:12

相关推荐

Global site tag (gtag.js) - Google Analytics