我的一个maven模块在运行测试时会忽略我的日志记录级别。
在 src/test/resources ,我有 application.properties
src/test/resources
application.properties
app.name=bbsng-import-backend app.description=Import Backend Module for Application spring.profiles.active=test # LOGGING logging.level.root=error logging.level.org.springframework.core =fatal logging.level.org.springframework.beans=fatal logging.level.org.springframework.context=fatal logging.level.org.springframework.transaction=error logging.level.org.springframework.test=error logging.level.org.springframework.web=error logging.level.org.hibernate=ERROR
我还试过 application-test.properties 。
application-test.properties
我的应用程序记录很多,特别是在加载上下文时。我试过 logback.xml , logback-test.xml 和 logback-spring.xml ,但是没有任何帮助。
logback.xml
logback-test.xml
logback-spring.xml
我的pom:
<parent> <groupId>at.company.bbsng</groupId> <artifactId>bbsng-import</artifactId> <version>0.1.0-SNAPSHOT</version> </parent> <artifactId>bbsng-import-backend</artifactId> <name>bbsng-import-backend</name> <properties> <start-class>at.company.bbsng.dataimport.ApplicationImportBackend</start-class> </properties> <dependencies> <!-- APPLICATION ... --> <dependency> <groupId>at.company.bbsng</groupId> <artifactId>bbsng-app-domain</artifactId> <scope>test</scope> </dependency> <!-- SPRING ... --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-batch</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <scope>test</scope> </dependency> <!-- JAVAX ... --> <!-- COMMONS ... --> <!-- LOMBOK ... --> <!-- DB --> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${org.springframework.boot-version}</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
一个简单的测试类:
@ContextConfiguration(classes = { ApplicationImportBackend.class }) @RunWith(SpringJUnit4ClassRunner.class) @ActiveProfiles({ "test" }) public class BatchJobConfigurationTests { @Autowired private JobLauncher jobLauncher; @Test public void testSimpleProperties() throws Exception { assertNotNull(jobLauncher); }
应用程序日志处于调试模式。
是的, application.properties 会被装载。我已经试图通过错误的配置来破坏应用程序。
谢谢你的暗示。
发布于 2016-02-07 14:20:48
好的,在我现在所做的所有模块中,配置如下:
src/main/resources:
我在 application.properies 中使用日志配置,如问题中所述的 logging.level.* 。
application.properies
logging.level.*
src/test/resources:
我使用 logback-test.xml 的方式如下:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <include resource="org/springframework/boot/logging/logback/base.xml" /> <logger name="*.myapp" level="error" /> <logger name="org.springframework.core " level="error" /> <logger name="org.springframework.beans" level="error" /> <logger name="org.springframework.context" level="error" /> <logger name="org.springframework.transaction" level="error" /> <logger name="org.springframework.web" level="error" /> <logger name="org.springframework.test" level="error" />