在spingBoot中我们通常使用添加了@configuration注解的配置类,对项目所需依赖进行管理。
配置类配置druidDataSrouce,话不多说,上代码:
@Bean
public DataSrouce dataSrouce(){
DataSrouce dataSrouce = new DuridDataSrouce();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc.mysql:http://localhost:3306/xxx?useSSL=false&characterEncoding=utf-8&serverTimeZone=GMT");
dataSource.setUsername("root");
dataSource.setPassword("root");
return dataSource;
}
@Bean
public JdbcTemplate jdbcTemplate(){
JdbcTemplate jdbcTemplate=new JdbcTemplate();
jdbcTemplate.setDataSource(dataSource())
return jdbcTemplate;
}
@Bean
public PlatformTransactionManager platformTransactionManager(){
DataSourceTransactionManager manager=new DataSourceTransactionManager();
manager.setDataSource(dataSource());
return manager;
}