fix(resource): Add the ability to pass the application context to a resource plugin
Closes gravitee-io/issues#709
@@ -31,6 +31,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
import org.springframework.util.ClassUtils;
import java.io.IOException;
@@ -126,6 +127,11 @@ public class ResourceManagerImpl extends AbstractLifecycleComponent<ResourceMana
}
io.gravitee.resource.api.Resource resourceInstance = new ResourceFactory().create(resourceClass, injectables);
+
+ if (resourceInstance instanceof ApplicationContextAware) {
+ ((ApplicationContextAware) resourceInstance).setApplicationContext(applicationContext);
+ }
+
resources.put(resource.getName(), resourceInstance);
} catch (Exception ex) {
logger.error("Unable to create resource", ex);
