-
Zuul统一异常处理
今天研究了一下Zuul,看书上的例子,最后发现异常处理的和书上的并不一样。书上使用的是`1.x`,我做的时候用的最新的`2.x`的版本。这里也做一下记录。首先是`SendErrorFilter`这个类,现在`filterType`已经是`error`的了:```java@OverridepublicStringfilterType(){returnERROR_TYPE;}```所以,现在异常都会到这个`filter`里面,而这个`filter`里面最后直接是`forward`到了`/error`这个链接上面。所以这里就出现了一个很奇怪的现象,如果进入到Zuul的`filter`链里面来后,在`SendErrorFilter`之前发生了异常,那么我们会发现请求数据已返回后,会再次进入到我们自定义的`post`的`filter`里面。下面就是`SendErrorFilter`里面的处理:```javaRequestDispatcherdispatcher=request.getRequestDispatcher(this.errorPath);if(dispatcher!=null){ctx.set(SEND_E...
Zuul Spring Cloud -
Spring Boot静态资源不能访问问题
之前做了一个demo,当时并没有注意,后来发现静态资源不能访问了。SpringBoot自动配置了`classpath:/static/`下面的资源为静态资源,后来网上找了很多的方法都试过了,解决不了。于是我重新写了一个项目,把这个旧项目的配置一个一个的移动过去,最后发现是我配置的拦截器的问题。因为我配置拦截器继承的类是:`WebMvcConfigurationSupport`这个类,它会让SpringBoot的自动配置失效。👿怎么解决呢?*继承`WebMvcConfigurerAdapter`,当然如果使用`Java8+`,那么`WebMvcConfigurerAdapter`这个类以及过时了,可以直接实现`WebMvcConfigurer`接口,然后重写`addInterceptors`来添加拦截器:```java@ConfigurationpublicclassInterceptorConfigimplementsWebMvcConfigurer{@OverridepublicvoidaddInterceptors(InterceptorRegistryregistry){registry.addInt...
Spring Boot 静态资源 WebMvcConfigurationSupport EnableWebMvc -
Chrome非安全端口
今天测试开了一个`6666`端口的服务,发现`Chrome`浏览器一直无法访问,提示:```无法访问此网站网址为http://localhost:6666/的网页可能暂时无法连接,或者它已永久性地移动到了新网址。ERR_UNSAFE_PORT```控制台:```RequestURL:http://www.acgist.com:6666/ReferrerPolicy:no-referrer-when-downgradeProvisionalheadersareshownUpgrade-Insecure-Requests:1User-Agent:Mozilla/5.0(WindowsNT6.1;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/65.0.3325.146Safari/537.36X-DevTools-Emulate-Network-Conditions-Client-Id:8556438C2AB21D3F7DD6045E8CE4FD74```一开始我一直以为是`CpringCloudZuul`的配置错了,排查了很久,最后我换了一个端口发现可以了...
Chrome 6666 -
feign异常整理
```ErrorstartingApplicationContext.Todisplaytheconditionsreportre-runyourapplicationwith'debug'enabled.2018-04-2510:26:07.335ERROR9924---[main]o.s.b.d.LoggingFailureAnalysisReporter:***************************APPLICATIONFAILEDTOSTART***************************Description:FielduserServiceincom.acgist.controller.UserControllerrequiredabeanoftype'com.acgist.service.IUserService'thatcouldnotbefound.Action:Considerdefiningabeanoftype'com.acgist.service.IUserService'inyourconfiguration.```启动上面的异常或者直接进入到`fallback`...
feign Spring Cloud -
推荐书籍
整理一些可以多次品位的书籍。即使在网上看些文章零散的学习,还是不如直接读书进行系统的学习。平时除了读一些工作相关书籍提升职业技能,还要多看看经济学、心理学、社会学的书籍提升自己,当然也少不了国学。经济学、心理学、社会学可以帮助我了解人与人、人与社会的关系以及怎么处理好这些关系。国学不仅可以让我了解历史,还可以看到华丽的辞藻,美丽的诗句,还有很多有趣的小故事。最重要的是让我知道需要成为什么样的人,怎么成为这样的人。悟性高的人也可以从中领悟很多心理学、经济学和社会学问题。其实读古人的书很多时候也是因为我们和古圣先贤也有一样的境遇。借鉴他们的事迹,吸取他们的教训,我们可以更好的完善自己。让我们在历史的长河里面不至于孤独,与古人行幸甚至哉。##人生格局影响力时间简史解读基金人性的弱点社会心理学经济学原理财务自由之路股票作手回忆录指数基金投资指南>心理学、经济学、社会学##技术机器学习Redis实战**高性能MySQL****代码整洁之道****架构整洁之道**设计模式之禅**Java编程思想****HTTP权威指南****Netty权威指南**Neo4j权威指南Kafka权威指南程序员修炼之道JUnit实战第二...
推荐 书籍 -
Java8+时间格式化错误
```Exceptioninthread"main"java.time.temporal.UnsupportedTemporalTypeException:Unsupportedfield:HourOfDayatjava.base/java.time.LocalDate.get0(LocalDate.java:708)atjava.base/java.time.LocalDate.getLong(LocalDate.java:687)atjava.base/java.time.format.DateTimePrintContext.getValue(DateTimePrintContext.java:308)atjava.base/java.time.format.DateTimeFormatterBuilder$NumberPrinterParser.format(DateTimeFormatterBuilder.java:2691)atjava.base/java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(Date...
Java8 时间格式化 LocalDate LocalDateTime DateTimeFormatter -
Spring AOP错误
```ErroroccuredprocessingXML'com/acgist/module/aop/admin/AdminSignhasbeencompiledbyamorerecentversionoftheJavaRuntime(classfileversion54.0),thisversionoftheJavaRuntimeonlyrecognizesclassfileversionsupto52.0'.SeeErrorLogformoredetails```升级了最新的Java10,然后`aspectjweaver`和`aspectjrt`都升级到了`1.9.0`,但是还是提示上面的错误,感觉很纳闷。项目的JDK也设置成了JDK10,怎么还是有这个错误。最后发现原来是Eclipse启动的JDK还是`1.8`的问题导致的。修改Eclipse的配置`eclipse.ini`如下:```-startupplugins/org.eclipse.equinox.launcher_1.4.0.v20161219-1356.jar--launcher.libraryplugins/org.eclipse.equi...
Spring AOP -
Spring Cloud异常
```com.sun.jersey.api.client.ClientHandlerException:java.net.ConnectException:Connectionrefused:connectatcom.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187)~[jersey-apache-client4-1.19.1.jar:1.19.1]atcom.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123)~[jersey-client-1.19.1.jar:1.19.1]atcom.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27)~[eureka-client-1.8.7.jar:1.8.7]atcom.s...
Spring Cloud -
Linux Java生成文件权限不够
今天升级了Java10,Tomcat9,一开始没发现问题,后来发现发布的文章全部`403forbidden`。一看文件的权限:`-rw-r-----`,权限不对导致`Nginx`不能访问。一开始我还以为是升级JDK的问题,后来我用`jshell`创建了一个文件发现权限是`-rw-r--r--`。猜想到可能是Tomcat的权限不对。然后看了一下Tomcat启动命令里面有一个参数:```-Dorg.apache.catalina.security.SecurityListener.UMASK=0027```再看了一下`catalina.sh`文件:```#SetUMASKunlessithasbeenoverriddenif[-z"$UMASK"];thenUMASK="0027"fiumask$UMASK```把0027修改为0022就OK了。
Linux Java Tomcat Nginx -
Spring获取bean异常
```org.springframework.beans.factory.BeanNotOfRequiredTypeException:Beannamed'wordService'isexpectedtobeoftype'com.acgist.service.impl.WordService'butwasactuallyoftype'com.sun.proxy.$Proxy51'atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:389)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:224)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.ja...
Spring -
slf4j log4j错误
错误内容,系统的日志没有输出:```MLoginitializationissue:slf4jfoundnobindingorthreatenedtouseits(dangerouslysilent)NOPLogger.Weconsidertheslf4jlibrarynotfound.```缺少依赖`slf4j-log4j12`,添加后就没问题了
slf4j log4j -
Tomcat 9 + Java 10 + Eclipse启动错误
今天把JDK升级到10以后发现Tomcat启动不了,启动提示:```-Djava.endorsed.dirs=D:\develop\apache-tomcat-9.0.7\endorsedisnotsupported.EndorsedstandardsandstandaloneAPIsinmodularformwillbesupportedviatheconceptofupgradeablemodules.```原来上面的启动参数已经不支持,启动时删除掉就可以了,配置如图:![Tomcat配置](//static.acgist.com/resources/images/article/201804/15236720592771001.png)如果Eclipse启动提示:```IncompatibleJVMVersion1.8.xxxxoftheJVMisnotsuitableforthisproduct.Version:10orgreaterisrequired.```那么就是你安装的JDK版本过低(path配置),然后你在Eclipse配置`eclipse.ini`中添加了`-Dosgi.requiredJ...
Tomcat 9 Java 10 Eclipse -
Spring Boot整合Dubbo
##安装ZooKeeper:下载:[http://archive.apache.org/dist/zookeeper/zookeeper-3.4.8/](http://archive.apache.org/dist/zookeeper/zookeeper-3.4.8/)启动:bin/zkServer##Dubbo管理项目:dubbo-admin:[https://github.com/apache/incubator-dubbo-ops](https://github.com/apache/incubator-dubbo-ops)使用Maven打包后放入到Tomcat后启动Tomcat。打包出现一下错误:```[ERROR]Failedtoexecutegoalorg.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile(default-compile)onprojectdubbo-admin:Compilationfailure[ERROR]Failureexecutingjavac,butcouldnotparsetheerror:[ERROR]...
Spring Boot Dubbo -
Spring Boot异常整理
这里是一个SpringBoot的示例,里面包含了一些JPA、C3P0连接池、AOP、拦截器、Freemarker、缓存的配置。地址:[https://gitee.com/acgist/demo/tree/master/springboot](https://gitee.com/acgist/demo/tree/master/springboot)后面是一些遇到的错误整理。SpringBoot和Java9,启动时出现以下错误:```Causedby:java.lang.NoClassDefFoundError:javax/xml/bind/JAXBException```这个是因为Java9模块化,所以以前JavaEE的一些包放到了`java.se.ee`模块,默认导入模块`java.se`是不包含以前的一些功能了。所以需要启动参数添加`--add-modulesjava.xml.bind`或者修改JDK为9以前的版本。添加参数如图:![Eclipse添加JVM启动参数](//static.acgist.com/resources/images/article/201804/15236775496391002....
Spring Boot Java 模块化 -
Spring Cloud异常整理
从[http://start.spring.io/](http://start.spring.io/)打包下来的程序运行时提示:```NoSuchMethodError:org.springframework.boot.builder.SpringApplicationBuilder.```网上我看到说的是SrpingBoot的版本和SpringCloud的版本冲突导致,但是这个是从官网下载的demo不应该出现这个问题。最后我有从新使用`mvnspring-boot:run`命令在控制台跑才发现问题,控制台提示:```[INFO]Changesdetected-recompilingthemodule![INFO]Compiling1sourcefiletoC:\Users\Administrator\Desktop\demo\target\classes[INFO]-------------------------------------------------------------[ERROR]COMPILATIONERROR:[INFO]--------------------------------...
Spring Cloud Spring Boot -
Spring Cloud 2.0和1.x中变化
SpringCloud从`1.x`升级到`2.0`后一些配置就不同了。主要列一些`starterpoms`的变化:*`spring-cloud-starter-eureka-server`升级后`spring-cloud-starter-netflix-eureka-server`*`hystrix-dashboard`的监控地址变了`http://localhost:9999/actuator/hystrix.stream`
Spring Cloud starter poms -
Maven私服仓库
使用Maven的私服仓库时,发现一些包不能进行更新。出现一下错误:```E:\git\spring\eureka-server>mvneclipse:eclipse[INFO]Scanningforprojects...Downloading:http://192.168.1.241:9081/nexus/content/groups/public/org/springframework/cloud/spring-cloud-dependencies-parent/2.0.0.RC2/spring-cloud-dependencies-parent-2.0.0.RC2.pom[ERROR]Thebuildcouldnotread1project->[Help1][ERROR][ERROR]Theprojectcom.acgist:eureka-server:1.0.0(E:\git\spring\eureka-server\pom.xml)has3errors[ERROR]Non-resolvableparentPOM:Couldnotfindartifactorg.springframework...
Maven -
Java创建自定义运行时映像
使用`jlink`创建一个运行时的映像,可以让运行环境最小化。使用命令:```jlink-v--module-pathlib;"D:\ProgramFiles\Java\jdk-10\jmods"--launcherrun=com.modules--add-modulescom.modules--outputtest```在使用JDK9的时候,没有问题,但是换到JDK10的时候就出现以下错误:```提供方:java.baseprovidesjava.nio.file.spi.FileSystemProviderusedbyjava.base错误:java.lang.IllegalArgumentException```😭原因是环境变量里面配置的JDK路径是JDK9的,所以就出现了上面的错误。>jimage学习:[http://www.cnblogs.com/IcanFixIt/p/7110790.html](http://www.cnblogs.com/IcanFixIt/p/7110790.html)
Java jlink jimage -
Spring Boot 2.0安全配置
升级2.0以后一些配置需要修改,下面是一些安全方面的配置:```#安全配置#management.security.enabled=true#配置用户#spring.security.user.name=user#spring.security.user.password=user#spring.security.user.roles=USER#manager端口management.server.port=9999#manager权限角色#management.security.roles=ADMIN#manager的上下文management.server.servlet.context-path=/admin#公开端点management.endpoints.web.exposure.include=*#隐藏端点management.endpoints.web.exposure.exclude=env```添加用户和角色:*配置USER角色,包含一个用户名为user,密码为user的用户。*配置ADMIN角色,包含一个用户名为admin,密码为admin的用户。```java@BeanpublicInM...
Sprint Boot 安全 security -
Spring Boot配置加载
SpringBoot默认加载的是`application.properties`和`application.yml`,如果两个配置同时存在时,默认使用会使用`properties`的配置替换`yml`,可以理解为先加载`yml`,然后加载`properties`进行替换。如果配置了`spring.profiles.active`属性时,还会加载`application-{profiles}.properties`或`application-{profiles}.yml`。上面文件加载的顺序是:`application.yml``application-{profiles}.yml``application.properties``application-{profiles}.properties`,后面的配置会替换前面的配置。##自定义配置###自定义properties```email.port=22email.name=email-nameemail.user.names=user-namesemail-tencent.port=tencent-22email-tencent.name=email-ten...
Spring Spring Boot