java 问题记录
- 问题一:uaa项目cannot determine embedded database driver class for database type NONE
- 二:包导入失败
- 三.MySQL数据库连接不上
- "errorMessage":"JSON parse error: Unrecognized token 'GH': was expecting ('true', 'false' or 'null');![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/57775e6e6aaea68c9001b071dde34fcd.png)
- 问题五:try、catch、finally都有return语句时执行哪个
- 问题六:运行项目出现Process finished with exit code 1
- 问题七:Nacos启动异常:failed to req API:/api//nacos/v1/ns/instance after all servers([127.0.0.1:8848])
- 问题八:报错:参数类型不匹配
- 问题九:com.alibaba.fastjson.JSONObject cannot be cast to ...
- 问题10:unknow column "xxx" in fieldList
问题一:uaa项目cannot determine embedded database driver class for database type NONE
这里我只是用maven clean一下,然后直接运行项目,就可以运行成功,不要rebuild,uaa项目的正确运行和部署方式是rebuild->clean->run->install
二:包导入失败
一.包导入失败的原因可能是
1.数据库连接池版本太早,maven中央仓库已经找不到包
2.可能是连接池和数据库版本不匹配
3.更改或添加另一个仓库地址:
<repositories>
<repository>
<id>jasper</id>
<name>jasper</name>
<url>https://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/</url>
</repository>
<repository>
<id>aliyun</id>
<name>aliyun central</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</repository>
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
如果还不行也可以试试调整三个的位置(把jasper仓库换到第二个或者第三个)
4.把mybatisx的插件禁用(即取消勾选即可,但这种问题一般不打紧,不影响运行,当子模块的pom文件引入依赖才会下载)
5.由于为RELEASE,导致maven会自动去下载最新的RELEASE包版本,由于没有向下兼容,所以导致某些依赖包找不到,import失败
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
改为某个固定版本最为稳妥,即可解决问题
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.2.6</version>
<scope>compile</scope>
</dependency>
6.更换maven的setting.xml文件,用idea自带的试试
7.直接启动项目,有的包问题不影响项目的运行
三.MySQL数据库连接不上
1.检查数据库链接url和用户名密码
2.如果有多个profile配置类似这样:**
<profiles>
<!-- 本地开发环境 -->
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- 数据库 -->
<db.application.database.type>mysql</db.application.database.type>
<db.driver>com.mysql.jdbc.Driver</db.driver>
<db.url>jdbc:mysql://xxx.xxx.x.xx:3367/databoot?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&useOldAliasMetadataBehavior=true</db.url>
<db.username>root</db.username>
<db.password>2mA%aKZG$^</db.password>
<AppCenterDBDatabase>databoot</AppCenterDBDatabase>
<!-- mongodb -->
<mongoUrl>192.168.2.3</mongoUrl>
<mongoPort>28001</mongoPort>
<!-- redis -->
<redisHost>192.168.2.3</redisHost>
<redisPassword></redisPassword>
<!-- solr -->
<baseSolrUrl>http://localhost:8984/solr/dbc-files</baseSolrUrl>
<!-- 日志级别 -->
<log.level>debug</log.level>
<mybatis.log>STDOUT_LOGGING</mybatis.log>
<jzgClientId>20210415170559021105696</jzgClientId>
<jzgClientSecret>34609154-843b-4a15-a765-e7d454d55bf2</jzgClientSecret>
<xsClientId>20210415170535484244090</xsClientId>
<xsgClientSecret>8daf64d8-de30-4a59-a262-9ca7a60312da</xsgClientSecret>
</properties>
</profile>
<!-- xxxxxx正式环境 -->
<profile>
<id>prod</id>
<!-- <activation>-->
<!-- <activeByDefault>true</activeByDefault>-->
<!-- </activation>-->
<properties>
<!-- 数据库 -->
<db.application.database.type>mysql</db.application.database.type>
<db.driver>com.mysql.jdbc.Driver</db.driver>
<db.url>jdbc:mysql://xx.xxx.3.159:3357/xxxx?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&useOldAliasMetadataBehavior=true</db.url>
<db.username>root</db.username>
<db.password>xxxx</db.password>
<AppCenterDBDatabase>xxxx</AppCenterDBDatabase>
<!-- mongodb -->
<mongoUrl>127.0.0.1</mongoUrl>
<mongoPort>27017</mongoPort>
<!-- redis -->
<redisHost>127.0.0.1</redisHost>
<redisPassword>123123</redisPassword>
<!-- solr -->
<baseSolrUrl>http://localhost:8984/solr/dbc-files</baseSolrUrl>
<!-- 日志级别 -->
<log.level>debug</log.level>
<mybatis.log>STDOUT_LOGGING</mybatis.log>
<jzgClientId>20200921191947652070920</jzgClientId>
<jzgClientSecret>5033aadd-24f2-49ab-bcb3-b492258ade74</jzgClientSecret>
<xsClientId>20200918120801948580935</xsClientId>
<xsgClientSecret>472e534e-041f-4b6b-939a-8391f4cc22da</xsgClientSecret>
</properties>
</profile>
</profiles>
那要在右侧maven的profile栏目里勾选你想要的配置,例如我想要ID为dev的测试环境的配置:
问题解决!
问题四:
“errorMessage”:"JSON parse error: Unrecognized token ‘GH’: was expecting (‘true’, ‘false’ or ‘null’);![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/57775e6e6aaea68c9001b071dde34fcd.png)
public static String doPost2(String url, Map<String, String> param,Map<String, String> header) {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Content-Type","application/json");
if (header != null) {
for (String key : header.keySet()) {
httpPost.addHeader(key, header.get(key));
}
}
// 创建参数列表
// if (param != null) {
// List<NameValuePair> paramList = new ArrayList<>();
// for (String key : param.keySet()) {
// paramList.add(new BasicNameValuePair(key, param.get(key)));
// }
// // 模拟表单
// UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList);
// httpPost.setEntity(entity);
// }
if (param != null) {
JSONObject jsonObject = new JSONObject();
for (String key : param.keySet()) {
jsonObject.put(key, param.get(key));
}
httpPost.setEntity(new StringEntity(jsonObject.toString()));
}
// 执行http请求
response = httpClient.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return resultString;
}
使用 UrlEncodedFormEntity 来设置 body,消息体内容类似于“KEY1=VALUE1&KEY2=VALUE2&…”这种形式,和前端数据接收格式不匹配,所以报错,替换成StringEntity即可!太恶心了
问题五:try、catch、finally都有return语句时执行哪个
在try或catch有return时,先执行finally,再执行try语句,如果try语句没有异常,则执行完try的return之后不会再执行catch的return(因为没有异常嘛,怎么会进入到catch呢?),有异常就只执行catch里的return
在try、catch和finally都有return的情况下,只执行finally的return,不会再管try和catch的return
问题六:运行项目出现Process finished with exit code 1
这种通常是配置文件的问题,删除logback-spring.xml就可以正常启动,我也不知道为什么
问题七:Nacos启动异常:failed to req API:/api//nacos/v1/ns/instance after all servers([127.0.0.1:8848])
解决方案:
删掉nacos文件夹下的data文件夹,重新启动
原因:
Nacos负载过高
问题八:报错:参数类型不匹配
原因:可能是参数错误,也可能是没有加注解(例:@RequestBody)
问题九:com.alibaba.fastjson.JSONObject cannot be cast to …
将字符串转成对象List时最好不好直接强转:
List<SubTrade> subTrades = (List<SubTrade>) json.get("org");
改成:
List<SubTrade> subTrades = JSON.parseArray(json.getString("org"), SubTrade.class);
解决!
问题10:unknow column “xxx” in fieldList
可能是实体和数据库的字段不匹配,又有可能是数据库不正确,库名有问题,在实际业务中很容易忽略