文章目录
- hibernate
- 一、nosql
- 二、 springmvc
- 三、权限
- 五、 [版本管理一些记录](https://blog.csdn.net/helloWorldAndYou/article/details/109732342)
- 六、 linux
- 七、 javaweb跨域/cors
- 八、 全局处理
- 九、 mybatis
- 十、 docker
- 十一、访问协议
- 十二、分布式(多数据源)事务
- 十三、问题集
- 十四、[javax Validation](https://blog.csdn.net/flowingflying/article/details/78150015)
- 十五、JPA
hibernate
映射策略
一、nosql
- javaee
classpath 和 classpath* 区别、
不再resources目录中 classpath:你的目录/eheache.xml
2)数字类型值太大:如 id自增太大,前端接受后精度丢失
1325041912076988419 主键自增,mybatis 查询空
@JsonSerialize(using = ToStringSerializer.class) 转出字符串避免精度丢失
3) 富文本 传入后台与后台接收
前端通过encodeURIComponent()或者encodeURI()转码后再传
encodeURIComponent java.net.URLDecoder.decode(works, “UTF-8”);
4) OPTIONS请求时设置了Header请求和token可是后台接收不到
拦截器增加
拦截器增加:
if (httpServletRequest.getMethod().equals("OPTIONS")) {
httpServletResponse.setStatus(HttpServletResponse.SC_OK);
return true;
}
5) 同一个工程同一个包路径的同一个class不能强转
同一个class在进行集合、遍历等计算时,提示该class不能转换成该class
原因:热加载
可能猜测:多个不同的热加载器?
6)stream
List<Student> projectTypeList= new ArrayList();
Long[] tempIds = projectTypeList.stream().map(ProjectType :: getId).toArray(Long[]::new);
Long[] tempIds =new Long[2];
Long[] tyIds = Stream.concat(Stream.of(tyIds), Stream.of(tempIds)).toArray(Long[]::new);
二、 springmvc
1)
Controller 前置控制器的 3 种实现方式,1)@controller 2)接口controller 3) 接口HttpRequestHandler
2)
model 没有 没有提供get set 方法 导致 返回json只有一个属性 其它丢掉了
三、权限
- springBoot
- @EnableAutoConfiguration(exclude 过时
2.x后改为yml配置 spring.application.autoconfigure.exclude
2)
spring boot中配置多个DispatcherServlet
- mybatis-plus springboot整合
找不到BaseMapper中的crud方法,配置MappperScan无效。在排除了pom存在的大量jar冲突,将boot升级到2.3.3,再将冲突jar排除、升级相关依赖jar之后,再次整合成功 - 排除 日志多个 binding绑定,boot项目引入了boot-web包含了slf4j ,删掉.排除掉其它所有日志依赖引入
- hutool 找不到log4j
在db.setting 设置了filter 日志用 log4j在com.alibaba.druid.pool.DruidDataSource#configFromPropety 264行设置时报错。再往后追就是com.alibaba.druid.filter.FilterManager#loadFilter - springboot默认用的是slf4j 包含在boot-web中,其它额外引入的日志jar可以直接删除
五、 版本管理一些记录
- 迁移项目 项目迁移 idea eclipse
1)
导入项目,没有修改maven地址,还是迁移之前的路径
hError running : No valid Maven installation found. Either set the home directory in the
2 )
eclipse 非maven web项目 迁移到 idea
eclipse 转 idea ssm项目
idea 加载 eclipse maven
打开pom文件,先修改maven为国内。。其它方式导入 右侧不会显示maven 选项
Could not find artifact .::pom:0.0.1-SNAPSHOT 父类version值和model引入父类时指定的version值不一致
idea导入eclipse springboot 项目
3)
a、 ——>idea 导入阿里云 aliyun-sdk-oss-3.10.2.jar 仍然找不到 OSSClientBuilder OSS 把 Artifacts 删掉 重新 tomcat deployment删掉重新 ,也可能是target缓存
b、 ——> 一开始把jar放在lib中能立即生效,后来在放的时候无法立即生效,环境配置未曾变动。可能是target缓存?
4)
Springboot项目下mybatis报错:Invalid bound statement (not found)
target\classes\ 缓存,删掉
5 ) 非maven改成maven
6 ) idea 创建 Artifacts之后 提示fix 修复lib
选择add lib to artifact
7 ) idea 弹出Server’s certificate is not trusted 解决方法
2、module -> 选中项目 --> lib类型改为 compile
3、package报红,编译不会报错提示、mapper引入路径错误启动项目才会提示,编译无提示
六、 linux
chkconfig --list
查看 系统启动服务列表
或者 systemctl list-unit-files
查看 乌班图 或者 red hat版本
cat /proc/version
a、
nacos安装 win版
b、
centos7下/etc/sysconfig/目录没有iptables问题
c、
erlang: wx-config: command not found或wxWidgets must be installed on your system.
b、
rpm安装 成功
经历步骤:
mysql linux 官网下载路径
linux安装5.5版本mysql_spring20l6的博客-CSDN博客_linux安装mysq
No such file or directory
Neither host ‘localhost.localdomain’ nor ‘localhost’ could be looked up with
./bin/resolveip
Please configure the ‘hostname’ command to return a correct
hostname.
If you want to solve this
CentOS7修改主机名的三种方法
修改主机名
修改后无效 : 64位 安装成 32位 导致的
Unit mysqld.service could not be found.
修改后 启动命令为 service mysqld start
Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’
其它源码安装博客
systemctl enable mysqld.service
启用服务
** * 1* * * * * 2*
mysql导入脚本 有大量的text类型字段
error: Row size too large (> 8126). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC
删掉 FORMAT=COMPACT 即可
DROP TABLE IF EXISTS `abc`;
CREATE TABLE `abc` (
`id` bigint(20) NOT NULL COMMENT '主键',
`a` text COMMENT '注释',
`b` text COMMENT '注释',
`c` text COMMENT '注释',
PRIMARY KEY (`id`),
KEY `abc` (`a`,`b`,`c`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
d、
各类源码安装博客(源码安装总是失败,各种错误,rpm安装一次成功):
0.1 ) https://blog.csdn.net/weixin_39020878/article/details/109491748
0.2 ) https://github.com/rabbitmq/erlang-rpm/tags
0.3 ) https://github.com/rabbitmq/rabbitmq-server/tags
node ‘rabbit’ not running at all no other nodes on localhost
未解决
换成rpm安装成功
rabbitmqctl shutdown -n rabbit@prod
distribution port 25672 in use by another node: rabbit@localhost
e、
redis安装 成功
cd redis-4.0.8
make
cd src
make install PREFIX=/usr/local/redis
出现 Hint: It’s a good idea to run 'make test
实际上已经安装成功了,无需理会,直接到src目录中启动即可./redis-server
g、
mongodb安装
不指定配置文件 启动 mongo
指定配置启动用【mongod 】 mongod --config /etc/mongodb.conf
注意两个命令不同,否则启动失败
指定ip 端口 访问
./mongo 192.168.1.1:27017
db.auth(“zjx”,”tsjianxin”) 测试登录
h、
安装服务组件启动正常reboot后,启动该服务组件各种错误–>jdk 重启失效 添加到开机启动 rc.local
i、
5 、设置开机自启动如果要开机自启tomcat ,配置如下:
1. chmod + /etc/rc. d/rc. local
2. vi /etc/rc. d/rc. local
3. 添加:
4. export JAVA_HOME=/usr/local/java/jdk
5. export PATH=$JAVA_HOME/bin:$PATH
6. export CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools. jar
7. usr/local/tomcat/bin/startup. sh
j、
nginx代理 ,实现国内访问国外,服务器为国外服务器
server {
server_name 9.20.100.50;
client_max_body_size 1024M;
location /a {
proxy_pass https://www.google.cn;
}
}
不写监听端口库 改为监听不同的路径 服务器ip:/zp ,ngxin帮你访问 http://api.zb.plus/data/v1/allTicker
多个 代理 域名
server {
server_name 9.20.100.50;
client_max_body_size 1024M;
location /a {
proxy_pass https://www.google.cn;
}
location /b {
proxy_pass https://www.google.cn;
}
}
- 缓存
ehache 创建Element 该对象中以Object类型存储待缓存的数据
ehache中有两个缓存选择:EhCache和MapCache
MapCache该对象有个私有的final不可变的map来缓存数据
k、Linux中卸载mariadb数据库/修改数据库密码
L、inux安装JDK(rpm方式)
M、vamare14+centos7标准版安装
ifconfig找不到
可能是忽略了某些步骤导致的。效果类似于: centos7最小化系统安装设置IP(ifconfig找不到) - centos7 防火墙管理
centos7版本对防火墙进行加强,不再使用原来的iptables,启用firewalld - docker 命令图
七、 javaweb跨域/cors
跨域 无用户凭证 success
上面博客 : 需要设置 bean.setOrder(1); 但是实际测试 去掉也是OK的,可能版本或体系有所不同。
遇到新问题: 设置允许跨域的凭证无效。即设置了允许哪些域名跨域无效。效果都如同以下代码。【以下代码只能用于测试环境、不能用于企业生产环境,容易遭受攻击】
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class HelloCorsConfig implements WebMvcConfigurer {
@Bean
public FilterRegistrationBean corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", corsConfig());
FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
// bean.setOrder(1);
return bean;
}
private CorsConfiguration corsConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*");
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
corsConfiguration.setAllowCredentials(true);
corsConfiguration.setMaxAge(3600L);
return corsConfiguration;
}
}
- 获取文件后缀
实际测试中,获取并不完全正确,例如.sh等类似文件被判定为txt、压缩文件有时候被判定为文档类型
<!-- 获取文件后缀-->
<dependency>
<groupId>net.sf.jmimemagic</groupId>
<artifactId>jmimemagic</artifactId>
<version>0.1.5</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>1.14</version>
</dependency>
- jdk8以后的stream流归约函数
关键 Collectors类中的方法 - thymelaf
1) th:if
<label th:if="*{num ne 1}" name="kenname" class="control-label">
[[*{kenname}]]
</label>
themaleaf 该判断用在lable上 条件不成立 也显示了。。div正常
原因: th:field与 th:text 后者 即便条件满足也会 显示值
-
java 的transient关键字与 @Transient
private transient String name2; 不参与序列化;
@Transient修饰的变量在表中不存在 -
获取文件后缀的jar
但是在解析部分压缩文件以及其它系统服务类型文件会被解析成其它格式,如txt
<!-- 获取文件后缀-->
<dependency>
<groupId>net.sf.jmimemagic</groupId>
<artifactId>jmimemagic</artifactId>
<version>0.1.5</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>1.14</version>
</dependency>
- tomcat乱码
前后端统一参数编码,服务器编码设置,数据库编码设置,浏览器编码设置等
八、 全局处理
1 ) hibernate validator 全局处理
1.1 ) webmvc (失败)
@EnableWebMvc
@ComponentScan("com.flycms.web.*")
@Configuration
public class HelloCorsConfig implements WebMvcConfigurer {
@ControllerAdvice 类
方法
@ExceptionHandler(value = {Exception.class})
@ResponseBody
public DataVo validationExceptionHandler(Exception exception) {
logger.error(exception.getMessage(), exception);
String ss = exception.getMessage();
System.out.println(1);
/* BindingResult bindResult = ((BindException) exception).getBindingResult();
String msg;
if (bindResult != null && bindResult.hasErrors()) {
msg = bindResult.getAllErrors().get(0).getDefaultMessage();
return DataVo.failure(msg);
}*/
return null;
}
1.2 ) @Aspect (成功)
注意点:
@Aspect 全局hibernate validator处理
package com.flycms.core.aspect;
import com.flycms.core.exception.HelloException;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;
/**
* @Author: HelloWorldAndYou
* @Description: data validator aspect
* @Date: 2020/12/7 14:15
* @Modified By:
*/
@Aspect
@Component
public class HelloAspect {
/*@Before("execution(* com.*.web..*.*(..)) && args(..,bindingResult)")
public void doAround(ProceedingJoinPoint pjp, BindingResult bindingResult) throws Throwable {
if (bindingResult != null && bindingResult.hasErrors()) {
throw new HelloException(bindingResult.getAllErrors().get(0).getDefaultMessage());
}
pjp.proceed();
}*/
@Before("execution(* com.*.web..*.*(..)) && args(..,bindingResult)")
public void doAround(JoinPoint pjp, BindingResult bindingResult) throws Throwable {
if (bindingResult != null && bindingResult.hasErrors()) {
throw new HelloException(bindingResult.getAllErrors().get(0).getDefaultMessage());
}
// pjp.proceed();
}
}
ProceedingJoinPoint 不支持before 使用around需要对后续方法返回结果做处理 ,否则 <reponse body empty>
-
linux远程调试
spring jar 开启远程调试 -
linux
nohup java -jar XXX.jar & -
window cmd
start javaw -jar demo.jar 后台启动
taskkill -im -f 15252
netstat -ano|findstr 8091
最后一列为PID -
spring
- 报错
Binding to target [Bindable@561b6512 type = org.springframework.boot.autoconfigure.web.servlet.MultipartProperties, value = 'provided', annotations = array<Annotation>[@org.springframework.boot.context.properties.ConfigurationProperties(prefix=spring.servlet.multipart, value=spring.servlet.multipart, ignoreInvalidFields=false, ignoreUnknownFields=false)]] failed:
Property: spring.servlet.multipart.max-file-size
Value:
Origin: class path resource [application.properties]:12:0
Reason: The elements [spring.servlet.multipart.max-file-size,spring.servlet.multipart.max-request-size] were left unbound.
Property: spring.servlet.multipart.max-request-size
Value:
Origin: class path resource [application.properties]:13:0
原因:spring.servlet.multipart.max-file-size 没有给值
九、 mybatis
1 ) Result Maps collection does not contain value for com.tutu.system.mapper.CUserMapper
原因:resultType写成了 resultMap
十、 docker
菜鸟教程
docker 官网API
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
systemctl [start|stop|restart] docker
docker run -it 你创建的容器ID
docker安装pxc集群
docker安装pxc集群问题集
例如:
[ERROR] [MY-000000] [Galera] handshake with remote endpoint ssl://10.0.0.2:4567 failed: asio.ssl:67567754: ‘invalid padding’ ( 67567754: ‘error:0407008A:rsa routines:RSA_padding_check_PKCS1_type_1:invalid padding’)
This error is often caused by SSL issues. For more information, please see:https://per.co.na/pxc/encrypt_cluster_traffic
在创建的各个节点数据卷目录中,同步主节点认证文件。
拷贝node1的ca.pem、client-cert.pem、client-key.pem、server-cert.pem、server-key.pem到其它各节点覆盖粘贴
cp /var/lib/docker/volumes/v1/_data/server-cert.pem /var/lib/docker/volumes/v2/_data/server-cert.pem
十一、访问协议
TCP
HTTP和HTTPS概述
HTTPS过程说明
HTTP过程说明
十二、分布式(多数据源)事务
1、分布式事务方案:AT、TCC、Saga、XA 模式分析对比
2、J2EE中间件(事务管理器、事务协调者):重量级Weblogic、Jboss、轻量级JTA、 Jotm、Atomikos、Narayana和Bitronix
Narayana是一个流行的开源JTA事务管理器实现,目前只有JBoss支持;
基于JTA多数据源事务方案列表介绍
3、常见的事务组件:seata hmily byetcc easytransaction
十三、问题集
-
YML : java.nio.charset.MalformedInputException: Input length = 1
editor -> file-encoding
修改后仍然不生效,因为原本文件是其它编码的。复制内容到txt,删掉并新建yml,再拷贝回来OK -
mongodb事务注意事项
所有事务中的 CRUD 操作,均要求 collection 已经预先存在;
所有事务均不能对 config、admin、local 三个 database 进行操作;
事务中不能对 system.* 的 collection 进行写操作(增删改);
事务内部不能对事务外部创建的游标(cursor)进行 getMore 操作,反之亦然;
如果在创建或删除 collection 后需要马上进入事务,并且事务中有对原 collection 的操作,则建议在创建或删除时,设置 writeConcern 为 majority;
事务中不能直接使用 Count Operation,需要在 aggregation 中使用 $count 或 $group 来替代
十四、javax Validation
十五、JPA
1) MyRepository 和 MyRepositoryImpl
No property found for type
本次遇到的:
MyRepositoryImpl 中对应的方法 写成了 private
MyRepositoryImpl 中对应的方法 参数不一致
2)JPA cannot access *.*impl
- 直接注入 *RepositoryImpl 调用方法而非通过 *Repository接口的方式调用