Search in sources :

Example 1 with ServiceLocator

use of liquibase.servicelocator.ServiceLocator in project spring-boot by spring-projects.

the class LiquibaseServiceLocatorApplicationListenerTests method replacesServiceLocator.

@Test
public void replacesServiceLocator() throws Exception {
    SpringApplication application = new SpringApplication(Conf.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    this.context = application.run();
    ServiceLocator instance = ServiceLocator.getInstance();
    Field field = ReflectionUtils.findField(ServiceLocator.class, "classResolver");
    field.setAccessible(true);
    Object resolver = field.get(instance);
    assertThat(resolver).isInstanceOf(SpringPackageScanClassResolver.class);
}
Also used : ServiceLocator(liquibase.servicelocator.ServiceLocator) Field(java.lang.reflect.Field) SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.Test)

Example 2 with ServiceLocator

use of liquibase.servicelocator.ServiceLocator in project liquibase by liquibase.

the class LogFactory method getLog.

public Logger getLog(String name) {
    if (!loggers.containsKey(name)) {
        Logger value;
        try {
            ServiceLocator serviceLocator = ServiceLocator.getInstance();
            if (serviceLocator == null) {
                //ServiceLocator not yet running
                return defaultLogger;
            }
            value = (Logger) serviceLocator.newInstance(Logger.class);
        } catch (Exception e) {
            return defaultLogger;
        }
        value.setName(name);
        if (defaultLoggingLevel != null) {
            value.setLogLevel(defaultLoggingLevel);
        }
        loggers.put(name, value);
    }
    return loggers.get(name);
}
Also used : ServiceLocator(liquibase.servicelocator.ServiceLocator) DefaultLogger(liquibase.logging.core.DefaultLogger) ServiceNotFoundException(liquibase.exception.ServiceNotFoundException)

Aggregations

ServiceLocator (liquibase.servicelocator.ServiceLocator)2 Field (java.lang.reflect.Field)1 ServiceNotFoundException (liquibase.exception.ServiceNotFoundException)1 DefaultLogger (liquibase.logging.core.DefaultLogger)1 Test (org.junit.Test)1 SpringApplication (org.springframework.boot.SpringApplication)1