Boot of MyBatis

Source: Internet
Author: User

Especially note that this method is incompatible with starter, I used two ways to jerk off, and found that it couldn't run up!
Spring
DataSource
Driver-class-name:com.mysql.cj.jdbc.driver
url:jdbc:mysql://localhost:3306/mybatis?useunicode=true&characterencoding=utf-8&usessl=false& Servertimezone=utc
Username:root
password:123456
Dbcp
Max-active:20
Max-idle:20
max-wait:60000
Min-idle:1
initial-size:0



Package org.sselab.config;


Import Org.apache.commons.dbcp.BasicDataSource;
Import Org.apache.ibatis.session.SqlSessionFactory;
Import Org.mybatis.spring.SqlSessionFactoryBean;
Import Org.mybatis.spring.annotation.MapperScan;
Import org.springframework.beans.factory.annotation.Autowired;
Import org.springframework.boot.context.properties.ConfigurationProperties;
Import Org.springframework.context.annotation.Bean;
Import org.springframework.context.annotation.Configuration;
Import Org.springframework.core.io.support.PathMatchingResourcePatternResolver;
Import Org.springframework.jdbc.datasource.DataSourceTransactionManager;
Import Org.springframework.transaction.PlatformTransactionManager;
Import org.springframework.transaction.annotation.EnableTransactionManagement;
Import Org.springframework.transaction.support.ResourceTransactionManager;

Import Javax.sql.DataSource;

@Configuration
@EnableTransactionManagement
@MapperScan ("Org.sselab.mapper")
public class Mybatisconfig {

@Bean
@ConfigurationProperties (prefix = "Spring.datasource")
Public DataSource DataSource () throws Exception {
return new Basicdatasource ();
}

@Bean
Public Sqlsessionfactory Sqlsessionfactory () throws Exception {
Sqlsessionfactorybean Sqlsessionfactorybean = new Sqlsessionfactorybean ();
Sqlsessionfactorybean.setdatasource (DataSource ());
Pathmatchingresourcepatternresolver resolver = new Pathmatchingresourcepatternresolver ();
Sqlsessionfactorybean.setmapperlocations (Resolver.getresources ("Classpath:/mapper/*.xml"));
return Sqlsessionfactorybean.getobject ();
}

@Bean
Public Platformtransactionmanager TransactionManager () throws Exception {
return new Datasourcetransactionmanager (DataSource ());
}
}

Boot MyBatis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.