我公司后端应用程序的 war 大小约为 100 MB,因此我们决定将所有 maven 依赖项的范围更改为提供。罐子从 .war 移动到 opt/tomcat/shared/lib 文件夹(根据此指令https://www.mulesoft.com/tcat/tomcat-classpath)。一切都很好,我们使用此配置在此服务器上部署了 2 个后端应用程序。在我们添加第三个类似的后端应用程序后,我们无法在 oauth2 服务中使用登录,因为在日志中我们可以看到以下错误:
org.springframework.cglib.core.CodeGenerationException: java.lang.LinkageError-->loader java.net.URLClassLoader @2f943d71 (instance of java.net.URLClassLoader, child of java.net.URLClassLoader @bd8db5a java.net.URLClassLoader) attempted duplicate class definition for org.springframework.security.oauth2.provider.token.DefaultTokenServices$$FastClassBySpringCGLIB$$5a1f25c.
前两个应用程序仍然可以正常工作,但第三个不能。在每次部署之前,我们都会清除 tomcat 的工作文件夹。我们使用 Java 11 SpringBoot2、OpenJDK 11、Tomcat 9.0.21。类 DefaultTokenServices 位于 spring-security-oauth2-2.3.5.RELEASE.jar 中,我们将其与其他 jar 一起放在 opt/tomcat/shared/lib 文件夹中。