东方通和达梦数据库与springboot项目的代码适配

1-东方通项目的部署:

1.1-在相关的代码分支将项目打包成war包

1.2-将war放到对应的目录webapps:/app/TongWeb7.0.4.7_Enterprise_Linux/webapps

ps -ef | grep Tongweb可以查询到东方通的安装目录:

从查询结果找到-Dpid_file_path=/app/TongWeb7.0.4.7_Enterprise_Linux/tongweb.pid

其中/app/TongWeb7.0.4.7_Enterprise_Linux/为安装目录

1.3-进入东方通的可视化控制台:http://东方通安装地址IP:9060/console/restthanos/

一般默认的密码thanos/ thanos123.com

1.4-设置HTTP通道【应用端口】:

控制台左侧:WEB容器——>HTTP通道管理——>创建HTTP通道

填写通道名称【唯一标识】,应用访问的端口【前提是该端口未被占用】,虚拟主机可以选择系统默认的serve,其他保持默认选项即可。

1.5-设置虚拟主机:

控制台左侧:WEB容器——>虚拟主机配置——>创建虚拟主机

正常填写虚拟主机名称,通道列表选择1.4创建的通道,访问日志可以选择开启,然后填写日志路径【建议为logs/access/项目名称】,其他保持默认选项即可。

创建虚拟主机完成后,可以将1.4通道的默认主机修改为为1.5创建的主机。

1.6-部署应用:

控制台左侧:应用管理——>部署应用

文件位置选择服务器,然后在列表中找项目war包,然后开始部署

1.7-日志:

部署应用启动日志查看,在安装目录对应的log目录下:

/app/TongWeb7.0.4.7_Enterprise_Linux/logs/server.log【所有的应用日志,可以查看部署是否成功以及部署失败的详细代码】

部署应用的请求日志,这个需要在对应的项目代码中配置logback:

/app/TongWeb7.0.4.7_Enterprise_Linux/bin/logs/logback/databoard.log

2-东方通和达梦数据库与springboot项目代码适配问题:

2.1-东方通中识别不了tomcat相关的配置,注释启动类中关于Tomcat相关的配置

//注释相关代码
@Bean
public TomcatServletWebServerFactory tomcatServletWebServerFactory(){
        // 修改内置的 tomcat 容器配置TomcatServletWebServerFactorytomcatServlet=newTomcatServletWebServerFactory();
        tomcatServlet .addConnectorCustomizers(
                (TomcatConnectorCustomizer) connector -> connector.setProperty("relaxedQueryChars", "[]{}")
        );
        return tomcatServlet ;
    }

2.2-部署在东方通中容器,找不到需要读取的配置文件application.yml:

在启动目录下的resource下的META_INF下添配置文件spring.factories

org.springframework.boot.env.EnvironmentPostProcessor=com.sf.gis.boot.config.DataboardEnvironmentPostProcessor
和配置启动类DataboardEnvironmentPostProcessor
package com.sf.gis.boot.config;

import java.io.File;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.stereotype.Component;

@Component@Slf4jpublicclassDataboardEnvironmentPostProcessorimplementsEnvironmentPostProcessor {
    privatestaticfinalStringmainYml="application-databoard.yml";
    publicvoidpostProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
        Stringparent= System.getProperty("application.path");
        FileparentFile=newFile(parent);
        if(!parentFile.exists()){
            thrownewNullPointerException("外部配置文件为空");
        }else {
            log.info("开始加载外部配置文件");
            Filemain= loadYml(parent);
            YamlPropertiesFactoryBeanmainYml=newYamlPropertiesFactoryBean();
            mainYml.setResources(newFileSystemResource(main));
            MutablePropertySourcespropertySources= environment.getPropertySources();
            propertySources.addFirst(newPropertiesPropertySource(main.getName(), mainYml.getObject()));

        }
    }

    public File loadYml(String parent){
        Stringmain= parent + File.separator + mainYml;
        returnnewFile(main);
    }

    public File loadMainYml(String parent){
        YamlPropertiesFactoryBeanyaml=newYamlPropertiesFactoryBean();
        Stringmain= parent + File.separator + mainYml;
        FilemainFile=newFile(main);
        if(mainFile.exists()){
            yaml.setResources(newFileSystemResource(mainFile));
            Stringactive= yaml.getObject().getProperty("spring.profiles.active");
            StringenvFile= parent + File.separator + "application-" + active + ".yml";
            returnnewFile(envFile);
        }
        returnnull;
    }
}

