与不同框架整合时mybatis的使用区别,框架自动封装几种情况(redis,active,solr)

http://www.xuebuyuan.com/910877.html多数据源怎么封装???

与不同框架整合时mybatis的使用区别,框架自动封装几种情况(redis,active,solr)

如何自动封装:

http://www.xuebuyuan.com/910877.html

1,通过工厂或者公模版id注入要封装的类中(这个可以适合类似多数据源的配置)

http://www.cnblogs.com/digdeep/p/4512368.html

  <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

      <property name="basePackage" value="net.aazj.mapper" />

      <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>

    </bean>

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

      <property name="basePackage" value="net.aazj.mapper2" />

      <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory_2"/>

    </bean>

2,相关框架直接根据容器内部的模板类或者工厂自动获取封装

spring集成 mybatis

  <bean id="sqlSessionFactory11" class="org.mybatis.spring.SqlSessionFactoryBean">

        <property name="dataSource" ref="dataSource" />

        <property name="typeAliasesPackage" value="com.esteel.*.bean"/> 

        <!-- typeAliasesPackage 为这个包下面的所有类生成别名,在配置文件中就可以直接用类名进行引用,而不用写全路径 -->

        <!-- <property name="typeAliasesPackage" value="com.esteel.system.bean,com.esteel.search" />

        <property name="mapperLocations" value="classpath:config_mybatis/*.xml" /> -->

        <property name="configLocation" value="classpath:config_spring/mybatis-config.xml" />

        <!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->

<property name="mapperLocations"  >

<array>

                <value> classpath:config_mybatis/**/*.xml</value>

            </array>

</property>

      

        <property name="plugins">

            <array>

              <bean class="com.github.pagehelper.PageHelper">

                    <property name="properties">

                        <value>

                            dialect=oracle

                            reasonable=true

                        </value>

                    </property> 

                </bean> 

               <!--  <bean class="com.github.abel533.mapperhelper.MapperInterceptor">

                    <property name="properties">

                        <value>

                            mappers=com.github.abel533.mapper.Mapper

                            ORDER=BEFORE

                           

                        </value>

                    </property>

                </bean> -->

            </array>

        </property> 

    </bean>

3,相关框架根据bean的特定id封装

比如:

缓存:

<!-- redis缓存管理器 -->

<bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager"

c:template-ref="jedisTemplate" /> 

纠正前面的:封装是直接封装工厂类的,一般框架的封装不会找模版,只有自定义的封装会通过模版实现封装(因为我们都是都过模版操作的)

猜你喜欢

转载自yuhuiblog6338999322098842.iteye.com/blog/2358022