problems_java
1 tomcat运行javaweb项目报错
erorlog:
java.lang.UnsupportedClassVersionError: ... : Unsupported major.minor version 52.0
RCA:
使用高版本的JDK编译的Java class文件试图在较低版本的JVM上运行。jdk高版本能兼容低版本,但是低版本不能兼容高版本。我的项目使用jdk1.8在eclipse编译并运行,然后放到服务器上的jdk为1.7的tomcat中运行,所以报错了。
注:stanford parser和jdk版本对应关系:
J2SE 8 = 52,
J2SE 7 = 51,
J2SE 6.0 = 50,
J2SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45
solution:
修改eclipse配置,然后重新编译导出war包,放到服务器上运行,具体配置如下:
- eclipse中右击项目,点击“Properties”;
- 进入Java Compiler,右侧的Complier Compliance level设为1.7;
- 进入Project Facets,右侧的Java设置为1.7(此项也可以不改,未验证过);
- 进入Java Build Path——Libraries,JRE System Library改为jdk1.7(此项也可以不改,亲测),保证旁边的Order and Export选项卡的JRE System Library的jdk版本与之相同;
- 如果上述还不管用的话试试这个,其实上面的步骤做完,相当于做了这一步,效果完全相同:
打开项目所在的文件夹,打开.settings文件夹,修改里面的org.eclipse.jdt.core.prefs
和
org.eclipse.wst.common.project.facet.core.xml
文件,将所有是1.8的地方修改为1.7
参考链接:https://www.cnblogs.com/jpfss/p/9036645.html
2 前端发起请求报错,响应码500
errorlog:
o.s.w.s.m.m.a.HttpEntityMethodProcessor : Writing [ResultDTO(code=2, message=Could not write JSON: -; nested exception is com.fasterxml.jackson.databin (truncated)...]
m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: -; nested exception is com.fasterxml.jackson.databind.JsonMappingException: - (through reference chain: ResultDTO["data"]->java.util.ArrayList[1]->LaborCostInfoDTO["qn"])]
RCA:
这是jackson的一个bug,当实体类中的某个属性值为 - (英文的中横线)时,报以上错误。
solution:
-
改为 —
(中文的中横线)。
3 Springboot,前端页面请求报错,响应码500
desc:
Springboot,前端页面请求报错
frontend errorlog:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Aug 18 21:48:54 CST 2021
There was an unexpected error (type=Internal Server Error, status=500).
backend errorlog:
2021-08-18 21:48:54.838 ERROR 4286 --- [nio-8888-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: Unknown return value type: java.lang.Integer] with root cause
java.lang.IllegalArgumentException: Unknown return value type: java.lang.Integer
2021-08-18 21:48:54.848 TRACE 4286 --- [nio-8888-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : 2 matching mappings: [{ [/error], produces [text/html]}, { [/error]}]
2021-08-18 21:48:54.849 TRACE 4286 --- [nio-8888-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#errorHtml(HttpServletRequest, HttpServletResponse)
RCA:
controller方法中的返回类型是Integer,但是controller类上的注解是@Controller,不支持返回Integer类型的数据。
solution:
将controller类上的注解由@Controller改为@RestController
4 jinfo -flags <pid>
报错
errorlog:
Attaching to process ID 3992, please wait...
ERROR: ptrace(PTRACE_ATTACH, ..) failed for 3992: 不允许的操作
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 3992: 不允许的操作Attaching to process ID 3992, please wait...
ERROR: ptrace(PTRACE_ATTACH, ..) failed for 3992: 不允许的操作
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 3992: 不允许的操作
RCA:
一些调试软件利用 ptrace 来进行获取某进程的内存状态的(包括GDB), ptrace-scope为了防止用户访问当前正在运行的进程的内存和状态 , 默认情况下不允许再访问了.
solution1: 临时开启: (改方法不行,会提示权限不够,前面加sudo,仍然提示权限不够,直接sudo vim该文件,提示同步失败)
echo 0 > /proc/sys/kernel/yama/ptrace_scope
solution2: 永久开启:
sudo vim /etc/sysctl.d/10-ptrace.conf
# 添加或修改为以下这一句:(0:允许, 1:不允许)
kernel.yama.ptrace_scope = 0
sulution3: 直接使用sudo
sudo /develop/jdk1.8.0_291/bin/jinfo -flags 3992
reference: https://blog.csdn.net/zqz_zqz/article/details/105078992
5 springboot启动报错
errorlog:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource
[org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed;
nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'transferController' method
com.mediocre.controller.TransferController#import()
to {POST [/api/transfer/]}: There is already 'transferController' bean method
com.mediocre.controller.TransferController#export() mapped.
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'transferController' method
com.mediocre.controller.TransferController#import()
to {POST [/api/transfer/]}: There is already 'transferController' bean method
com.mediocre.controller.TransferController#export() mapped
RCA: 同一个controller类中,有2个方法的RequestMapping路径相同。
solution: 将不同方法的路径改为不同。
6 postman发起http请求报错
request:
https://localhost:8888/api/xxx
```js
frontend errorlog:
Error: write EPROTO 8848568547528:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:../../third_party/boringssl/src/ssl/tls_record.cc:242:
backend errorlog:
```java
2021-08-20 10:02:46.703 INFO 6836 --- [nio-8888-exec-1] o.apache.coyote.http11.Http11Processor : Error parsing HTTP request header
Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in method name [0x160x030x010x000xf70x010x000x000xf30x030x030xa240xd20xf00xfd0xc40x990xd0]e0xb30x020xc70x8b>0xf60xa80x9b0xdb0x8c0xa50xd7y0xca<50xa3X0x0b0x840xc30xd6].
HTTP method names must be tokens
RCA: 请求协议出错,不应该为https,而应该是http
solution: 将https改为http
7 javac报错WakeOnLan.java:19: 错误: 编码GBK的不可映射字符
8 javac报错WakeOnLan.java:19: 错误: 编码GBK的不可映射字符
RCA: windows的默认编码是GBK,而java文件的编码是UTF-8.
solution:
-
用UltraEdit打开java文件,查看右下角的状态栏上显示的编码,此处确认是UTF-8。 或者将该java文件复制到eclipse中,右击选择属性,查看其编码。
-
如果确认该文件编码是UTF-8,则javac编译时,添加编码参数:
javac -encoding UTF-8 WakeOnLan.java
9 dom4j解析XML文件报错:无效的 XML 字符 (Unicode: 0x8)
errorlog:
org.dom4j.DocumentException: Error on line 9862 of document : 在 CDATA 节中找到无效的 XML 字符 (Unicode: 0x8)
进入xml文档的9862行,将类似空格的字符一个个删除,一个个测试,当删除某个空格后,这一行不报错了,然后复制该类似空格的字符(0x8),进行全局的查找和替换,将所有的0x8全部替换为普通的空格,然后就不报该错误了。
reference: https://blog.csdn.net/u011823494/article/details/51958064/
然后又报了以下错误:
org.dom4j.DocumentException: Error on line 60679 of document : 文档中根元素后面的标记必须格式正确。
这个比较简单,是因为该xml文档的开头,我删除了<rss>
标签,但是末尾的</rss>
忘记删除了。