我有一个用Maven构建的RESTJava应用程序。它由一个包含两个模块的项目组成:
这是父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>
<groupId>org.sample</groupId>
<artifactId>myapp_server</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>myapp_server</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<slf4j.version>1.7.25</slf4j.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>central</id>
<url>http://repo1.maven.org/maven2</url>
</repository>
</repositories>
<modules>
<module>myapp_rest</module>
<module>myapp_logging</module>
</modules>
</project>
这是myapp_rest
的POM(使用dropwizard中的java简单原型创建):
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>myapp_server</artifactId>
<groupId>org.sample</groupId>
<version>0.0.1</version>
</parent>
<prerequisites>
<maven>3.0.0</maven>
</prerequisites>
<groupId>org.sample</groupId>
<artifactId>myapp_rest</artifactId>
<packaging>jar</packaging>
<name>REST layer</name>
<description>REST layer</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<dropwizard.version>1.3.5</dropwizard.version>
<mainClass>org.sample.rest.Application</mainClass>
</properties>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>${dropwizard.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>lo4j-slf4j-impl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.sample</groupId>
<artifactId>myapp_logging</artifactId>
<version>0.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${mainClass}</mainClass>
</transformer>
</transformers>
<!-- exclude signed Manifests -->
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
<dependencyDetailsEnabled>false</dependencyDetailsEnabled>
</configuration>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
</plugin>
</plugins>
</reporting>
</project>
这是myapp_logging
的 POM:
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sample</groupId>
<artifactId>myapp_server</artifactId>
<version>0.0.1</version>
</parent>
<groupId>org.sample</groupId>
<artifactId>myapp_logging</artifactId>
<name>myapp_logging</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<log4j.version>2.11.0</log4j.version>
</properties>
<dependencies>
<dependency> <!-- slf4j -> log4j bridge
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
</project>
我想让所有日志都通过slf4j
,以便使用log4j
进行日志记录。删除向导在内部使用日志,所以我试图让它使用slf4j。
如果我运行这个项目,我会得到以下输出:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/user/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/user/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.11.0/log4j-slf4j-impl-2.11.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
slf4j似乎正确地从日志模块中看到了log4j,但它也考虑了<code>logback classic
如果我排除了日志经典
包,我会收到此错误:
Exception in thread "main" java.lang.NoClassDefFoundError: ch/qos/logback/classic/Level
at io.dropwizard.Application.bootstrapLogLevel(Application.java:33)
at io.dropwizard.Application.bootstrapLogging(Application.java:38)
at io.dropwizard.Application.<init>(Application.java:26)
at org.sample.rest.Application.<init>(Application.java:10)
at org.sample.rest.Application.main(Application.java:15)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.classic.Level
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 more
通过单击类名,它将我重定向到io.dropwizard.Application
类,该类包含对ch.qos.logback.classic.Level
的引用,因此无法安全删除logback包。
我已经看到log4j有一个“逆桥”,可以让您将所有调用代理到slf4j(log4j-over-slf4j),但似乎没有对应的logback。
有没有办法摆脱日志,并通过slf4j使用删除向导使用任何其他框架?
实际上有一个Dropwizard文档介绍了如何摆脱Logback:https://dropwizard.readthedocs.io/en/stable/manual/core.html#logging
阅读黄色的注释(在错误级别的正下方),它会告诉你该怎么做。希望有帮助!
问题内容: 我有一个多线程函数,我想使用一个状态栏。有没有一种简单的方法来显示状态栏?正是并行化部分使我感到困惑。 问题答案: 你可以用周围,如下跟踪进度: 这是您的示例: 结果是这样的:
是否有任何示例项目展示了如何将Kafka与Micronaut结合使用?我很难让它工作。 我有以下制片人: 听众: 我的申请。yml包含: 以及应用测试。yml(这是正确的吗?它应该与application.yml位于同一目录中吗?还不确定嵌入式服务器应该如何使用): 我的测试结果如下: 我面临的主要问题是: > 我的消费者没有从我的主题中消费。我可以看到制作者在Kafka中创建了主题,并且创建了客
Mesos 安装与使用 以 Mesos 结合 Marathon 应用框架为例,来看下如何快速搭建一套 Mesos 平台。 Marathon 是可以跟 Mesos 一起协作的一个 framework,基于 Scala 实现,可以实现保持应用的持续运行。 另外,Mesos 默认利用 ZooKeeper 来进行多个主节点之间的选举,以及从节点发现主节点的过程。一般在生产环境中,需要启动多个 Mesos
go get github.com/gorilla/websocket go get github.com/valyala/fasthttp go get github.com/hprose/hprose-golang 使用 Hello 服务端 package main import ( "net/http" "github.com/hprose/hprose-golang
问题内容: 在哪种情况下,应该只在实际部署中将Node.js用作服务器? 当一个人 不 希望只使用Node.js的,有什么用Node.js的发挥更好?Apache还是Nginx? 问题答案: 将另一个Web服务器放在Node.js前面有几个充分的理由: 不必担心Node.js进程的特权/ setuid。通常只有root可以绑定到端口80。如果让nginx / Apache担心以root身份启动,绑
问题内容: 我已经看到许多特定的案例,人们在询问,人们在解释两者之间的区别,但我似乎也不能理解一般的区别。这两个是同义词吗?一个暗示另一个吗? 问题答案: 这两个是同义词吗? 号说:“嘿,Android(及相关的发行渠道),请让用户允许我做X”。说:“嘿,Android(及相关的发行渠道),我有兴趣在具有Y功能的硬件上运行”。 如果硬件不符合您的要求,但用户不参与,则可能会将您从Play商店(和其