我使用的是jjwt-0.9.1.jar,运行时为球衣重置API调用提供了此异常。
[当我使用java main()方法使用此代码时,它可以正常工作,但是当我从servlet调用该类方法时会给出异常。
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import java.util.Date;
import java.util.UUID;
public String createJWTToken() {
String id = UUID.randomUUID().toString().replace("-", "");
//The JWT signature algorithm we will be using to sign the token
// SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
long nowMillis = System.currentTimeMillis();
Date now = new Date(nowMillis);
//Let's set the JWT Claims
JwtBuilder builder = null;
try {
builder = Jwts.builder().setId(id).setHeaderParam("typ", "JWT")
.setIssuedAt(now)
.setSubject("")
.setIssuer(API_KEY)
.signWith(SignatureAlgorithm.HS256,SECRET_KEY.getBytes("UTF-8"));
//if it has been specified, let's add the expiration
if (ttlMillis >= 0) {
long expMillis = nowMillis + ttlMillis;
Date exp = new Date(expMillis);
builder.setExpiration(exp);
}
} catch (Exception e) {
e.printStackTrace();
}
return builder.compact();//Builds the JWT and serializes it to a compact, URL-safe string
}
当调用servlet到Java类方法时,即createJWTToken()在tomcat中给出以下异常。
javax.servlet.ServletException:Servlet执行在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210处的org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:328)处引发了异常)的org.apache.catalina.core.ApplicationFilterChain的com.test.lms.servlets.GlobalFilter.doFilter(GlobalFilter.java:48)的com.test.lms.servlets.GlobalFilter.doFilter(GlobalFilter.java:204)。 org.apache.catalina.core处的internalDoFilter(ApplicationFilterChain.java:243)com.general.FilterDemo.doFilter(FilterDemo.java:312)处的org.apache.catalina.core处的ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)位于org.apache.catalina.core的.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)位于org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)处的ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) org.apache.catalina.core.Standa org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)上的org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)上的rdContextValve.invoke(StandardContextValve.java:169) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)上的.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve .java:118)位于org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)位于org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:200)位于org.apache.coyote。 org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:307)处的AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:579)在java.util.concurrent.ThreadPoolExecutor.runWorker(未知源) java.lang.Thread.run中的java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知源) urce)由以下原因引起:java.lang.NoClassDefFoundError:com.zoom.JWTTokenGeneration.createJWTToken(JWTTokenGeneration.java:31)的io / jsonwebtoken / Jwts com.general的com.zoom.Utilities.setMeeting(Utilities.java:571)的io / jsonwebtoken / Jwts org.apache处的javax.servlet.http.HttpServlet.service(HttpServlet.java:641)处的.InsertController.doPost(InsertController.java:377)在org.apache处的javax.servlet.http.HttpServlet.service(HttpServlet.java:722)处。 catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)... 22更多原因:java.lang.ClassNotFoundException:io.jsonwebtoken.Jwts位于org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java: 1701),位于org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)... 28其他
例外是java.lang.NoClassDefFoundError:io / jsonwebtoken / Jwts
检查Jar文件(jwt)是否打包在内部版本中?