赞
踩
<!--mybatis多数据源--> <dependency> <groupId>com.baomidou</groupId> <artifactId>dynamic-datasource-spring-boot-starter</artifactId> <version>2.5.6</version> </dependency> <!--druid--> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.2.8</version> </dependency> <!--SQL Server JDBC驱动--> <dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>sqljdbc4</artifactId> <version>4.0</version> </dependency> <!--jdbc--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <!--mysql--> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <scope>runtime</scope> </dependency> <!-- mybatis plus --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.5.1</version> </dependency>
server: port: 8888 spring: main: allow-circular-references: true datasource: dynamic: primary: mysql_localhost #配置主数据源 datasource: mysql_localhost: # 数据源的名字,第二个数据源 url: jdbc:mysql://127.0.0.1:3306/library?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false&allowMultiQueries=true username: xxx password: xxxxxxxx driver-class-name: com.mysql.cj.jdbc.Driver sql_server_bbj: # 数据源的名字,第二个数据源 url: jdbc:sqlserver://127.0.0.1:1433;databaseName=test username: xxxx password: xxxxxx driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver #一定要加上,否则连接sqlserver不成功 druid: validation-query: SELECT 1 druid: initial-size: 1 max-active: 20 min-idle: 1 max-wait: 60000 #整合mybatis mybatis-plus: #别名设置 type-aliases-package: com.juyi.juyidockingplatform.entity.* #设置xml文件mapper的位置 classpath:代表的是resources mapper-locations: classpath:/mapper/*.xml # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用 configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
@Service
@DS("sql_server_bbj")
public class HagCar01ServiceImpl extends ServiceImpl<HagCar01Mapper, HagCar01> implements HagCar01Service {
}
@SpringBootTest
class JuyiDockingPlatformApplicationTests {
@Autowired
private BookBaseService bookBaseService;
@Test
void contextLoads2() {
System.out.println(hagCar01Service.list());
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。