SpringBoot项⽬配置c3p0数据源
⼀、导⼊依赖
<dependency>
<groupId&hange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.5</version>
</dependency>
<dependency>
<groupId&batis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.3</version>
</dependency>
⼆、在application.yaml配置数据源信息
spring:
datasource:
url: jdbc:mysql://localhost:3306/hrsystem?serverTimezone=UTC
username: root
password: root
driver-class-name: sql.jdbc.Driver
type: hange.v2.c3p0.ComboPooledDataSource
acquireIncrement: 11
acquireRetryAttempts: 7
三、创建DataSourceConfig配置dataSource
nfig;
hange.v2.c3p0.ComboPooledDataSource;
import org.t.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import t.annotation.Bean;
import t.annotation.Configuration;
import t.annotation.Primary;
import javax.sql.DataSource;
@Configuration
public class DataSourceConfig {
@Bean
@Primary//⾃动装配时当出现多个Bean候选者时,被注解为@Primary的Bean将作为⾸选者,否则将抛出异常
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource(){
ate().type(ComboPooledDataSource.class).build();
}
}
四、启动类添加注解
@MapperScan("dao")//扫描mapper接⼝与配置⽂件,如果配置⽂件和接⼝不在同⼀个包下,要在配置⽂件中配置xml路径
@SpringBootApplication
public class HrsystemApplication {
public static void main(String[] args) {
spring怎么读取yamlSpringApplication.run(HrsystemApplication.class, args);
}
}
五、添加MyBatis配置
mybatis:
mapper-locations: classpath:mapper/*l
type-aliases-package: dao
#打印mybatis⽇志
configuration:
log-impl: org.apache.ibatis.logging.log4j2.Log4j2Impl
PS:遇到报错:java.io.FileNotFoundException: C:\Users\ABC\.m2\repository\com\mchange\c3p0\0.9.5.2\mchange-commons-java-0.2.11.jar (The system cannot find the file specified)
在C:\Users\ABC\.m2\repository\com\mchange\c3p0\0.9.5.2\放置mchange-commons-java-0.2.11.jar即可

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。