当前位置: 首页 > 知识库问答 >
问题:

jetty-maven-plugin和tomcat-jdbc 8.0.9之间的类路径问题导致ServiceConfigurationError

张玺
2023-03-14

我正在使用以下软件开发应用程序:

jetty maven插件:9.3.2。v20150730
tomcat jdbc:8.0.8(依赖于tomcat juli)

尝试将tomcat jdbc jar升级到8.0.9以外的任何版本后,我遇到以下错误:

java.util.服务配置错误:org.apache.juli.logging.日志:提供程序org.eclipse.jetty.apache.jsp.JuliLog不是子类型

查看这两个版本之间的变更日志,我发现了一些可疑的内容:

“向JULI LogFactory添加一个简单的基于ServiceLoader的发现机制,使依赖于JULI(如Jasper)的JULI和Tomcat组件更容易使用,而不依赖于Tomcat。由Greg Wilkins提供的修补程序。(markt)”

另外,我发现Apache Tomcat JDBC连接池中引入了一个新的系统属性:

组织。阿帕奇。公猫jdbc。水塘仅限当前类加载器

控制动态类(如JDBC驱动程序、拦截器和验证器)的类加载。如果设置为false,则池将首先尝试使用当前加载程序(即加载池类的类加载程序)加载如果类加载失败,则尝试使用线程上下文加载程序加载。如果希望与Apache Tomcat 8.0.8及更早版本保持向后兼容,并且只尝试当前加载程序,请将此值设置为true。如果未设置,则默认值为false。"

不幸的是,使用这个属性启动jetty:run插件并没有解决这个问题。

任何帮助将不胜感激!谢谢!

堆栈跟踪和依赖关系树:

Caused by: 
java.util.ServiceConfigurationError: org.apache.juli.logging.Log: Provider org.eclipse.jetty.apache.jsp.JuliLog not a subtype
    at java.util.ServiceLoader.fail(ServiceLoader.java:239)
    at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
    at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376)
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
    at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
    at org.apache.juli.logging.LogFactory.(LogFactory.java:78)
    at org.apache.juli.logging.LogFactory.(LogFactory.java:66)
    at org.apache.tomcat.jdbc.pool.DataSourceFactory.(DataSourceFactory.java:58)
    at local.ristretto.persistence.datasource.mail.MailDataSourceConfiguration.dataSource(MailDataSourceConfiguration.java:31)
    at local.ristretto.persistence.datasource.mail.MailDataSourceConfiguration$$EnhancerBySpringCGLIB$$497970dd.CGLIB$dataSource$0()
    at local.ristretto.persistence.datasource.mail.MailDataSourceConfiguration$$EnhancerBySpringCGLIB$$497970dd$$FastClassBySpringCGLIB$$2ba2dde9.invoke()
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
    at local.ristretto.persistence.datasource.mail.MailDataSourceConfiguration$$EnhancerBySpringCGLIB$$497970dd.dataSource()
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813)
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:464)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:434)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:798)
    at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:530)
    at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:771)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:342)
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1368)
    at org.eclipse.jetty.maven.plugin.JettyWebAppContext.startWebapp(JettyWebAppContext.java:320)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1335)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:735)
    at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:259)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:511)
    at org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:403)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:161)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
    at org.eclipse.jetty.server.Server.start(Server.java:405)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:106)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
    at org.eclipse.jetty.server.Server.doStart(Server.java:372)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.maven.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:457)
    at org.eclipse.jetty.maven.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:328)
    at org.eclipse.jetty.maven.plugin.JettyRunMojo.execute(JettyRunMojo.java:170)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:1.8.2.RELEASE:compile               
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:1.10.2.RELEASE:compile       
[INFO] |  |  +- org.springframework:spring-orm:jar:4.1.7.RELEASE:compile                      
[INFO] |  |  |  \- org.springframework:spring-jdbc:jar:4.1.7.RELEASE:compile                  
[INFO] |  |  +- org.springframework:spring-tx:jar:4.1.7.RELEASE:compile                       
[INFO] |  |  \- org.aspectj:aspectjrt:jar:1.8.6:compile                                       
[INFO] |  +- org.postgresql:postgresql:jar:9.4-1202-jdbc42:compile                            
[INFO] |  +- org.apache.tomcat:tomcat-jdbc:jar:8.0.9:compile                                 
[INFO] |  |  \- org.apache.tomcat:tomcat-juli:jar:8.0.9:compile                              
[INFO] |  +- org.hibernate:hibernate-entitymanager:jar:5.0.1.Final:compile                    
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile                       
[INFO] |  |  +- org.hibernate:hibernate-core:jar:5.0.1.Final:compile                          
[INFO] |  |  |  +- antlr:antlr:jar:2.7.7:compile                                              
[INFO] |  |  |  \- org.jboss:jandex:jar:1.2.2.Final:compile                                   
[INFO] |  |  +- dom4j:dom4j:jar:1.6.1:compile                                                 
[INFO] |  |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile                                       
[INFO] |  |  +- org.hibernate.common:hibernate-commons-annotations:jar:5.0.0.Final:compile    
[INFO] |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile 
[INFO] |  |  +- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile             
[INFO] |  |  \- org.javassist:javassist:jar:3.18.1-GA:compile                                 
[INFO] |  \- com.fasterxml.jackson.core:jackson-databind:jar:2.6.1:compile                    
[INFO] |     +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.1:compile              
[INFO] |     \- com.fasterxml.jackson.core:jackson-core:jar:2.6.1:compile                     

