javaee一些问题点基础记录

这篇博客主要探讨了JavaEE开发中的一些常见问题和实践经验,涵盖了hibernate的映射策略、nosql(MongoDB)、SpringMVC、权限管理、版本管理、Linux操作、javaweb跨域/CORS、全局处理、MyBatis、Docker使用以及访问协议等多个方面。作者分享了在实际操作中遇到的问题,如类转换问题、富文本处理、权限配置、数据库事务、Linux服务配置等,并给出了相应的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

hibernate
映射策略
一、nosql
  1. mongdb入门
  2. MongoDB 之 aggregate $lookup
  • 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只有一个属性 其它丢掉了

关于 OOA→OOD→OOP

三、权限

spring security

  • springBoot
  1. @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可以直接删除
五、 版本管理一些记录
六、 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;
}
}

七、 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>
<label th:if="*{num ne 1}" name="kenname"  class="control-label">
[[*{kenname}]]
</label>

themaleaf 该判断用在lable上 条件不成立 也显示了。。div正常
原因: th:field与 th:text 后者 即便条件满足也会 显示值

  • jdk8 > stream

  • 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

  1. 报错
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

javax官网API

十五、JPA

1) MyRepository 和 MyRepositoryImpl

No property found for type

本次遇到的:
MyRepositoryImpl 中对应的方法 写成了 private
MyRepositoryImpl 中对应的方法 参数不一致

2)JPA cannot access *.*impl

cannot access xxx.class

  • 直接注入 *RepositoryImpl 调用方法而非通过 *Repository接口的方式调用
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值