1.在父工程pom.xml添加依赖:
<dependency><groupId>com.dameng</groupId><artifactId>DmJdbcDriver18</artifactId><version>8.1.1.193</version>
</dependency>
2.在nacos-config模块pom.xml添加依赖:
<dependency><groupId>com.dameng</groupId><artifactId>DmJdbcDriver18</artifactId><version>8.1.1.193</version>
</dependency>
3.修改nacos-console模块配置文件application.properties :
spring.sql.init.platform=dm
### Count of DB:
db.num=1### Connect URL of DB:
# db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
# db.user=nacos
# db.password=nacos
db.jdbcDriverName=dm.jdbc.driver.DmDriver
db.url.0=jdbc:dm://localhost:5236?schema=NACOS
db.user.0=SYSDBA
db.password.0=SYSDBA
4. 全局搜索这个ExternalDataSourceProperties.java类,添加如下信息:
//添加变量private String jdbcDriverName;public String getJdbcDriverName() {return jdbcDriverName;}public void setJdbcDriverName(String jdbcDriverName) {this.jdbcDriverName = jdbcDriverName;}//替换原来的方法List<HikariDataSource> build(Environment environment, Callback<HikariDataSource> callback) {List<HikariDataSource> dataSources = new ArrayList<>();Binder.get(environment).bind("db", Bindable.ofInstance(this));Preconditions.checkArgument(Objects.nonNull(num), "db.num is null");Preconditions.checkArgument(CollectionUtils.isNotEmpty(user), "db.user or db.user.[index] is null");Preconditions.checkArgument(CollectionUtils.isNotEmpty(password), "db.password or db.password.[index] is null");for (int index = 0; index < num; index++) {int currentSize = index + 1;Preconditions.checkArgument(url.size() >= currentSize, "db.url.%s is null", index);DataSourcePoolProperties poolProperties = DataSourcePoolProperties.build(environment);if (StringUtils.isEmpty(poolProperties.getDataSource().getDriverClassName())) {System.out.println("jdbcDriverName=" + jdbcDriverName);if (StringUtils.isNotEmpty(jdbcDriverName)) {poolProperties.setDriverClassName(jdbcDriverName);} else {poolProperties.setDriverClassName(JDBC_DRIVER_NAME);}System.out.println("dataSources=" + dataSources);}poolProperties.setJdbcUrl(url.get(index).trim());poolProperties.setUsername(getOrDefault(user, index, user.get(0)).trim());poolProperties.setPassword(getOrDefault(password, index, password.get(0)).trim());HikariDataSource ds = poolProperties.getDataSource();if (StringUtils.isEmpty(ds.getConnectionTestQuery())) {ds.setConnectionTestQuery(TEST_QUERY);}dataSources.add(ds);callback.accept(ds);}Preconditions.checkArgument(CollectionUtils.isNotEmpty(dataSources), "no datasource available");return dataSources;}
5. 修改DataSourceConstant.java类,添加变量:
public static final String DM = "dm";
6.修改ExternalConfigInfoPersistServiceImpl.java这个类的176和194行异常DuplicateKeyException改成DataIntegrityViolationException
7.nacos-datasource-plugin模块添加dm实现类,复制一个mysql包,然后把所有类名换成Dm,再把里面所有跟mysql相关的变量换成dm,如下:
同时把对应resources目录下的文件,添加如下内容:
8.在根目录运行:
mvn -Prelease-nacos -Dmaven.test.skip=true -Dcheckstyle.skip=true -Dcheckstyle.skip=true clean install -U
9.在nacos-distribution模块下会有生成的jar包,然后可以正常使用访问了。。。