1, add DataSourceAutoConfiguration class
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import javax.sql.DataSource;
@Configuration
public class DataSourceAutoConfiguration {
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.sqlite.JDBC");
dataSource.setUrl("");
dataSource.setUsername("");
dataSource.setPassword("");
returndataSource; }}Copy the code
2. Inject dataSource at the point of use and set sqLite file dynamically
@Autowired
private DriverManagerDataSource dataSource;
for (String dbFilePath : fileAddressList) {
dataSource.setUrl("jdbc:sqlite:"+ dbFilePath); BaseInfo baseInfo = service.queryBaseInfo(); . }Copy the code