-
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.```原来上面的启动参数已经不支持,启动时删除掉就可以了,配置如图:如果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以前的版本。添加参数如图:打包下来的程序运行时提示:```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 -
Nginx+Tomcat正确获取客户端请求地址
如果使用的是HTTP协议,直接使用如下配置,即可获取到客户端请求地址和IP信息:```proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;```但是如果使用了Nginx使用了HTTPS协议,但是反向代理时使用的是HTTP协议,那么上面的代码就不能获取到正确的协议。Nginx还需要添加如下配置:```proxy_set_headerX-Forwarded-Proto$scheme;```然后Tomcat的Engine下添加如下配置:``````这样就能正确获取到协议信息了。这里还需要说明一点,上面配置均需要配置到`location`中方能有效,之前一直配置在`server`模块内是无效的。>参考文章:[http://feitianbenyue.iteye.com/blog/2056357](http://feitianbenyue.iteye.com/blog/2056357)如果是SpringBoot内嵌的Tomc...
Nginx Tomcat Spring Boot -
Tomcat无法读取手动修改资源文件
在Tomcat下面手动修改资源文件,发现使用`getResourceAsStream`重新读取配置并没有被修改。然后看了一下源码发现,Tomcat对资源文件进行了缓存:```java//(0)Checkforacachedcopyofthisresourcestream=findLoadedResource(name);if(stream!=null){if(log.isDebugEnabled())log.debug("-->Returningstreamfromcache");return(stream);}```所以导致使用`SuccessCodeConfig.class.getResourceAsStream("/successCode.properties");`读取配置时不能读取到修改的内容。所以应该修改为:```javanewFileInputStream(SuccessCodeConfig.class.getResource("/successCode.properties").getFile());```
Tomcat Java -
box-sizing
经常发现`select`和`input`设置的属性一样但是发现两者的实际显示效果不一致,这是因为`box-sizing`属性导致的。>具体参考:[http://www.w3school.com.cn/cssref/pr_box-sizing.asp](http://www.w3school.com.cn/cssref/pr_box-sizing.asp)
box-sizing CSS -
JPA自动生成设置外键名称
使用JPA的`@ManyToOne`时,生成了外键,而且用的`generateDdl`配置自动生成。如果想修改外键名称,可以使用`@ForeignKey`注解去修改外键名称。
JPA Hibernate -
Postman将JSON字符串作为表单数据提交
使用Postman模拟请求,但是发现`body`的`form-data`里面,放入JSON字符串,发送时并不能自动拆分为表单数据。我们选择`body`后面有一个`key-valueedit`的选项,点击后进入以下界面:然后直接粘贴复制的`JSON`字符串就可以自动将你的`JSON`字符串变为表单数据了。
Postman JSON form-data