ResourceResolverRegistrar.java

  1. /*
  2.  * Copyright 2005-2025 the original author or authors.
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  * http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16. package org.openwms.tms.routing.app;

  17. import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
  18. import org.springframework.beans.factory.config.BeanPostProcessor;
  19. import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
  20. import org.springframework.context.ResourceLoaderAware;
  21. import org.springframework.core.io.ResourceLoader;
  22. import org.springframework.stereotype.Component;

  23. /**
  24.  * A ResourceResolverRegistrar.
  25.  *
  26.  * @author Heiko Scherrer
  27.  */
  28. @Component
  29. class ResourceResolverRegistrar implements BeanPostProcessor, BeanFactoryPostProcessor {

  30.     private ResourceLoader resourceLoader;

  31.     /**
  32.      * {@inheritDoc}
  33.      */
  34.     @Override
  35.     public Object postProcessBeforeInitialization(Object bean, String beanName) {
  36.         if (bean instanceof ResourceLoaderAware) {
  37.             ((ResourceLoaderAware) bean).setResourceLoader(resourceLoader);
  38.         }
  39.         return bean;
  40.     }

  41.     /**
  42.      * {@inheritDoc}
  43.      */
  44.     @Override
  45.     public Object postProcessAfterInitialization(Object bean, String beanName) {
  46.         return bean;
  47.     }

  48.     /**
  49.      * {@inheritDoc}
  50.      */
  51.     @Override
  52.     public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
  53.         resourceLoader = beanFactory.getBean(ConfigServerResourcePatternResolver.class);
  54.         beanFactory.registerResolvableDependency(ResourceLoader.class, resourceLoader);
  55.     }

  56. }