Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 弹簧靴SLF4j回写_Spring_Junit_Logback_Spring Test_Spring Logback - Fatal编程技术网

Spring 弹簧靴SLF4j回写

Spring 弹簧靴SLF4j回写,spring,junit,logback,spring-test,spring-logback,Spring,Junit,Logback,Spring Test,Spring Logback,我有一个小的SpringBoot MvC应用程序。对于这些依赖项: <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version>

我有一个小的SpringBoot MvC应用程序。对于这些依赖项:

<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>${spring-boot-starter-test.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
    </dependencies>
但是当我添加到文件
/src/test/resources/application.properties:

  # logging level
logging.level.root=error
    logging.level.org.springframework=ERROR
    logging.level.com.plats.bruts=ERROR
但它似乎不起作用,因为我在运行测试时在控制台上看到了调试级别:

10:16:08.039 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class eu.europa.ec.oib.kw.frontoffice.repository.autorisation.AutorisationPersonneRepositoryTest]
10:16:08.047 [main] DEBUG org.springframework.test.context.BootstrapUtils 

在测试spring boot应用程序以加载默认的日志记录时,请确保使用
@SpringBootTest
注释

在大多数情况下,您可以不需要自定义的logback xml文件,并且可以使用application.properties进行管理

对于非spring启动测试用例,您必须提供自己的logback xml文件

对于自定义配置,您应该基于spring引导库中提供的base.xml default(定义了文件和控制台appender)构建文件,以便您可以导入默认值并根据需要添加特定配置

通过这种方式,您仍然可以管理spring引导测试的来自应用程序的属性。还将文件重命名为以spring扩展名结尾,以便spring boot可以控制日志初始化

差不多

<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml" />
    !-- custom configuration goes here --!
</configuration>

!-- 自定义配置在这里--!

在测试spring boot的spring boot应用程序时,确保使用
@SpringBootTest
注释来加载默认的日志记录

在大多数情况下,您可以不需要自定义的logback xml文件,并且可以使用application.properties进行管理

对于非spring启动测试用例,您必须提供自己的logback xml文件

对于自定义配置,您应该基于spring引导库中提供的base.xml default(定义了文件和控制台appender)构建文件,以便您可以导入默认值并根据需要添加特定配置

通过这种方式,您仍然可以管理spring引导测试的来自应用程序的属性。还将文件重命名为以spring扩展名结尾,以便spring boot可以控制日志初始化

差不多

<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml" />
    !-- custom configuration goes here --!
</configuration>

!-- 自定义配置在这里--!

根日志记录器设置为什么级别?它未在应用程序中设置。属性它应在logback文件中设置<代码>。。。appenders…但如果可能,我只想使用application.properties而不是.xml文件为什么不在日志配置中使用logback,我很确定您不能将
应用程序.properties
日志配置和logback混用。根日志记录器设置为什么级别?它没有在应用程序中设置。properties应该在logback文件中设置<代码>。。。appenders…但是如果可能的话,我只想使用application.properties而不是.xml文件。为什么不在日志配置中使用logback,我很确定您不能将
应用程序.properties
日志配置和logback混合使用。