[INFO] |  +- org.slf4j:jcl-over-slf4j:jar:1.7.12:compile                                      
[INFO] |  +- org.slf4j:jul-to-slf4j:jar:1.7.12:compile                                        
[INFO] |  +- org.slf4j:log4j-over-slf4j:jar:1.7.12:compile                                    
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.12:compile                                           
[INFO] |  +- ch.qos.logback:logback-classic:jar:1.1.3:compile                                 
[INFO] |  |  \- ch.qos.logback:logback-core:jar:1.1.3:compile                                 
[INFO] |  +- org.wicketstuff:wicketstuff-logback:jar:6.20.0:compile                           
[INFO] |  +- org.apache.commons:commons-lang3:jar:3.4:compile                                 
[INFO] |  +- org.apache.commons:commons-collections4:jar:4.0:compile                          
[INFO] |  +- commons-io:commons-io:jar:2.4:compile                                            
[INFO] |  +- commons-codec:commons-codec:jar:1.10:compile                                     
[INFO] |  +- commons-beanutils:commons-beanutils:jar:1.9.2:compile                            
[INFO] |  |  \- commons-collections:commons-collections:jar:3.2.1:compile                     
[INFO] |  \- com.google.guava:guava:jar:18.0:compile                                          
[INFO] +- junit:junit:jar:4.12:test                                                           
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test                                          
[INFO] +- org.springframework:spring-test:jar:4.1.7.RELEASE:test                              
[INFO] |  \- org.springframework:spring-core:jar:4.1.7.RELEASE:compile                        
[INFO] +- org.springframework:spring-web:jar:4.1.7.RELEASE:compile                            
[INFO] |  +- org.springframework:spring-aop:jar:4.1.7.RELEASE:compile                         
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile                                       
[INFO] |  +- org.springframework:spring-beans:jar:4.1.7.RELEASE:compile                       
[INFO] |  \- org.springframework:spring-context:jar:4.1.7.RELEASE:compile                     
[INFO] |     \- org.springframework:spring-expression:jar:4.1.7.RELEASE:compile               
[INFO] \- javax:javaee-web-api:jar:7.0:provided

共有3个答案

云京
2023-03-14

如果不是Spring项目

以下是我在pom中提供的排除项。xml:

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.4.24.v20191120</version>
             <exclusions>
                <exclusion>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>apache-jsp</artifactId>
                </exclusion>
             </exclusions>
        </dependency>

还提供了插件:

           <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.4.24.v20191120</version>

                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <webApp>
                        <contextPath>/ezops-preprocessor</contextPath>
                    </webApp>
                </configuration>

            </plugin>

有了上面的排除,apachejsp(Jule Logging),我就不会得到那个异常。

希望这有帮助。!!!

涂溪叠
2023-03-14

