我想制作Spring Boot Console应用程序。我添加了这些行中的pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.4.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<dependencies>
<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>
我已经在我的资源文件夹中添加了log4j2.xml文件:
<Configuration status="INFO">
<Appenders>
<File name="MyFile" fileName="log"
immediateFlush="true" append="false">
<PatternLayout pattern=
"%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="MyFile"/>
</Root>
</Loggers>
</Configuration>
和我的主要看起来像这样:
public static void main(String[] args) {
LOG.info("STARTING THE APPLICATION");
SpringApplication app = new SpringApplication(Main.class);
app.setBannerMode(Banner.Mode.OFF);
app.run(args);
LOG.info("APPLICATION FINISHED");
}
问题是,当我从终端运行应用程序时,我有一些日志并打印到控制台上,我不希望这种行为:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1 (jar:file:/Users/robert.cebula/Projects/expense_summary/target/expense_summary-1.0.jar!/BOOT-INF/lib/spring-core-5.0.7.RELEASE.jar!/) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
您知道我该怎么做才能摆脱这些印刷到主机的线条。我希望通过春季靴打印任何东西。
Spring Boot具有内置的记录文件。
您需要通过创建自己的logback.xml
文件来覆盖它。您可以在此处阅读有关春季创建记录文件的更多信息。
我建议将日志写入文件,而不是完全没有日志。