0

我正在关注 SLF4J 异常,我已尝试从 pom.xml 中删除 slf4j 依赖项,但它仍然存在,有人可以帮忙吗?

抛出的异常为:。. .

 " org.osgi.framework.BundleException: Exception in
 oracle.acs.assessment.PatchDataExtractionActivator.start() of bundle
 oracle.acs.mf.PatchDataExtractionBundle.
         at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:1018)
>         at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:974)
>         at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:346)
>         at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:260)
>         at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:252)
>         at org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._start(FrameworkCommandProvider.java:260)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:606)
>         at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.execute(FrameworkCommandInterpreter.java:150)
>         at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java:291)
>         at org.eclipse.osgi.framework.internal.core.FrameworkConsole.console(FrameworkConsole.java:276)
>         at com.sun.svc.container.admin.cli.Console.run(Console.java:85)
>         at java.lang.Thread.run(Thread.java:724) Caused by: java.lang.NoSuchMethodError:
> org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
>         at org.apache.log4j.Category.log(Category.java:288)
>         at org.apache.commons.logging.impl.Log4JLogger.info(Log4JLogger.java:199)
>         at org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:412)
>         at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:350)
>         at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
>         at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
>         at oracle.acs.assessment.util.SpringHelper.initContext(SpringHelper.java:34)
>         at oracle.acs.assessment.util.SpringHelper.getBean(SpringHelper.java:57)
>         at oracle.acs.assessment.PatchDataExtractionActivator.start(PatchDataExtractionActivator.java:50)
>         at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:999)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:993)
>         ... 14 more Nested Exception: java.lang.NoSuchMethodError:

org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V

    at org.apache.log4j.Category.log(Category.java:288)
    at org.apache.commons.logging.impl.Log4JLogger.info(Log4JLogger.java:199)
    at org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:412)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:350)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
    at oracle.acs.assessment.util.SpringHelper.initContext(SpringHelper.java:34)
    at oracle.acs.assessment.util.SpringHelper.getBean(SpringHelper.java:57)
    at oracle.acs.assessment.PatchDataExtractionActivator.start(PatchDataExtractionActivator.java:50)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:999)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:993)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:974)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:346)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:260)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:252)
    at org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._start(FrameworkCommandProvider.java:260)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.execute(FrameworkCommandInterpreter.java:150)
    at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java:291)
    at org.eclipse.osgi.framework.internal.core.FrameworkConsole.console(FrameworkConsole.java:276)
    at com.sun.svc.container.admin.cli.Console.run(Console.java:85)
    at java.lang.Thread.run(Thread.java:724) Nested Exception: java.lang.NoSuchMethodError:

org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V at org.apache.log4j.Category.log(Category.java :288) 在 org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:412) 在 org.springframework.context 的 org.apache.commons.logging.impl.Log4JLogger.info(Log4JLogger.java:199)。 support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:350) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93) at oracle .acs.assessment.util.SpringHelper.initContext(SpringHelper.java:34) 在 oracle.acs.assessment.util.SpringHelper.getBean(SpringHelper.java:57) 在 oracle.acs.assessment.PatchDataExtractionActivator.start(PatchDataExtractionActivator.java:50) 在 org.eclipse.osgi.framework.internal.core .BundleContextImpl$2.run(BundleContextImpl.java:999) at java.security.AccessController.doPrivileged(Native Method) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:993) at org. eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:974) 在 org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:346) 在 org.eclipse.osgi。 org.eclipse.osgi.framework.internal 上的 framework.internal.core.AbstractBundle.start(AbstractBundle.java:260)。core.AbstractBundle.start(AbstractBundle.java:252) 在 org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._start(FrameworkCommandProvider.java:260) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun。 reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.eclipse.osgi .framework.internal.core.FrameworkCommandInterpreter.execute(FrameworkCommandInterpreter.java:150) 在 org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java:291) 在 org.eclipse.osgi.framework.internal .core.FrameworkConsole.console(FrameworkConsole.java:276) 在 com.sun.svc.container.admin.cli.Console.run(Console.java:85) 在 java.lang.Thread.run(Thread.java:724)

