`

mybatis configuration

阅读更多
<?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:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:task="http://www.springframework.org/schema/task"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
     http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
     http://www.springframework.org/schema/context
     http://www.springframework.org/schema/context/spring-context-3.2.xsd
     http://www.springframework.org/schema/aop
     http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
     http://www.springframework.org/schema/tx
     http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
     http://www.springframework.org/schema/jdbc
     http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
     http://www.springframework.org/schema/task
     http://www.springframework.org/schema/task/spring-task-3.2.xsd">

	<!-- auto-wired -->
	<context:component-scan base-package="com.lasho.mybatis" />
	
	<context:annotation-config />
	
	<!-- prop-placeHolder -->
	<bean id="placeholderProperties"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
		   <list>
				<value>classpath:db.properties</value>
		   </list>
		</property>
		<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
		<property name="ignoreUnresolvablePlaceholders" value="true" />
		<property name="order" value="1" />
		<property name="valueSeparator" value="?" />
	</bean>
	<!-- data-source -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName" value="${db.driverClassName}" />
		<property name="url" value="${db.url}" />
		<property name="username" value="${db.username}" />
		<property name="password" value="${db.password}" />
	</bean>
	<!-- transaction-manager -->
	<tx:annotation-driven transaction-manager="transcationManager" />
	<bean id="transcationManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<!-- define the SqlSessionFactory -->
	<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<!-- relative-path -->
		<property name="typeAliasesPackage" value="com.lasho.mybatis.domain" />
		<!-- mapper.xml locations -->
		<property name="mapperLocations" value="classpath*:com/lasho/mybatis/xmlmapper/*.xml"/>
	</bean>

	<!-- scan for mappers and let them be autowired -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<!-- interface-package[ if xml&interface in the same path ,mapperLocations could not set] -->
		<property name="basePackage" value="com.lasho.mybatis.mapper" /> 
		<!-- many sqlSessionFactory -->
		<property name="sqlSessionFactoryBeanName" value="sessionFactory" />
	</bean>
	
	<!-- special-mapper-proxy -->
	<!-- <bean id="codeMapper" class="org.mybatis.spring.mapper.MapperFactoryBean"> 
      <property name="mapperInterface" value="com.lasho.mybatis.mapper.CodeMapper" />
      <property name="sqlSessionFactory" ref="sessionFactory" /> 
    </bean> -->
	
</beans>


----------- maper interface ---------
2014-02-14 16:20:53,250 DEBUG [main] support.PathMatchingResourcePatternResolver (PathMatchingResourcePatternResolver.java:550)     - Looking for matching resources in directory tree [D:\work\sts3.3\myBatisDemo\target\classes\com\lasho\mybatis\mapper]
2014-02-14 16:20:53,250 DEBUG [main] support.PathMatchingResourcePatternResolver (PathMatchingResourcePatternResolver.java:612)     - Searching directory [D:\work\sts3.3\myBatisDemo\target\classes\com\lasho\mybatis\mapper] for files matching pattern [D:/work/sts3.3/myBatisDemo/target/classes/com/lasho/mybatis/mapper/**/*.class]
2014-02-14 16:20:53,251 DEBUG [main] support.PathMatchingResourcePatternResolver (PathMatchingResourcePatternResolver.java:351)     - Resolved location pattern [classpath*:com/lasho/mybatis/mapper/**/*.class] to resources [file [D:\work\sts3.3\myBatisDemo\target\classes\com\lasho\mybatis\mapper\CodeMapper.class]]
2014-02-14 16:20:53,252 DEBUG [main] mapper.ClassPathMapperScanner (ClassPathScanningCandidateComponentProvider.java:264)     - Identified candidate component class: file [D:\work\sts3.3\myBatisDemo\target\classes\com\lasho\mybatis\mapper\CodeMapper.class]
2014-02-14 16:20:53,252 DEBUG [main] mapper.ClassPathMapperScanner (ClassPathMapperScanner.java:161)     - Creating MapperFactoryBean with name 'codeMapper' and 'com.lasho.mybatis.mapper.CodeMapper' mapperInterface
------------ mapper location -----------
2014-02-14 16:20:53,427 DEBUG [main] support.PathMatchingResourcePatternResolver (PathMatchingResourcePatternResolver.java:550)     - Looking for matching resources in directory tree [D:\work\sts3.3\myBatisDemo\target\classes\com\lasho\mybatis\xmlmapper]
2014-02-14 16:20:53,428 DEBUG [main] support.PathMatchingResourcePatternResolver (PathMatchingResourcePatternResolver.java:612)     - Searching directory [D:\work\sts3.3\myBatisDemo\target\classes\com\lasho\mybatis\xmlmapper] for files matching pattern [D:/work/sts3.3/myBatisDemo/target/classes/com/lasho/mybatis/xmlmapper/*.xml]
2014-02-14 16:20:53,429 DEBUG [main] support.PathMatchingResourcePatternResolver (PathMatchingResourcePatternResolver.java:351)     - Resolved location pattern [classpath*:com/lasho/mybatis/xmlmapper/*.xml] to resources [file [D:\work\sts3.3\myBatisDemo\target\classes\com\lasho\mybatis\xmlmapper\CodeMapper.xml]]
2014-02-14 16:20:53,431 DEBUG [main] support.DefaultListableBeanFactory (AbstractAutowireCapableBeanFactory.java:1531)     - Invoking afterPropertiesSet() on bean with name 'sessionFactory'
-----------  instance  ----------
2014-02-14 16:20:53,925 DEBUG [main] spring.SqlSessionFactoryBean (Slf4jImpl.java:47)     - Parsed mapper file: 'file [D:\work\sts3.3\myBatisDemo\target\classes\com\lasho\mybatis\xmlmapper\CodeMapper.xml]'
2014-02-14 16:20:53,926 DEBUG [main] support.DefaultListableBeanFactory (AbstractBeanFactory.java:246)     - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
2014-02-14 16:20:53,927 DEBUG [main] support.DefaultListableBeanFactory (AbstractAutowireCapableBeanFactory.java:463)     - Finished creating instance of bean 'sessionFactory'
2014-02-14 16:20:53,927 DEBUG [main] support.DefaultListableBeanFactory (AbstractBeanFactory.java:246)     - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
2014-02-14 16:20:53,936 DEBUG [main] support.DefaultListableBeanFactory (AbstractAutowireCapableBeanFactory.java:1531)     - Invoking afterPropertiesSet() on bean with name 'codeMapper'
2014-02-14 16:20:53,936 DEBUG [main] support.DefaultListableBeanFactory (AbstractBeanFactory.java:246)     - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
2014-02-14 16:20:53,937 DEBUG [main] support.DefaultListableBeanFactory (AbstractAutowireCapableBeanFactory.java:463)     - Finished creating instance of bean 'codeMapper'
2014-02-14 16:20:53,938 DEBUG [main] support.DefaultListableBeanFactory (AbstractBeanFactory.java:246)     - Returning cached instance of singleton bean 'codeMapper'
2014-02-14 16:20:53,941 DEBUG [main] support.DefaultListableBeanFactory (AbstractBeanFactory.java:246)     - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
2014-02-14 16:20:53,942 DEBUG [main] annotation.AutowiredAnnotationBeanPostProcessor (AutowiredAnnotationBeanPostProcessor.java:433)     - Autowiring by type from bean name 'codeServiceImpl' to bean named 'codeMapper'
2014-02-14 16:20:53,943 DEBUG [main] support.DefaultListableBeanFactory (AbstractBeanFactory.java:246)     - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
2014-02-14 16:20:53,944 DEBUG [main] support.DefaultListableBeanFactory (AbstractAutowireCapableBeanFactory.java:463)     - Finished creating instance of bean 'codeServiceImpl'
分享到:
评论

相关推荐

    MyBatis学习笔记(一):MyBatis configuration和mapper xml配置总结

    本笔记将详细解析MyBatis的configuration配置文件和Mapper XML配置,帮助你深入掌握这两个核心组件。 首先,我们来看MyBatis的`configuration`配置文件。这个XML文件是MyBatis系统的核心,包含了MyBatis运行所需的...

    MyBatis异常-Property 'configLocation' not specified, using default MyBatis Configuration

    在使用MyBatis框架时,可能会遇到一个特定的异常:“Property 'configLocation' not specified, using default MyBatis Configuration”。这个异常通常表明MyBatis在启动时无法找到配置文件的位置,因此它会使用默认...

    mybatis_xml关联插件

    在Eclipse中,打开项目的“属性”(Properties)设置,找到"Mybatis"或"MyBatis Configuration"选项,这里可以添加Mybatis的配置文件(mybatis-config.xml),并指定Mapper XML文件所在的目录。这一步确保Eclipse知道...

    springboot 集成mybatis

    但如果我们有特殊需求,可以自定义`MybatisConfiguration`类,覆盖默认配置。 4. **编写Mapper接口和XML文件** MyBatis的核心是Mapper接口和对应的XML文件。在接口中声明SQL方法,然后在XML文件中编写具体的SQL...

    mybatis_3.5.9官方中文文档pdf

    MyBatis 官方中文文档 MyBatis 是一款优秀的持久层框架,它支持自定义 SQL、存储过程以及高级映射。MyBatis 免除了几乎所有的 JDBC 代码以及设置参数和获取结果集的工作。MyBatis 可以通过简单的 XML 或注解来配置...

    MyBatis3官方中文文档

    MyBatis还提供了不通过XML构建SqlSessionFactory的选项,如果开发者更愿意直接从Java程序中创建configuration,或者创建自己的configuration构建器,MyBatis同样提供了完整的配置类,以提供所有和XML文件相同功能的...

    mybatis的中文api文档

    而SqlSessionFactoryBuilder则可以从XML配置文件或一个预先定制的Configuration的实例构建出SqlSessionFactory的实例。从XML文件中构建SqlSessionFactory的实例非常简单,建议使用类路径下的资源文件进行配置。但是...

    mybatis-3-config.dtd mybatis-3-mapper.dtd

    在MyBatis中,`mybatis-3-config.dtd` 和 `mybatis-3-mapper.dtd` 是两个至关重要的DTD(Document Type Definition)文件,它们定义了MyBatis配置文件和映射文件的结构和规则。 首先,让我们深入了解一下`mybatis-3...

    asp.net搭建mybatis开发环境

    _userMapper = SqlMapper.Instance.SqlMapperFor&lt;MyBatis.Configuration.MyBatisConfigSection&gt;("DefaultConnection"); } public ActionResult Index() { var users = _userMapper.SelectAllUsers(); return ...

    MyBatis源码分析.pdf

    MyBatis的配置文件解析过程是MyBatis的核心组件之一,负责解析MyBatis的配置文件,并将其转换为 Configuration 对象。配置文件解析过程主要包括解析节点、节点、节点、节点、节点、节点等。 2.1.1 解析节点 节点...

    mybate对象映射

    5. **MyBatis配置文件(MyBatis Configuration)**:定义了数据源、事务管理器以及Mappers的配置。在Generator中,我们需要在配置文件中指定数据库连接信息,以便工具能正确连接到数据库并获取表信息。 6. **插件...

    手撕Mybatis源码,自己动手实现Mybatis

    2. **Configuration**: Configuration 存储了所有的Mybatis配置信息,包括映射文件、事务管理器、数据源等。在解析配置文件后,Mybatis 将元数据存储在这个对象中,用于后续的SQL执行。 3. **SqlSession**: ...

    springmybatis

    1.Configuration.xml 是 mybatis 用来建立 sessionFactory 用的,里面主要包含了数据库连接相关东西,还有 java 类所对应的别名,比如 &lt;typeAlias alias="User" type="com.yihaomen.mybatis.model.User"/&gt; 这个别名...

    Mybatis最新版-中文手册.pdf

    MyBatis是一款流行的Java持久层框架,它在使用上提供了灵活性和强大功能,尤其是在SQL操作方面。它是对JDBC操作的轻量级替代,并且可以自动处理对象和SQL语句之间的映射关系,简化了数据库编程工作。 首先,要开始...

    Mybatis源码分析.pdf

    MyBatis的设计模式也是其强大之处,例如工厂模式用于创建SqlSession,代理模式用于实现动态SQL,单例模式用于管理Configuration对象,责任链模式用于执行SQL等。理解这些设计模式可以帮助我们更好地理解MyBatis的...

    mybatis、mybatis详细设计、mybatis配置

    MyBatis是一款强大的Java持久层框架,它实现了SQL与Java代码的分离,使得开发者能够更加灵活地编写SQL语句,并且提供了丰富的映射机制,简化了数据库操作。本篇文章将深入探讨MyBatis的设计原理、详细配置以及在实际...

    mybatis配置dtd文件

    1. `&lt;configuration&gt;`:根元素,包含MyBatis的所有配置。 2. `&lt;properties&gt;`:用于管理外部属性文件,如数据库连接信息。 3. `&lt;settings&gt;`:设置MyBatis的运行时行为,如缓存、延迟加载等。 4. `&lt;typeAliases&gt;`:...

Global site tag (gtag.js) - Google Analytics