[spring-extensions] branch master updated: IDP-1650 Allow Injection of a PropertyInitializer into the Spring Cli Class

Rod Widdowson rdw at steadingsoftware.com
Fri Aug 7 10:22:35 UTC 2020


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch master
in repository spring-extensions.

View the commit online:
http://git.shibboleth.net/view/?p=spring-extensions.git;a=commit;h=9ff716f1b9e21df3145fa2904bef52a53dfd57e5

The following commit(s) were added to refs/heads/master by this push:
       new  9ff716f   IDP-1650  Allow Injection of a PropertyInitializer into the Spring Cli Class
9ff716f is described below

commit 9ff716f1b9e21df3145fa2904bef52a53dfd57e5
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Aug 6 17:31:22 2020 +0100

    IDP-1650  Allow Injection of a PropertyInitializer into the Spring Cli Class
    
    https://issues.shibboleth.net/jira/browse/IDP-1650
---
 .../ext/spring/cli/AbstractCommandLine.java        | 29 +++++++++++++++++-----
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/src/main/java/net/shibboleth/ext/spring/cli/AbstractCommandLine.java b/src/main/java/net/shibboleth/ext/spring/cli/AbstractCommandLine.java
index 4f4d1af..4a3d558 100644
--- a/src/main/java/net/shibboleth/ext/spring/cli/AbstractCommandLine.java
+++ b/src/main/java/net/shibboleth/ext/spring/cli/AbstractCommandLine.java
@@ -29,6 +29,7 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import org.slf4j.Logger;
+import org.springframework.context.ApplicationContextInitializer;
 import org.springframework.context.support.GenericApplicationContext;
 import org.springframework.core.env.PropertySource;
 import org.springframework.core.io.Resource;
@@ -38,6 +39,7 @@ import org.springframework.core.io.support.ResourcePropertySource;
 
 import com.beust.jcommander.JCommander;
 
+import net.shibboleth.ext.spring.context.FilesystemGenericApplicationContext;
 import net.shibboleth.ext.spring.resource.PreferFileSystemResourceLoader;
 import net.shibboleth.ext.spring.util.ApplicationContextBuilder;
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
@@ -73,10 +75,21 @@ public abstract class AbstractCommandLine<T extends CommandLineArguments> {
 
     /** Return code indicating an unknown error occurred, {@value} . */
     public static final int RC_UNKNOWN = -1;
-    
+
     /** Spring context. */
     @Nullable private GenericApplicationContext applicationContext;
-        
+
+    /** Optional Context initialized. */
+    @Nullable private ApplicationContextInitializer<? super FilesystemGenericApplicationContext> contextInitializer;
+    
+    /** Set the context Initializer.
+     * @param initializer what to set.
+     */
+    protected void setContextInitializer(
+            @Nonnull final ApplicationContextInitializer<? super FilesystemGenericApplicationContext> initializer) {
+        contextInitializer = Constraint.isNotNull(initializer, "Injected ContextInitializer should not be null");
+    }
+
     /**
      * Get the Spring context.
      * 
@@ -215,11 +228,15 @@ public abstract class AbstractCommandLine<T extends CommandLineArguments> {
                 }
             });
             
-            applicationContext = new ApplicationContextBuilder()
+            final ApplicationContextBuilder builder = new ApplicationContextBuilder()
                     .setServiceConfigurations(configs)
-                    .setPropertySources(propertySources)
-                    .build();
-            
+                    .setPropertySources(propertySources);
+
+            if (contextInitializer != null) {
+                builder.setContextInitializer(contextInitializer);
+            }
+            applicationContext = builder.build();
+
             // Register a shutdown hook for the context, so that beans will be
             // correctly destroyed before the CLI exits.
             applicationContext.registerShutdownHook();

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list