首页 文章 新番
动漫 学习 生活 日记 书籍 服务器 Bing
  • Spring Boot Redis Session问题

    使用`redis`来共享`session`,其中容易出现一个问题就是:如果两个不同的项目选择了同一个`redis`数据库,如果`session`里面保存了不同的Java对象,反序列化就会出现`ClassNotFoundException`这个异常。解决办法有两种:1.使用不同的`session`数据库。2.使用不同的`cookie`名称。不过第一种,能解决`ClassNotFoundException`问题,但是由于`session`名称是一样的,那么就导致两个项目只能登陆一个,而不能同时登陆。

    2018年11月13日 Spring Boot Redis Session
  • Spring Boot使用redis

    添加依赖:```xmlorg.springframework.bootspring-boot-starter-data-redis```redis配置:```spring.redis.host=127.0.0.1spring.redis.port=6379spring.redis.database=0```如果我们不添加`redis`配置,默认提供的是一个`RedisTemplate`工具,我们可以自己实现一个配置:```javapackagecom.api.core.config;importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.Configuration;importorg.springframework.data.redis.connection.RedisConnectionFactory;importorg.springframework.data.redi...

    2018年11月02日 Spring Boot Spring Cloud redis
  • Srping Boot使用redis缓存

    引入依赖:```xmlorg.springframework.bootspring-boot-starter-data-redis```redis配置:```spring.redis.host=127.0.0.1spring.redis.port=6379spring.redis.database=0```然后配置缓存`CacheManager`:```javapackagecom.api.core.config;importjava.time.Duration;importjava.util.HashMap;importjava.util.HashSet;importjava.util.Map;importjava.util.Set;importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;importorg.springframework.cache.CacheManager;importorg.springframework.cache.interceptor.KeyGenerator;importorg.springframework.cache.int...

    2018年11月02日 Spring Boot Spring Cloud redis
  • Spring Cloud监控页面打不开

    之前没有使用`rabbit`来收集熔断器的信息时,没有问题,后来整合以后,发现了一个问题就是`zipkin`和`hystrix`页面一直打不开,看了一下控制台发现资源文件一直处于加载中。仔细一看请求返回的类型居然是:`text/event-stream`。然后访问了一下映射端点`/actuator/mappings`,发现映射的`controller`为`TurbineController`。下面是源码:```java@RestControllerpublicclassTurbineController{privatestaticfinalLoglog=LogFactory.getLog(TurbineController.class);privatefinalFluxflux;publicTurbineController(PublishSubject>hystrixSubject){Observable>stream=StreamAggregator.aggregateGroupedStreams(hystrixSubject.groupBy(data->InstanceKey.crea...

    2018年10月28日 Spring Cloud Turbine
  • CSRF CORS学习

    ##CORS说到跨域,我想很多程序员都遇到过。跨域简单来说就是在一个页面上发起一个请求,这个请求的域名、端口或者协议不同时就会出现跨域问题。常见的加载静态资源的标签浏览器默认允许跨域(HTTP协议页面不能加载HTTPS的资源):script、link、iframe、img。ajax请求会严格的审核跨域信息。##CSRF跨站攻击,这个东西,说简单一点就是网站A直接跳转到网站B,对于用户浏览器来说,跳转过去时会携带用户在网站B上面的cookie、session等信息,这样可以达到用户在B网站操作的效果。比如:添加购物车、支付等。这个解决办法:1.验证请求发起页面。2.对于请求添加一个token验证。如果以前网站,设置了运行跨域请求,同时运行携带验证信息,那么可能就会出现,如果用户浏览器存在网站B的登陆信息,网站A,可以不用跳转到网站B,直接使用ajax就可以实现用户在网站B上面进行操作。还有一个叫做XSS攻击,这个就是跨站脚本,常见比如BBS,用户提交帖子里面含有一段JS代码,其他用户浏览时就会执行这个JS代码。解决办法过滤掉这些代码即可。

    2018年10月27日 CSRF CORS XSS
  • Spring Cloud发送POST请求时提示403

    引入了`spring-boot-starter-security`依赖后,配置了通过所有请求,GET请求正常,但是POST请求被拦截,提示`403`。这时需要添加`.csrf().disable()`这段代码,来禁用`csrf`拦截:```java@Overrideprotectedvoidconfigure(HttpSecuritysecurity)throwsException{security.csrf().disable()//解决POST请求403错误.authorizeRequests()//.requestMatchers(EndpointRequest.toAnyEndpoint()).denyAll()//.requestMatchers(EndpointRequest.toAnyEndpoint()).access("hasIpAddress('0:0::/112')orhasIpAddress('192.168.1.0/24')")//.antMatchers("/actuator/**").denyAll()//.antMatchers("/actuator/**").access("...

    2018年10月27日 Spring Cloud Security
  • Spring Cloud日志异常

    启动异常:```Exceptioninthread"main"java.lang.IllegalArgumentException:LoggerFactoryisnotaLogbackLoggerContextbutLogbackisontheclasspath.EitherremoveLogbackorthecompetingimplementation(classorg.apache.logging.slf4j.Log4jLoggerFactoryloadedfromfile:/C:/Users/Administrator/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.10.0/log4j-slf4j-impl-2.10.0.jar).IfyouareusingWebLogicyouwillneedtoadd'org.slf4j'toprefer-application-packagesinWEB-INF/weblogic.xml:org.apache.logging.slf4j.Log4jLoggerFactoryatorg.spr...

    2018年10月26日 Spring Cloud
  • hystrix配合turbine使用消息队列收集信息

    使用的是SpringCloud2.0。使用`turbine`聚合`hystrix`监控信息,默认使用`turbine`通过`hystrix.stream`获取`hystrix`的信息,依赖:```xmlorg.springframework.cloudspring-cloud-starter-netflix-turbineorg.springframework.cloudspring-cloud-starter-netflix-hystrix```如果使用`stream`来聚合,需要加入`stream`和`stream`的`binder`(`spring-cloud-stream-binder-rabbit`):```xmlorg.springframework.cloudspring-cloud-starter-netflix-turbine-streamorg.springframework.cloudspring-cloud-starter-netflix-hystrixorg.springframework.cloudspring-cloud-netflix-hystrix-stream```prop...

    2018年10月26日 Spring Cloud hystrix turbine
  • Spring Cloud 2.0 zipkin无效

    使用SpringCloud2.0,配置了zipkin后发现并没有发送数据到zipkinserver。原来需要配置数据发送的方法:```spring.zipkin.sender.type=web```项目参考:[https://gitee.com/acgist/api](https://gitee.com/acgist/api)

    2018年10月25日 zipkin Spring Cloud
  • Spring Boot测试时@PropertySource加载不到文件异常

    项目启动时没有问题,但是测试时提示:```Causedby:org.springframework.beans.factory.BeanDefinitionStoreException:Failedtoparseconfigurationclass[com.acgist.main.ApiServiceOrderApplication];nestedexceptionisjava.io.FileNotFoundException:CouldnotopenServletContextresource[/c3p0.properties]atorg.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:184)atorg.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java...

    2018年10月21日 Spring Boot @PropertySource
  • Spring Boot打包后不能访问Freemarker

    我将Freemarker模板打包到jar里面,其他项目引用后不能访问模板,提示:```FreeMarkertemplateerror(DEBUGmode;useRETHROWinproduction!):Templateinclusionfailed(forparametervalue"/include/resources.ftl"):Templatenotfoundforname"/include/resources.ftl".ThenamewasinterpretedbythisTemplateLoader:MultiTemplateLoader(loader1=FileTemplateLoader(baseDir="E:\gitee\api\api-service\api-service-www\target\classes\templates",canonicalBasePath="E:\gitee\api\api-service\api-service-www\target\classes\templates\"),loader2=ClassTemplateLoader(resourceLoader...

    2018年10月19日 Spring Boot Freemarker
  • VirtualBox安装deepin一直加载安装界面

    我是使用虚拟光驱加载的ISO文件,所以安装完成后重启发现又进入到安装界面。这个时候我们只需要在**设备-分配光驱**这个选项里面弹出光驱就可以了,然后重启就可以进入到登陆页面了。

    2018年10月12日 deepin VirtualBox
  • Eclipse插件

    Subclipse:[https://github.com/subclipse/subclipse](https://github.com/subclipse/subclipse)jBoss:[http://download.jboss.org/jbosstools/updates/development/](http://download.jboss.org/jbosstools/updates/development/)Freemarker:[http://download.jboss.org/jbosstools/updates/](http://download.jboss.org/jbosstools/updates/)P3C:[https://p3c.alibaba.com/plugin/eclipse/update](https://p3c.alibaba.com/plugin/eclipse/update)JD-Eclipse:[http://java-decompiler.github.io/](http://java-decompiler.github.io/)汉化:[https://do...

    2018年10月12日 Eclipse
  • Nginx开启TLSv1.3和HTTP/2

    安装最新的openssl:[https://www.openssl.org/source/](https://www.openssl.org/source/),版本:`openssl-1.1.1`。安装命令:```bash#下载解压tar-zxvfopenssl-1.1.1.tar.gzcdopenssl-1.1.1#编译安装./configsharedzlibmakemakeinstall#版本替换rm-rf/usr/bin/opensslrm-rf/usr/include/opensslln-s/usr/local/bin/openssl/usr/bin/opensslln-s/usr/local/include/openssl/usr/include/openssl#注意下面是>>追加内容echo"/usr/local/lib64/">>/etc/ld.so.confldconfig-v```如果使用`yum`安装的Nginx,编译的`openssl`版本不对,所以配置对了也没有效果。**可以先用`yum`安装试试,如果`openssl`版本没问题,可以直接配置**。```bas...

    2018年09月29日 Nginx TLSv1.3 HTTP/2
  • Java11启动异常

    ```Invocationofinitmethodfailed;nestedexceptionisjavax.persistence.PersistenceException:[PersistenceUnit:persistenceUnit]UnabletobuildHibernateSessionFactory;nestedexceptionisorg.hibernate.MappingException:Couldnotgetconstructorfororg.hibernate.persister.entity.SingleTableEntityPersisteratorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1702)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCrea...

    2018年09月28日 Java Tomcat Java11
  • Jackson整理

    ```com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:Unrecognizedfield"test"(classcom.acgist.api.request.pay.PayRequest),notmarkedasignorable(3knownproperties:"orderId","requestTime","sign"])at[Source:(String)"{"test":"test","orderId":"orderId","sign":"sign","queryId":"queryId"}";line:1,column:10](throughreferencechain:com.acgist.api.request.pay.PayRequest["test"])atcom.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:60)atcom.fasterxml.jack...

    2018年09月27日 JSON Jackson
  • fastdfs异常

    安装方法:[https://github.com/happyfish100/fastdfs/wiki](https://github.com/happyfish100/fastdfs/wiki)`storage.conf`配置的`tracker_server`配置项不能是`127.0.0.1:22122`,而应该用`localhost:22122`,不然会提示:```[2018-09-2017:18:15]ERROR-file:storage_func.c,line:1194,conffile"/etc/fdfs/storage.conf",tracker:"127.0.0.1:22122"isinvalid,trackerserveripcan'tbe127.0.0.1[2018-09-2017:18:15]CRIT-exitabnormally!```启动命令:```bash#必须是下面命令/etc/init.d/fdfs_trackerdstart/etc/init.d/fdfs_storagedstart#不能是fdfs_trackerdstartfdfs_storagedstart```

    2018年09月20日 fdfs fastdfs
  • ELK环境搭建

    ELK用来干什么我就不介绍了,主要说一下环境搭建。其实环境搭建非常简单,去官网下载的页面均有搭建步骤。elasticsearch:[https://www.elastic.co/cn/downloads/elasticsearch](https://www.elastic.co/cn/downloads/elasticsearch)logstash:[https://www.elastic.co/cn/downloads/logstash](https://www.elastic.co/cn/downloads/logstash)kibana:[https://www.elastic.co/cn/downloads/kibana](https://www.elastic.co/cn/downloads/kibana)环境:Windows系统、软件版本`6.4.1`、Java10。##elasticsearch下载、解压运行:`bin\elasticsearch.bat`访问:`http://localhost:9200/`##logstash下载、解压配置文件logstash.conf:```input{st...

    2018年09月20日 ELK 日志处理
  • logstash异常

    ```UnrecognizedVMoption'UseParNewGC'Error:CouldnotcreatetheJavaVirtualMachine.Error:Afatalexceptionhasoccurred.Programwillexit.```logstash的版本`6.4.1`,修改`config/jvm.options`,注释掉`-XX:+UseParNewGC`这个配置即可。还有Windows系统配置`input-file`时发现并没有将文件内容发送到`es`,原来是`path`配置的问题:```#下面两种无效D:\elk\logs\*D:\\elk\\logs\\*#下面配置有效D:/elk/logs/*```

    2018年09月20日 logstash ELK
  • JDK内置HTTPClient工具问题

    最新的Java9内置了一个HTTPClient的工具,挺好用的。但是最近发现了一个问题,就是不能设置`User-Agent`请求头。设置了没有效果,至少我现在用的Java10是没有效果的,`Content-type`请求头设置了是有效果的。蒙圈中😕看了一下源代码,这个`header`是不能自定义的:```privatestaticfinalSetDISALLOWED_HEADERS_SET=Set.of("authorization","connection","cookie","content-length","date","expect","from","host","origin","proxy-authorization","referer","user-agent","upgrade","via","warning");publicstaticfinalPredicateALLOWED_HEADERS=header->!Utils.DISALLOWED_HEADERS_SET.contains(header);```然后我仔细再看了一遍,这个判断是区分大小写的,所以大写的`User-Agen...

    2018年09月19日 JDK incubator HttpClient
1...11121314151617...31

关于 ACGIST

Copyright © 2013-2025 ACGIST.COM. All Rights Reserved.