POM中的依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
现在以调试模式运行时为真,该应用正在记录两次启动一样的日志。我正在使用STS eclipse开发环境。
12:34:24.576 [main] DEBUG org.springframework.boot.context.logging.ClasspathLoggingApplicationListener - Application started with classpath: [file:/D:/STS-%20My%20Research%20Workspace/bootresearch/target/classes/, file:/C:/Users/test/.m2/repository/org/springframework/boot/spring-boot-starter/2.1.2.RELEASE/spring-boot-starter-2.1.2.RELEASE.jar, file:/C:/Users/test/.m2/repository/org/springframework/boot/spring-boot/2.1.2.RELEASE/spring-boot-2.1.2.RELEASE.jar, file:/C:/Users/test/.m2/repository/org/springframework/spring-context/5.1.4.RELEASE/spring-context-5.1.4.RELEASE.jar, file:/C:/Users/test/.m2/repository/org/springframework/spring-aop/5.1.4.RELEASE/spring-aop-5.1.4.RELEASE.jar, file:/C:/Users/test/.m2/repository/org/springframework/spring-beans/5.1.4.RELEASE/spring-beans-5.1.4.RELEASE.jar, file:/C:/Users/test/.m2/repository/org/springframework/spring-expression/5.1.4.RELEASE/spring-expression-5.1.4.RELEASE.jar, file:/C:/Users/test/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.1.2.RELEASE/spring-boot-autoconfigure-2.1.2.RELEASE.jar, file:/C:/Users/test/.m2/repository/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar, file:/C:/Users/test/.m2/repository/org/springframework/spring-core/5.1.4.RELEASE/spring-core-5.1.4.RELEASE.jar, file:/C:/Users/test/.m2/repository/org/springframework/spring-jcl/5.1.4.RELEASE/spring-jcl-5.1.4.RELEASE.jar, file:/C:/Users/test/.m2/repository/org/yaml/snakeyaml/1.23/snakeyaml-1.23.jar, file:/C:/Users/test/.m2/repository/org/springframework/boot/spring-boot-starter-log4j2/2.1.2.RELEASE/spring-boot-starter-log4j2-2.1.2.RELEASE.jar, file:/C:/Users/test/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.11.1/log4j-slf4j-impl-2.11.1.jar, file:/C:/Users/test/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar, file:/C:/Users/test/.m2/repository/org/apache/logging/log4j/log4j-api/2.11.1/log4j-api-2.11.1.jar, file:/C:/Users/test/.m2/repository/org/apache/logging/log4j/log4j-core/2.11.1/log4j-core-2.11.1.jar, file:/C:/Users/test/.m2/repository/org/apache/logging/log4j/log4j-jul/2.11.1/log4j-jul-2.11.1.jar, file:/C:/Users/test/.m2/repository/org/slf4j/jul-to-slf4j/1.7.25/jul-to-slf4j-1.7.25.jar]
12:34:24.576 [main] DEBUG org.springframework.boot.context.logging.ClasspathLoggingApplicationListener - Application started with classpath: [file:/D:/STS-%20My%20Research%20Workspace/bootresearch/target/classes/, file:/C:/Users/test/.m2/repository/org/springframework/boot/spring-boot-starter/2.1.2.RELEASE/spring-boot-starter-2.1.2.RELEASE.jar, file:/C:/Users/test/.m2/repository/org/springframework/boot/spring-boot/2.1.2.RELEASE/spring-boot-2.1.2.RELEASE.jar, file:/C:/Users/test/.m2/repository/org/springframework/spring-context/5.1.4.RELEASE/spring-context-5.1.4.RELEASE.jar, file:/C:/Users/test/.m2/repository/org/springframework/spring-aop/5.1.4.RELEASE/spring-aop-5.1.4.RELEASE.jar, file:/C:/Users/test/.m2/repository/org/springframework/spring-beans/5.1.4.RELEASE/spring-beans-5.1.4.RELEASE.jar, file:/C:/Users/test/.m2/repository/org/springframework/spring-expression/5.1.4.RELEASE/spring-expression-5.1.4.RELEASE.jar, file:/C:/Users/test/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.1.2.RELEASE/spring-boot-autoconfigure-2.1.2.RELEASE.jar, file:/C:/Users/test/.m2/repository/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar, file:/C:/Users/test/.m2/repository/org/springframework/spring-core/5.1.4.RELEASE/spring-core-5.1.4.RELEASE.jar, file:/C:/Users/test/.m2/repository/org/springframework/spring-jcl/5.1.4.RELEASE/spring-jcl-5.1.4.RELEASE.jar, file:/C:/Users/test/.m2/repository/org/yaml/snakeyaml/1.23/snakeyaml-1.23.jar, file:/C:/Users/test/.m2/repository/org/springframework/boot/spring-boot-starter-log4j2/2.1.2.RELEASE/spring-boot-starter-log4j2-2.1.2.RELEASE.jar, file:/C:/Users/test/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.11.1/log4j-slf4j-impl-2.11.1.jar, file:/C:/Users/test/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar, file:/C:/Users/test/.m2/repository/org/apache/logging/log4j/log4j-api/2.11.1/log4j-api-2.11.1.jar, file:/C:/Users/test/.m2/repository/org/apache/logging/log4j/log4j-core/2.11.1/log4j-core-2.11.1.jar, file:/C:/Users/test/.m2/repository/org/apache/logging/log4j/log4j-jul/2.11.1/log4j-jul-2.11.1.jar, file:/C:/Users/test/.m2/repository/org/slf4j/jul-to-slf4j/1.7.25/jul-to-slf4j-1.7.25.jar]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.2.RELEASE)
12:34:24.610 [main] INFO com.research.boot.App - Starting App on mymachine with PID 12688 (started by test in D:\STS- My Research Workspace\bootresearch)
12:34:24.610 [main] INFO com.research.boot.App - No active profile set, falling back to default profiles: default
12:34:24.610 [main] DEBUG org.springframework.boot.SpringApplication - Loading source class com.research.boot.App
12:34:24.610 [main] DEBUG org.springframework.boot.SpringApplication - Loading source class com.research.boot.App
12:34:24.626 [main] DEBUG org.springframework.boot.context.config.ConfigFileApplicationListener - Loaded config file 'file:/D:/STS-%20My%20Research%20Workspace/bootresearch/target/classes/application.yml' (classpath:/application.yml)
12:34:24.626 [main] DEBUG org.springframework.boot.context.config.ConfigFileApplicationListener - Loaded config file 'file:/D:/STS-%20My%20Research%20Workspace/bootresearch/target/classes/application.yml' (classpath:/application.yml)
12:34:24.877 [main] DEBUG org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar$SpringApplicationAdmin - Application Admin MBean registered with name 'org.springframework.boot:type=Admin,name=SpringApplication'
12:34:24.877 [main] DEBUG org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar$SpringApplicationAdmin - Application Admin MBean registered with name 'org.springframework.boot:type=Admin,name=SpringApplication'
Spring Boot应用程序类。
@SpringBootApplication
public class App
{
private static final Logger logger = LogManager.getLogger(App.class);
public static void main( String[] args)
{
logger.info("starting");
SpringApplication.run(App.class, args);
logger.info("Started");
}
}
这在我的常规应用程序中导致了两次JMS侦听器主题,然后我可以在示例启动项目中将其追溯到log4j2依赖关系。如果我删除log4j2依赖关系,则它将启动一次。不知道这里出了什么问题。
感谢您的帮助。
答案 0 :(得分:1)
我认为您必须将记录器上的 additiveivity 属性设置为 false 。否则,默认情况下将其设置为true ,并将导致多个日志语句。
在代码中,它看起来像:
logger.setadditivity(false);