..

db.mybatis.config

config1:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:/configuration.xml" />
    <property name="mapperLocations"
    value="classpath:/mapping/*.xml" />
</bean>

 


 

config2:

@Bean
    public SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) throws Exception {

        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(dataSource);
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mapping/*.xml"));
        sqlSessionFactoryBean.setConfigLocation(resolver.getResource("classpath:/configuration.xml"));
        return sqlSessionFactoryBean.getObject();
    }

 

config3:

@Bean
    public SqlSessionFactory sqlSessionFactory() throws Exception {
        SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
        sessionFactory.setDataSource(dataSource());
        sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:com/springdemo/bean/UserMapper.xml"));
        sessionFactory.setTypeAliasesPackage("com.springdemo.bean");
        return sessionFactory.getObject();
    }

 

posted @ 2018-10-22 14:14  罗浩楠  阅读(192)  评论(0)    收藏  举报
..