Springboot 1.5.16統合jdk 1.6_c 3 p 0を使用してプールを接続する_pagehelperページングプラグインを使用してプロジェクトを構築する


ネット上でたくさん探して、ずっと间违ってまた试して、试してまた间违って、最后についに1つの使うことができることを探し当てて、その上起动して间违いを报告しないバージョン、今pomを贴ってwebserviceを使ったため、webserviceの依存があって、自分の使うことだけを见て


    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        1.5.16.RELEASE
         
    
    com.are.yuecloud.cpsp
    ms_spa_service
    0.0.1-SNAPSHOT
    ms_spa
    sp    

    
        
        1.6
        7.0.59
        4.2.1.RELEASE
        

    


    

        
            org.springframework.boot
            spring-boot-starter
        
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.1.1
        
        
        
            com.github.pagehelper
            pagehelper-spring-boot-starter
            1.1.0
            
                
                    org.mybatis.spring.boot
                    mybatis-spring-boot-starter
                
            
        
        
            org.springframework.boot
            spring-boot-starter-jdbc
        
        
        
            mysql
            mysql-connector-java
        
        
        
            c3p0
            c3p0
            0.9.1.2
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            org.springframework.boot
            spring-boot-starter-web
        

        
        
            org.apache.tomcat
            tomcat-juli
            ${tomcat.version}
        
        
        
        
            org.apache.axis2
            axis2-transport-http
            1.7.7
        
        
            org.apache.axis2
            axis2-transport-local
            1.7.7
        
        
            org.apache.axis2
            axis2-adb
            1.7.7
        
        
        
            org.apache.axis2
            axis2-xmlbeans
            1.7.7
        
  

    

    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    1.6
                    1.6
                    utf8
                
            

            
                org.springframework.boot
                spring-boot-maven-plugin
            
			
            
                org.jvnet.jaxb2.maven2
                maven-jaxb2-plugin
                0.13.3
                
                    
                        
                            generate
                        
                    
                
                
                    WSDL
                    com.htairlines
                    ${basedir}/src/main/java
                    
                        
                            
                                
                                ${basedir}/src/main/resources/wsdl
                                
                                
                                    *.wsdl
                                
                            
                        
                    
                
            
            
        
    




次はアプリケーション.yml
server:
  port: 21081
  servlet:
    context-path: /cpsp/spa
spring:
  application:
    name: msspa
  profiles:
    active: sy
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8

logging:
  level:
    root: info


application-sy.yml
spring:
  datasource:
    type: com.mchange.v2.c3p0.ComboPooledDataSource
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/airdynamic
    username: root
    password: root

mapper:
  package:
    path: com.are.yuecloud.cpsp.spa.module.mapper #mapper      
  xml:
    config:
      path: mybatis/mapper/xml/*.xml #mapper xml   ,   /  .

logging:
  level:
    root: debug
    com.are.yuecloud.app.yuef.module.mapper: DEBUG


接続プール構成クラス
package com.are.yuecloud.cpsp.spa.config;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;
import java.beans.PropertyVetoException;

/**
 * @ClassName DataSource
 * @Description:
 * @Author: YangJunyi
 * @Copyright: Copyright (c) 2019 All rights reserved.
 * @Company: ARE Corporation, China, Ltd.
 * @Date 2020/1/2
 **/
@SpringBootConfiguration
public class DataSourceConfiguration {
	@Value("${spring.datasource.driver-class-name}")
	private String jdbcDriver;
	@Value("${spring.datasource.url}")
	private String jdbcUrl;
	@Value("${spring.datasource.username}")
	private String jdbcUser;
	@Value("${spring.datasource.password}")
	private String jdbcPassword;

	@Bean
	public DataSource createDataSource() throws PropertyVetoException {
		ComboPooledDataSource dataSource = new ComboPooledDataSource();

		dataSource.setDriverClass(jdbcDriver);
		dataSource.setJdbcUrl(jdbcUrl);
		dataSource.setUser(jdbcUser);
		dataSource.setPassword(jdbcPassword);
		//           
		dataSource.setAutoCommitOnClose(false);

		return dataSource;
	}
}


セッションファクトリ構成クラス
package com.are.yuecloud.cpsp.spa.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import javax.sql.DataSource;
import java.io.IOException;

/**
 * @ClassName SessionFactoryConfiguration
 * @Description:
 * @Author: YangJunyi
 * @Copyright: Copyright (c) 2019 All rights reserved.
 * @Company: ARE Corporation, China, Ltd.
 * @Date 2020/1/2
 **/
@SpringBootConfiguration
public class SessionFactoryConfiguration {
	@Value("${mapper.xml.config.path}")
	private String mapperXMLConfigPath;
	@Value("${mapper.package.path}")
	private String mapperPackagePath;
	@Autowired
	private DataSource dataSource;

	@Bean
	public SqlSessionFactoryBean createSqlSessionFactory() throws IOException {
		SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
		PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
		String packageXMLConfigPath = PathMatchingResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + mapperXMLConfigPath;

		//    mapper     XML      
		sqlSessionFactoryBean.setMapperLocations(resolver.getResources(packageXMLConfigPath));
		//      
		sqlSessionFactoryBean.setDataSource(dataSource);
		//    mapper       
		sqlSessionFactoryBean.setTypeAliasesPackage(mapperPackagePath);

		return sqlSessionFactoryBean;
	}
}


最後に起動クラスでテストします
        ConfigurableApplicationContext context = SpringApplication.run(SPAApplication.class, args);
        DataSource dataSource = context.getBean(DataSource.class);

        System.out.println(dataSource.getClass());
        System.out.println("========================================>");

最後にコンソールでc 3 p 0接続プールを見ればいいので、構成が有効であることを示します.