Preface : If you're a little bit spring There is no basis for , I suggest you don't study springboot, At least one spring Project experience or self built spring Project relearning springboot, So you'll find that in spring What I don't understand in English , stay springboot Get some answers in .springboot The principle of “ Convention over configuration ”, So it's using springboot If there's a problem when you're on the road , There's no foundation , It's very difficult to solve the problem .

The goal is : take spring Configuration in the container of : Configuration of database , The timer configuration is converted to springboot in , Realization spring And springbooot Configuration and docking of .

Database configuration conversion :

spring The configuration of the database connection in is as follows

<!-- Database instance -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.mybatis.driver}" />
<property name="url" value="${jdbc.mybatis.url}" />
<property name="username" value="${jdbc.mybatis.username}" />
<property name="password" value="${jdbc.mybatis.password}" />
<!-- Initialize connection size -->
<property name="initialSize" value="10" />
<!-- Maximum number of connection pools -->
<property name="maxActive" value="1000" />
<!-- Connection pool maximum idle -->
<property name="maxIdle" value="30" />
<!-- Connection pool minimum idle -->
<property name="minIdle" value="10" />
<!-- Get connection maximum wait time -->
<property name="maxWait" value="2000" />

pringboot Configuration in

 @Bean(name = "dataSource")
public BasicDataSource myGetDataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setInitialSize(2); //
dataSource.setValidationQuery("SELECT 1");
return dataSource;

spring Configuration in

 <!-- spring and MyBatis Perfect integration , Unwanted mybatis Configuration map file -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath:springMVCmybatis/com/my/mapper/*.xml" />
<!-- <property name="typeAliasesPackage" value=""/> --> </bean>

springboot To configure sqlSessionFactoryBean, Corresponding to the above sping Of SqlSessionFactoryBean class


@Bean(name = "sqlSessionFactoryBean")
public SqlSessionFactoryBean myGetSqlSessionFactory(DataSource dataSource) throws Exception { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); // mapperLocations
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); try {
} catch (IOException e) {"sqlSessionFactoryBean Of setMapperLocations There is a problem ");
} // dataSource sqlSessionFactoryBean.setDataSource(dataSource); // SqlSessionFactory sessionFactory = sqlSessionFactoryBean.getObject(); return sqlSessionFactoryBean; }

spring Configuration in

 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="springMVCmybatis" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> </bean>

springboot Configuration in

import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Configuration; //<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
//<property name="basePackage" value="springMVCmybatis" />
//<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
//</bean> @Configuration
// This annotation needs to be loaded MybatisDbConfigure.class And then load MapperScanConfig This class
public class MapperScanConfig { public MapperScannerConfigurer myGetMapperScannerConfigurer() {
MapperScannerConfigurer myMapperScannerConfigurer = new MapperScannerConfigurer(); myMapperScannerConfigurer.setBasePackage("");
return myMapperScannerConfigurer;
} }

Conclusion :springboot It's through @Configuration To mark the custom configuration , Use... In configuration @Bean To add class functions and spring The configuration of the .xml Files work the same way , Both are the function of the container .

About this part of the configuration has been uploaded to my github On , Interested in or not understanding , You can log in to view .

springboot More articles about custom profiles

  1. springboot + Custom profile read

    Create a new profile src\main\resources\resources\ # Custom configuration files #System Encoding #File Upload Temp ...

  2. SpringBoot( Two ): SpringBoot Properties profile SpringBoot Multi environment profile SpringBoot Custom configuration files

    1. Properties profile There are two kinds , One is the key value pair properties Properties profile , One is yaml Format of the configuration file properties To configure : 2. Multi environment profile When we have multiple sets of configuration files in our project For example, the development of matching ...

  3. Springboot Read configuration files and custom configuration files

    1. establish maven engineering , stay pom Add dependencies to the file <parent> <groupId>org.springframework.boot</groupId> <a ...

  4. springboot Read custom profile node

    Today I share with you the reading of custom configuration information : There are plans for blogging in the near future , Write separately springboot Aspects and springcloud Articles on , because springboot There are a lot of expected chapters , such cloud My article needs ...

  5. SpringBoot To load a custom configuration file

    SpringBoot The default load profile name is and application.yml, If you need to use a custom profile , Through @PropertySource Annotation assignment . J ...

  6. Springboot And Custom profile and read profile

    This article is from [ Knowledge forest ] Read core configuration file The core profile refers to the resources In the root directory or application.yml The configuration file , There are two ways to read these two configuration files ...

  7. Springboot And Custom profile and read profile note : Do not underline strings in the configuration file . Configuration in progress key You can't underline ,value Sure ( The pit of underline , For two days .. In memory of )

    Be careful : Do not underline strings in the configuration file . Configuration in progress  key You can't underline ,value Sure FALSE . Examples that cannot be read : mySet .ABAP_AS_POOLED      =  ABAP_AS_WITH_P ...

  8. Springboot Several ways to read custom configuration files

    One . Read core configuration file The core profile refers to the resources In the root directory or application.yml The configuration file , There are two ways to read these two configuration files , It's all pretty simple . ...

  9. SpringBoot Read custom profile

    Custom configuration files bfxy.title=bfxy spring boot! bfxy.attr=12345 Profile class appc ...

Random recommendation

  1. JsonProperties Application of model return

    When using springMvc+Mybatis In the framework of . The database has been built , The database and the entity to be returned share one model. Everything is in order , It looks beautiful . The return code is as follows @RequestMapping(&qu ...

  2. jQuery Element traversal and element filtering

    jQuery Traversal, traversal down jQuery Ergodic up ergodic jQuery Traversal of the same level jQuery Filtering of traversal

  3. php use mysql Function error

    It's probably just because you forgot to pretend mysql Expand apt-get install php5-mysql

  4. c++ map Remove elements

    typedef std::map<std::string,float> StringFloatMap; StringFloatMap col1; StringFloatMap::itera ...

  5. Python Standard library 04 file management ( part os package ,shutil package )

    author :Vamei Source : Welcome to reprint , Please also retain this statement . thank you ! Under the operating system , Users can manage files by operating system commands , Reference resources linux Document management related orders ...

  6. php export csv

    public function doworks(){        // Output Excel The file header , Can handle user.csv Change it to the file name you want         header('Content-Type: appli ...

  7. git Use (4)-git The principle of the work area of the buffer and the command of modifying and deleting

    Article reprinted from : The blogger said that without my permission , Shall not be reproduced , Then don't post it , Make a note of the key parts 1. The staging area is G ...

  8. Excel Paste the content into DataGridView, DataGridView Paste the Excel

    void dataGridView1_KeyDown(object sender, KeyEventArgs e) { if (e.Control && e.KeyCode == Ke ...

  9. POJ 1904 King&#39;s Quest Strong connected components + Bipartite graph augmentation decision The God said it very well #include <iostream> #inc ...

  10. BZOJ 3672: [Noi2014] Ticket purchase ( The tree chain splits + Line segment tree + convex hull )

    s Make prefixes and ( To the root ), dp(i) = min(dp(j) + (s(i)-s(j))*p(i)+q(i)). We all do the chain situation ... Is to use the stack to maintain a lower convex hull , It's a stack of bullets when it's inserted , Query on convex hull / ...