INTSAMPLES-150: Switch to Log4j2
JIRA: https://jira.spring.io/browse/INTSAMPLES-150
This commit is contained in:
committed by
Artem Bilan
parent
68377fedd1
commit
e37904128e
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,7 +19,9 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.samples.enricher.domain.User;
|
||||
@@ -30,14 +32,16 @@ import org.springframework.integration.samples.enricher.service.UserService;
|
||||
* Starts the Spring Context and will initialize the Spring Integration routes.
|
||||
*
|
||||
* @author Gunnar Hillert
|
||||
* @author Gary Russell
|
||||
* @version 1.0
|
||||
*
|
||||
*/
|
||||
public final class Main {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(Main.class);
|
||||
private static final Log LOGGER = LogFactory.getLog(Main.class);
|
||||
|
||||
private static final String LINE_SEPARATOR = "\n==========================================================================";
|
||||
|
||||
private static final String EMPTY_LINE = "\n ";
|
||||
|
||||
private Main() { }
|
||||
@@ -123,7 +127,8 @@ public final class Main {
|
||||
|
||||
LOGGER.info("\n\nExiting application...bye.");
|
||||
|
||||
System.exit(0);
|
||||
scanner.close();
|
||||
context.close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
package org.springframework.integration.samples.enricher.service.impl;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.samples.enricher.domain.User;
|
||||
|
||||
@@ -23,11 +24,12 @@ import org.springframework.integration.samples.enricher.domain.User;
|
||||
* Simple Service class for retrieving user information.
|
||||
*
|
||||
* @author Gunnar Hillert
|
||||
* @author Gary Russell
|
||||
*
|
||||
*/
|
||||
public class SystemService {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(SystemService.class);
|
||||
private static final Log LOGGER = LogFactory.getLog(SystemService.class);
|
||||
|
||||
/** Default Constructor. */
|
||||
public SystemService() {
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||
|
||||
<!-- Appenders -->
|
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||
<param name="Target" value="System.out" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- Loggers -->
|
||||
<logger name="org.springframework.integration">
|
||||
<level value="warn" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.integration.samples">
|
||||
<level value="info" />
|
||||
</logger>
|
||||
|
||||
<!-- Root Logger -->
|
||||
<root>
|
||||
<priority value="warn" />
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
||||
16
basic/enricher/src/main/resources/log4j2.xml
Normal file
16
basic/enricher/src/main/resources/log4j2.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n" />
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="info">
|
||||
<AppenderRef ref="Console" />
|
||||
</Root>
|
||||
<Logger name="org.springframework" level="warn" />
|
||||
<Logger name="org.springframework.integration" level="warn" />
|
||||
<Logger name="org.springframework.integration.samples" level="debug" />
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
@@ -20,58 +20,56 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.samples.enricher.domain.User;
|
||||
|
||||
|
||||
/**
|
||||
* Verify that the Spring Integration Application Context starts successfully.
|
||||
*/
|
||||
public class UserServiceTest {
|
||||
|
||||
@Test
|
||||
public void testStartupOfSpringInegrationContext() throws Exception{
|
||||
final ApplicationContext context
|
||||
= new ClassPathXmlApplicationContext("/META-INF/spring/integration/spring-integration-context.xml",
|
||||
UserServiceTest.class);
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
@Test
|
||||
public void testStartupOfSpringInegrationContext() throws Exception {
|
||||
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"/META-INF/spring/integration/spring-integration-context.xml", UserServiceTest.class);
|
||||
Thread.sleep(2000);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteFindUser() {
|
||||
@Test
|
||||
public void testExecuteFindUser() {
|
||||
|
||||
final ApplicationContext context
|
||||
= new ClassPathXmlApplicationContext("/META-INF/spring/integration/spring-integration-context.xml",
|
||||
UserServiceTest.class);
|
||||
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"/META-INF/spring/integration/spring-integration-context.xml", UserServiceTest.class);
|
||||
|
||||
final UserService service = context.getBean(UserService.class);
|
||||
final UserService service = context.getBean(UserService.class);
|
||||
|
||||
User user = new User("foo", null, null);
|
||||
final User fullUser = service.findUser(user);
|
||||
User user = new User("foo", null, null);
|
||||
final User fullUser = service.findUser(user);
|
||||
|
||||
assertEquals("foo", fullUser.getUsername());
|
||||
assertEquals("foo@springintegration.org", fullUser.getEmail());
|
||||
assertEquals("secret", fullUser.getPassword());
|
||||
assertEquals("foo", fullUser.getUsername());
|
||||
assertEquals("foo@springintegration.org", fullUser.getEmail());
|
||||
assertEquals("secret", fullUser.getPassword());
|
||||
context.close();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteFindUserByUsername() {
|
||||
@Test
|
||||
public void testExecuteFindUserByUsername() {
|
||||
|
||||
final ApplicationContext context
|
||||
= new ClassPathXmlApplicationContext("/META-INF/spring/integration/spring-integration-context.xml",
|
||||
UserServiceTest.class);
|
||||
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"/META-INF/spring/integration/spring-integration-context.xml", UserServiceTest.class);
|
||||
|
||||
final UserService service = context.getBean(UserService.class);
|
||||
final UserService service = context.getBean(UserService.class);
|
||||
|
||||
User user = new User("foo", null, null);
|
||||
final User fullUser = service.findUserByUsername(user);
|
||||
User user = new User("foo", null, null);
|
||||
final User fullUser = service.findUserByUsername(user);
|
||||
|
||||
assertEquals("foo", fullUser.getUsername());
|
||||
assertEquals("foo@springintegration.org", fullUser.getEmail());
|
||||
assertEquals("secret", fullUser.getPassword());
|
||||
assertEquals("foo", fullUser.getUsername());
|
||||
assertEquals("foo@springintegration.org", fullUser.getEmail());
|
||||
assertEquals("secret", fullUser.getPassword());
|
||||
context.close();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user