[DS-2058] Move workflow curation testing to dspace-api since it has no essential connection with REST.

This patch duplicates the Spring/JUnit initializer classes from
dspace-server-webapp.  We should share a single set.  Possibly they should
live in dspace-services where the fundamental Spring support is found.
This commit is contained in:
Mark H. Wood
2021-06-08 09:00:30 -04:00
parent 7cc969829d
commit 2eea17c63b
4 changed files with 336 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.util;
import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.spring.ConfigurationPropertySource;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
/**
* Utility class that will initialize the DSpace Configuration on Spring startup.
* Adapted from the class of the same name in {@code dspace-server-webapp}.
* <P>
* NOTE: MUST be loaded after DSpaceKernelInitializer, as it requires the kernel
* is already initialized.
* <P>
* This initializer ensures that our DSpace Configuration is loaded into Spring's
* list of {@code PropertySource}s very early in the Spring startup process.
* That is important as it allows us to use DSpace configurations within
* {@code @ConditionalOnProperty} annotations on beans, as well as {@code @Value}
* annotations and XML bean definitions.
*/
public class DSpaceConfigurationInitializer
implements ApplicationContextInitializer<ConfigurableApplicationContext> {
private static final Logger log = LogManager.getLogger();
@Override
public void initialize(final ConfigurableApplicationContext applicationContext) {
// Load DSpace Configuration service (requires kernel already initialized)
ConfigurationService configurationService
= DSpaceServicesFactory.getInstance().getConfigurationService();
Configuration configuration = configurationService.getConfiguration();
// Create an Apache Commons Configuration Property Source from our configuration
ConfigurationPropertySource apacheCommonsConfigPropertySource =
new ConfigurationPropertySource(configuration.getClass().getName(), configuration);
// Prepend it to the Environment's list of PropertySources
// NOTE: This is added *first* in the list so that settings in DSpace's
// ConfigurationService *override* any default values in Spring's
// application.properties (or similar).
applicationContext.getEnvironment()
.getPropertySources()
.addFirst(apacheCommonsConfigPropertySource);
}
}