# TheFool **Repository Path**: weiwei3597/the-fool ## Basic Information - **Project Name**: TheFool - **Description**: No description available - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2020-11-16 - **Last Updated**: 2024-06-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # TheFool #### 介绍 ### 2020年11月17日 othing gold can stay --《the outsiders》 X 《EP - Stay Gold》 ### 2020年11月18日 多线程任务提交器 future.get(timeout, TimeUnit.MILLISECONDS) 方法超时会抛出TimeoutException异常,当线程内部抛出异常,调用该方法会抛出同样的异常,所以可以用该方法捕获异步线程内的异常 ### 2020年11月19日 今日试验BeanUtils.copyProperties 发现当parent和child如果是内部类(ParentAndChildMain)BeanUtils.copyProperties就会失效, if (!"class".equals(name) && this.getPropertyUtils().isReadable(orig, name) && this.getPropertyUtils().isWriteable(dest, name))这个判断没有通过 isReadable返回false 可访问性 因为是内部类所以可访问性是null 所以拷贝失败 isReadable()和isWritable()检查bean是否可读(有getter)或可写(有setter) 阅读源码发现apache 做了大量的校验 不建议使用推荐使用spring的 BeanUtils (仅检查属性的可访问性。(通过源码发现没有校验所以内部也可以使用)) isReadable 看半天大概猜测**class必须为public才行** 尝试了一下 **果然 public就行** ### 2020年11月21日 今天试验了一下事务,在公司项目,这个项目等以后完善一栏再补充 ```java @Override @Transactional public void test(Consumer c) { User user=new User(); user.setPhone("16638216290"); userMapper.insertUser(user); c.accept(1L); } ``` 当Consumer内部发生异常 仍然可以回退 ### 2020年11月30日 many shoes(许多鞋子) = Main issues(为什么呢?)”赛博朋克2077 ### 2020年12月3日 [springCache 的坑](./think/src/main/java/com/cache/springCache.md) ### 2021年1月14日 好久没有维护了,今天工作的时候发现一个idea的bug当resources目录下有别的文件夹,并且文件夹里还有application.yml 那么所有application.yml文件就不会被识别为springboot配置,就没有提示功能 研究了一下,发现是idea不接受重名的application.yml,所以多环境配置就有两个方案 1. 使用多个配置文件,启动项目时指定文件,(--spring.profiles.active=dev),这种可以有提示,比较友好,但是一个环境多个配置文件就不太友好了, 2. 使用maven打包替换外面的配置文件,外面有一个配置文件,spring使用这个配置文件,打包则指定config文件夹的配置替换外层配置,那样就形成了替换环境问题 ### 2021年2月4日 Give a man a program, frustrate him for a day.Teach a man to program, frustrate him for a lifetime ### 2021年2月6日 fake it,,,make it ### 2021年2月19日 todo 今天给公司程序的推送功能封装完成,测试的时候发现使用异步线程时,使用测试类调用方法时发现获取不到JDBC Connection, 本来打算改成同步,使用mq实现异步,后来发现不在测试类中使用正常 个人猜测:测试类测试方法执行完毕后连接池就关闭了,所以在async中无法获取连接池 ### 2021年3月4日 Because you are a kind person,you can help other people in the world who are suffering ### 2021年3月13日 Spring的BeanUtils的CopyProperties方法需要对应的属性有getter和setter方法;2.如果存在属性完全相同的内部类,但是不是同一个内部类,即分别属于各自的内部类,则spring会认为属性不同,不会copy;3.泛型只在编译期起作用,不能依靠泛型来做运行期的限制;4.最后,spring和apache的copy属性的方法源和目的参数的位置正好相反,所以导包和调用的时候都要注意一下。 ### 2021年3月16日 alimaven central aliyun maven http://maven.aliyun.com/nexus/content/repositories/central/ 关于maven setting文件中配置镜像, mirrorOf如果配置为*,所有请求都走这个,这样所造成的后果就是在项目中pom文件配置repository就会不生效 ### 2021年8月26日 idea-tomcat文字乱码 1. tomcat的service.xml文件 添加URIEncoding="UTF-8" ```xml ``` 2. tomcat的logging.properties下面增加一行(没有就加) ``` java.util.logging.ConsoleHandler.encoding = GBK ``` 然后将文件所有UTF-8改为GBK ### 2021年9月2日 mysql安装参考 两个文章结合来 [1](https://blog.csdn.net/qq_37598011/article/details/93489404) [2](https://blog.csdn.net/qq_37598011/article/details/93489404) 修改密码开放远程使用一下命令 ```bash SET PASSWORD = PASSWORD('123456'); ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; FLUSH PRIVILEGES; use mysql #访问mysql库 update user set host = '%' where user = 'root'; #使root能再任何host访问 FLUSH PRIVILEGES; ``` [nginx的安装](https://www.cnblogs.com/happyyangyanghappy/p/10860747.html): 1.解压tar包得到c的安装包 2.安装c的插件后make命令初始化c包 3.使用make install命令安装真正的nginx 需要ssl插件在 make之前,nginx的c包中执行 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module ### 2021年11月4日 mavne引入外接lib包 引入外接lib包时如果之后使用maven发布打包需要引入mavne打包插件加上如下配置 ``` maven-compiler-plugin 1.8 1.8 UTF-8 ${project.basedir}/src/lib ``` 如果是springbootmaven打包需要加上true配置 ``` org.springframework.boot spring-boot-maven-plugin 2.1.1.RELEASE true true repackage ``` ### 2021年12月30日 RestTemplate的URLEncoder 使用spring的RestTemplate时,发请求时,会对请求的url值进行编码再发送。也就是说不需要再进行URLEncoder https://blog.csdn.net/Petershusheng/article/details/54236816 ### 2022年2月25日 @AsyncBUG @Async 小心使用,@Async在处理循环依赖时会产生问题,因为@Async修饰的bean会在创建时进行处理,但是此时这个类可能已经被 其他bean注入了,所以版本不匹配,启动报错 ``` Caused by:org.springframework.beans.factory.BeanCurrentlyInCreationException: Errorcreating bean with name 'asyncUpdate': Bean with name 'asyncUpdate' has beeninjected into other beans [dealerService,userService] in its raw version aspart of a circular reference, but has eventually been wrapped. This means thatsaid other beans do not use the final version of the bean. This is often theresult of over-eager type matching - consider using 'getBeanNamesOfType' withthe 'allowEagerInit' flag turned off, for example. ``` ```java @Component @EnableAsync public classAsyncUpdate { @Autowired private DealerMemberMapper dealerMemberMapper; @Autowired private UserService userService; @Autowired private GoodsSubscribeService goodsSubscribeService; /** *异步更新 */ @Async public void updateDealerAsync(Dealer dealer, String mobilephone, Integer type) throwsException { } } ``` ```java @Service public classDealerService { @Autowired private DealerMapper dealerMapper; @Autowired private UserService userService; @Autowired private AsyncUpdate asyncUpdate; } ``` 在启动程序的时候,Spring已经对DealerService里的asyncUpdate、userService加载完成,当准备创建AsyncUpdate类的时候发现使用了@Async注解,即spring又需将该Bean代理一次,然后Spring发现该Bean已经被其他对象注入,这里就是问题的关键所在了。 ``` 解决办法 @Autowired 类的时候使用@Lazy 注解控制懒加载 比如 IUniversityOrderService 引入IPushService ,IPushService 引入了IUniversityOrderService, IPushService 里面有方法是 @Async的,那么就将 IUniversityOrderService的引入IPushService上加@Lazy ``` ### 2022年3月24日 编程式事务 springboot使用编程式事务:先autowired DataSourceTransactionManager 获取事务源, 然后用dataSourceTransactionManager.getTransaction(new DefaultTransactionDefinition())获得transactionStatus 开启事务 最后就可以DataSourceTransactionManager 进行提价和回滚 dataSourceTransactionManager.rollback(transactionStatus);/dataSourceTransactionManager.rollback(transactionStatus); ### 2022年3月29日 ObjectMapper ```java //序列化的时候序列化所有属性 /** * JsonInclude.Include.ALWAYS 默认 * JsonInclude.Include.NON_DEFAULT 属性为默认值不序列化 * JsonInclude.Include.NON_EMPTY 属性为 空(“”) 或者为 NULL 都不序列化 * JsonInclude.Include.NON_NULL 属性为NULL 不序列化 * 或者在类的属性上使用标签 * -@JsonIgnoreProperties({"sex","addTime"}) //序列化时忽略的属性名称集合 ,加在类上,给出的属性都不序列化 * -@JsonProperty("stu_id") //序列化时,如果要修改某些属性的名字,可以使用, 序列化 将id改为 stu_id * -@JsonIgnore //序列化时忽略字段,用在 属性上 、方法上 边。 * */ objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS); //反序列化时如果多了其他属性不抛出异常 objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false); //序列化如果是空对象的时候不抛出异常 objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,false); //序列化取消时间的转化格式,默认是时间戳,可以取消,同事需要设置表现的时间格式 objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,false); objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); T t = objectMapper.readValue(json, responseType) ```