啊
BaseConfig.java
public class BaseConfig extends JFinalConfig { @Override public void configPlugin(Plugins plugins) { // …………………… final ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin); // …………………… JwqConfigKit.configArp(arp); // 第216行 // …………………… } }
jwq-1.0.jar --> JwqConfigKit.java
package top.xpman.jwq.kit; import com.jfinal.ext.annotation.Table; import com.jfinal.ext.enjoy.sql.ParaInDirective; import com.jfinal.ext.enjoy.sql.ParaLikeDirective; import com.jfinal.kit.StrKit; import com.jfinal.plugin.activerecord.ActiveRecordPlugin; import com.jfinal.plugin.activerecord.Model; import com.jfinal.template.Engine; import java.util.Arrays; import java.util.Collection; import java.util.List; import org.jetbrains.annotations.NotNull; import top.xpman.jwq.model.SysJwq; import top.xpman.jwq.model.SysJwqCol; import top.xpman.jwq.model.SysJwqTemplate; public class JwqConfigKit { private JwqConfigKit() { } public static void configArp(@NotNull ActiveRecordPlugin arp) { configSqlEngine(arp.getEngine()); configModel(arp); configSqlTemplate(arp); } public static void configSqlEngine(@NotNull Engine engine) { engine.addDirective("paraIn", ParaInDirective.class).addDirective("paraLike", ParaLikeDirective.class); } public static void configSqlTemplate(@NotNull ActiveRecordPlugin arp) { arp.addSqlTemplate("templates/sql/jwq.sql"); } public static void configModel(@NotNull ActiveRecordPlugin arp) { configModel(arp, List.of(SysJwq.class, SysJwqCol.class, SysJwqTemplate.class)); } // ....... }
jwq项目依赖:
dependencies { testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' compileOnly( "com.alibaba:fastjson:${fastjsonVersion}", "com.jfinal:jfinal:${jfinalVersion}", "javax.servlet:javax.servlet-api:${javaxServletApiVersion}", "org.jetbrains:annotations:${annotationsVersion}", ) }
主项目:
dependencies { testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' implementation ( // jfinal相关 "com.jfinal:jfinal-undertow:${jfinalUndertowVersion}", "com.jfinal:jfinal:${jfinalVersion}", "com.jfinal:cos:${jfinalCosVersion}", // 日志相关 "org.slf4j:slf4j-nop:${slf4jNopVersion}", "log4j:log4j:${log4jVersion}", // 数据库相关 "mysql:mysql-connector-java:${mysqlConnectorVersion}", "com.alibaba:druid:${druidVersion}", "javax.servlet:javax.servlet-api:${javaxServletApiVersion}", "org.jetbrains:annotations:${annotationsVersion}", "com.alibaba:fastjson:${fastjsonVersion}", "it.sauronsoftware.cron4j:cron4j:${cron4jVersion}", "net.sf.ehcache:ehcache:${ehcacheVersion}", ) implementation 'top.xpman:jwq:1.0' }
异常:
Exception in thread "main" java.lang.LinkageError: loader constraint violation: loader 'app' wants to load class com.jfinal.plugin.activerecord.ActiveRecordPlugin. A different class with the same name was previously loaded by com.jfinal.server.undertow.hotswap.HotSwapClassLoader @464bee09. (com.jfinal.plugin.activerecord.ActiveRecordPlugin is in unnamed module of loader com.jfinal.server.undertow.hotswap.HotSwapClassLoader @464bee09, parent loader 'app') at java.base/java.lang.ClassLoader.defineClass1(Native Method) at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012) at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150) at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862) at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) at top.xpman.jwq.kit.JwqConfigKit.configArp(JwqConfigKit.java:29) at cn.jiulianfu.business.common.BaseConfig.configPlugin(BaseConfig.java:216) at com.jfinal.core.Config.configPluginWithOrder(Config.java:70) at com.jfinal.core.Config.configJFinal(Config.java:59) at com.jfinal.core.JFinal.init(JFinal.java:61) at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:64) at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:111) at io.undertow.servlet.core.ManagedFilter.createFilter(ManagedFilter.java:80) at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:594) at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:559) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43) at io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerImpl.java:601) at com.jfinal.server.undertow.UndertowServer.configHttp(UndertowServer.java:302) at com.jfinal.server.undertow.UndertowServer.doStart(UndertowServer.java:280) at com.jfinal.server.undertow.UndertowServer.start(UndertowServer.java:153) at com.jfinal.ext.undertow.ServerStarter.run(ServerStarter.java:60) at com.jfinal.ext.undertow.ServerStarter.run(ServerStarter.java:25) at cn.jiulianfu.business.Main.main(Main.java:13)