我的 Pom 文件是

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>oracle.acs.mf</groupId>
        <artifactId>assessment</artifactId>
        <version>all</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <groupId>oracle.acs.mf</groupId>
    <artifactId>PatchDataExtractionBundle</artifactId>
    <version>${assmnt.version}</version>
    <packaging>bundle</packaging>
    <name>Sun IT Services :: Monitoring Framework :: PatchDataExtractionBundle Bundle</name>
    <description>PatchDataExtractionBundle OSGi bundle project.</description>
    <properties>
        <slf4j.version>1.6.1</slf4j.version>
        <logback.version>1.0.11</logback.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.sun.cs</groupId>
            <artifactId>transport</artifactId>
            <version>2.5.6</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.mf</groupId>
            <artifactId>MonitoringFrameworkBundle</artifactId>
            <version>3.0-SNAPSHOT</version>
            <!--<scope>provided</scope>-->
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>jcl-over-slf4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>oracle.acs.platform</groupId>
            <artifactId>MonitoringFrameworkBundle</artifactId>
            <!--<version>all</version>-->
            <version>3.5.999</version>
            <type>jar</type>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>jcl-over-slf4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>2.5.4</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>jcl-over-slf4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
            <version>2.5.4</version>
            <type>jar</type>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>jcl-over-slf4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
            <version>4.2.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.karaf.shell</groupId>
            <artifactId>org.apache.karaf.shell.console</artifactId>
            <version>2.2.3</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>oracle.jdbc</groupId>
            <artifactId>ojdbc14</artifactId>
            <version>10.1.0.5.0</version>
            <type>jar</type>
        </dependency>

        <dependency>
            <groupId>org.eclipse</groupId>
            <artifactId>osgi</artifactId>
            <version>3.5.0.v20090520</version>
            <type>jar</type>
        </dependency>
       <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>${logback.version}</version>
            <optional>true</optional>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>jcl-over-slf4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
            <optional>true</optional>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>jcl-over-slf4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>oracle.acs.mf</groupId>
            <artifactId>assessment-common</artifactId>
            <version>2.1</version>
            <type>jar</type>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.2.2</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
                        <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                        <Bundle-Version>${project.version}</Bundle-Version>
                        <Bundle-Activator>oracle.acs.assessment.PatchDataExtractionActivator</Bundle-Activator>
                        <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
                        <!-- include the complete set of transitive dependencies -->
                        <Embed-Transitive>true</Embed-Transitive>
                        <Embed-Directory>META-INF/lib</Embed-Directory>
                        <!-- Custom entries
                        <CONFIG_FILE>/${install.config.dir}/patch_assessment.properties</CONFIG_FILE>-->
                        <Export-Package>
                            oracle.acs.assessment.service.*;oracle.acs.assessment.entity.*;version=${project.version}
                        </Export-Package>
                        <Import-Package>
                            org.osgi.service.http,
                            org.osgi.framework;version="1.3.0",
                            org.eclipse.osgi.framework.console, *;resolution:=optional
                        </Import-Package>
                    </instructions>
                </configuration>
            </plugin>
             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                  <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>

        </plugins>
    </build>

</project>
4

1 回答 1

6

我假设您使用的是 Maven 3.x。因此,<dependencyManagement>在您的 POM 中添加一个部分,您可以在其中配置 slf4j 的实际版本(这将进入您的父 POM,因此所有模块都使用这些覆盖):

<properties>
  <slf4j.version>1.7.5</slf4j.version>
</properties>

<dependencyManagement>
   <dependencies>
      <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-api</artifactId>
         <version>${slf4j.version}</version>
      </dependency>
      <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>jcl-over-slf4j</artifactId>
         <version>${slf4j.version}</version>
      </dependency>
      <!-- Since slf4j is a bridge, you need an implementation of it that would 
      redirect all calls to slf4j or JCL. Following is to perform logging using 
      the basic implementation, choose your preferred implementation 
      (it seems you were using logback). -->
      <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-simple</artifactId>
         <version>${slf4j.version}</version>
         <scope>runtime</scope>
      </dependency>
   </dependencies>
</dependencyManagement>

然后,在您的模块的 POM 中,使用主要<dependencies>部分中的依赖项,如下所示(我建议也从其他依赖项中删除排除项,Maven 应该能够选择正确的版本,因为您已经覆盖了它):

<dependencies>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
     </dependency>
     <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
     </dependency>
     <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
     </dependency>
     <!-- Other dependencies -->
     ...
</dependencies>

mvn clean install现在从项目的根目录执行 a 。

于 2013-08-12T16:31:42.837 回答