这似乎是由Jetty使用修改过的ApacheJSP包Jasper造成的。它有自己版本的Juli日志(在Jetty主目录下检查lib/apachejsp/org.mortbay.jasper.apache-jsp-8.0.27.jar),这似乎引起了所有的混乱。我认为,Jetty默认的webapp类加载逻辑会导致每次请求该类时都从webapp加载JuliLogFactory。当LogFactory必须加载tomcatjdbc类时,一切都很好。当它通过Jetty修改过的Jasper类时,会变得很棘手,因为它意识到存在类型冲突。

你如何解决这个问题?我认为有两种方法可以做到:

1.更改Jetty webapp类加载器逻辑

您可以修改类加载器逻辑,以便始终将类加载委托给父类加载器。您只需在特定的WebAppContext上调用setParentLoaderPriority(true)。您可以通过Jetty配置或包含Jetty web来实现这一点。xml文件与您的war。

2.排除tomcat juli依赖项

使用Maven的依赖排除,您可以跳过任何您不喜欢的传递依赖。所以只要包含tomcat-jdbc而不包含tomcat-juli,就完成了。

唯一的问题是,这两种解决方案都迫使您使用Jetty修改的Juli包。还没有看到这样的场景有问题,但是我想在某个时候你可能会发现你丢失了一些功能,因为Jetty修改后的Juli没有与Apache最新版本同步。

孔和畅
2023-03-14

默认情况下,spring boot starter web依赖项将包括tomcat。这将使jetty在启动时感到困惑,因为它使用不同版本的juli库。

只需修复您的pom.xml,排除启动-tomcat,并分别包括码头依赖:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
    </dependency>
 类似资料:
  • 在Windows上,我刚刚将我的应用程序安装程序从Izpack转换为JPackage,由于JPackage创建的结构,我必须进行一些代码更改,以允许我的应用软件查找各种配置文件,基本上,它们在第一次启动时就从app文件夹复制到C:\Users\Username\Appdata……(但比这要复杂一些)。 我现在在Linux上使用JPackage,应用程序将配置文件从应用程序复制到$HOME/. ap

  • 我的系统中安装了pyenv Virtual alenv和Anaconda,以管理虚拟环境。 我的.zshrc文件如下所示: 在给定的文件夹中,我设置了一个本地虚拟环境 在该文件夹中列出虚拟env会导致: 但是当我加载python而不是使用Python v2.7.12打开会话时(正如人们所期望的那样,因为虚拟环境已加载),我得到: 因此,很明显,Anaconda平台正在我的虚拟环境之间。列出 环境显

  • 我在一个web应用程序上工作,该应用程序从其代码中调用多个web服务客户端。 每个 Web 服务都有一些通用命名空间,但是当我生成每个客户端时,我目前正在将这些命名空间映射到不同的包 e. g. g. Web服务1的名称空间1- Web 服务 2 的命名空间1 - 其中namespace1引用相同的命名空间URL。 使用Wsdl2Java的namespace2package选项: 我可以毫无问题地

  • 问题内容: 我有两节课: MyApplication 库 该库已被编译为Library.class,并且源代码不再可用。我现在正在尝试从源代码编译MyApplication。MyApplication取决于库。该库的软件包名称为org.myCompany。我尝试将我的类路径设置为以下内容: 产生以下javac编译器错误消息: 所以我将类路径更改为: 产生完全相同的错误消息。 如何设置Windows

  • maven-tomcat-plugin让maven与tomcat配合得很好。它可以把应用部署到Tomcat服务器,也可以把 tomcat作为内嵌服务器启动,就像jetty一样。 使用JPDA启动tomcat的远程调试功能。这样就能与eclipse配合起来,轻松地 实现调试。而且具有tomcat的热部署功能。

  • 我在设置Java开发环境时遇到了一个问题。在过去,我安装了Java,然后安装了IDE,然后开始编写代码。我现在开始设置我的笔记本电脑,使用命令行编译和记事本作为我的代码编辑器。这是我第一次尝试纠正错误。 我运行javac,它创建了我的。类文件没有问题,但是我尝试用java A运行类文件,它抛出了一个错误: c:\工作区 我的类路径设置为C:\Program Files\Java\jdk-14.0.