import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
import org.springframework.data.jdbc.repository.config.JdbcRepositoryConfigExtension;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;
@SpringBootApplication
@EnableJdbcRepositories(basePackages = "com.yourpackage.mysql",
repositoryBaseClass = JdbcRepositoryConfigExtension.class)
@EnableJpaRepositories(basePackages = "com.yourpackage.tdengine",
repositoryBaseClass = JdbcRepositoryConfigExtension.class)
@EnableTransactionManagement
public class Application {
@Bean
public DataSource mysqlDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/yourdb");
dataSource.setUsername("yourusername");
dataSource.setPassword("yourpassword");
return dataSource;
}
@Bean
public DataSource tdEngineDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.taosdata.jdbc.TSDBDriver");
dataSource.setUrl("jdbc:TAOS://localhost:0/?charset=UTF-8");
dataSource.setUsername("yourusername");
dataSource.setPassword("yourpassword");
return dataSource;
}
@Bean
@Primary
public DataSource routingDataSource(DataSource mysqlDataSource, DataSource tdEngineDataSource) {
RoutingDataSource routingDataSource = new RoutingDataSource();
Map<Object, Object> dataSourceMap = new HashMap<>();
dataSourceMap.put("mysql", mysqlDataSource);
dataSourceMap.put("tdengine", tdEngineDataSource);
routingDataSource.setDefaultTargetDataSource(mysqlDataSource);
routingDataSource.setTargetData
评论已关闭