一、中文字符乱码
1、修改webdefault.xml文件zh编码为utf-8
<locale-encoding-mapping>
<locale>zh</locale>
<encoding>UTF-8</encoding>
</locale-encoding-mapping>
2、在application.properties文件增加http编码配置
spring.http.encoding.charset=UTF-8 spring.http.encoding.enabled=true spring.http.encoding.force=true
二、启动错误java.lang.RuntimeException: Error scanning entry module-info.class from jar ...
详细错误:
2018-07-17 08:08:15.981:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.w.WebAppContext@34b7bfc0{/mp_store,file:/usr/local/jetty-9.2.25/webapps/mp_store/,STARTING}{/mp_store}
java.lang.RuntimeException: Error scanning entry module-info.class from jar file:/usr/local/jetty-9.2.25/webapps/mp_store/WEB-INF/lib/asm-all-repackaged-2.5.0-b32.jar
at org.eclipse.jetty.annotations.AnnotationParser.parseJar(AnnotationParser.java:913)
at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:831)
at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call(AnnotationConfiguration.java:164)
at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run(AnnotationConfiguration.java:549)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:748)
Caused by:
java.lang.IllegalArgumentException
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.jetty.annotations.AnnotationParser.scanClass(AnnotationParser.java:973)
at org.eclipse.jetty.annotations.AnnotationParser.parseJarEntry(AnnotationParser.java:956)
at org.eclipse.jetty.annotations.AnnotationParser.parseJar(AnnotationParser.java:909)
at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:831)
at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call(AnnotationConfiguration.java:164)
at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run(AnnotationConfiguration.java:549)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:748)
原因是asm-all-repackaged-2.5.0-b32.jar编译的jdk9,而服务器我配置的是jdk8,因此降低asm-all-repackaged版本,
<dependency> <groupId>org.glassfish.hk2.external</groupId> <artifactId>asm-all-repackaged</artifactId> <version>2.4.0</version> </dependency>
三、配置contextPath
在webapps目录,默认以war包的名字作为contextPath。比如war包名为test.war,那么contextPath就为test。当然如果war包是root.war,那么contextPath为“/”。
另外可以在webapps目录增加war包名对应的xml文件实现配置与war包名不同的contextPath。如war包为test.war,则对应增加test.xml文件,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/test1</Set>
<Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test.war</Set>
</Configure>
这样就设置contextPath为test1了。对应的url就为http://localhost:8080/test1
四、修改jetty端口
jetty9修改端口方法:
修改start.ini文件的jetty.port的值即可