东方通配置:

启动参数配置->其他jvm参数配置:-Dapplication.path=${TongWeb_Base}/config

2.3-达梦数据库与mybatisplus适配中在QueryWrapper查询时不支持数组作为查询参数,建议用List替换

//Cause: dm.jdbc.driver.DMException: 不支持该数据类型:
QueryWrapper<StdAddrPushRecord> wrapper = new QueryWrapper<>();
wrapper.in("push_result",newint[]{1,2})

建议修改为:
List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
wrapper.in("push_result",list)

2.4-使用Spring Data JDBC中间件遇到了类似的“无效的列”问题,查询无问题,但是修改/新增/删除会出现无效的列错误:

由于达梦数据库的依赖版本过低,导致与mybatisplus适配不是很好,升级一下依赖版本依赖修复:在pom文件中更换依赖<version>8.1.2.141</version>到 <version>8.1.2.79</version>

PS:如果在pom文件更换了依赖的情况下仍然出现“无效的列”问题,可能原因是war中的lib依赖有两个版本,需要重新打包。

<dependency><groupId>com.dameng</groupId>
    <artifactId>DmJdbcDriver18</artifactId>
    <version>8.1.2.79</version>
</dependency>

2.5-达梦数据库不支持表名被``包括,这时会出现SQL查询错误:

---2007: 第 1 行, 第 19 列[`]附近出现错误: 语法分析出错
select * from `student` wherenamelike'%滕%'

2.6-达梦数据库中不支持order by 列名!=1 这种形式的sql:

可以对sql进行修改,使用order by FIELD(列名,2,3,4,1)函数这种形式指定排序规则

--mysql
select * from student orderby group_num != 1
--dm
select * from student orderby FIELD(group_num,2,3,4,1)

2.7-达梦数据库中关于大小写敏感问题:

select case_sensitive【结果为1则大小写敏感,为0则大小写不敏感】

在代码适配中,如果查询时列名的别名没有被双引号包括,则查出来的时候默认都是大写,从达梦返回到java结果集会全部显示为小写。

select package_id as packageId, count(1) as totalCount from t_task_package groupby package_id 

如果此时返回的是一个List<Map>结果:

对map通过map.get("packageId")或者map.get("totalCount")会查询不到数据

此时通过debug可以看到map中的key全是小写。

PS:如果想要保持返回的字段严格区分大小写,需要将别名或者字段名用“”包括。

select package_id as"packageId", count(1) as"totalCount"from t_task_package groupby package_id 

2.8-关键字错误:达梦数据库中有77个关键不能作为表名,列名等

select * from v$reserved_words where res_fixed = 'Y'【有77个关键字】

RES_FIXED 关键字是否可以 EXCLUDE,Y 不可以,N 可以

当RES_FIXED为N时,可以通过修改了dm.int的EXCLUED_RESERVED_WORDS参数,屏蔽关键字或者修改/etc/dm_svc.conf文件

KEYWORDS=关键字【用,分隔】

以下为解决参考:

http://t.zoukankan.com/hong-yf-p-15320205.html

https://eco.dameng.com/document/dm/zh-cn/faq/faq-errorcode

https://eco.dameng.com/community/question/1b697bc9a0245b1f9d085e398ce81a8f

但是当RES_FIXED为Y时,通过以上方法仍然没有生效,目前提供解决办法:修改表字段和实体类字段【不建议使用关键字作为表字段,表名等】。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_Mervin_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值