@SuppressWarnings("unchecked") private ApplicationContextInitializer<ConfigurableApplicationContext> loadInitializer( String className, ConfigurableApplicationContext wac) { try { Class<?> initializerClass = ClassUtils.forName(className, wac.getClassLoader()); Class<?> initializerContextClass = GenericTypeResolver.resolveTypeArgument( initializerClass, ApplicationContextInitializer.class); if (initializerContextClass != null) { Assert.isAssignable( initializerContextClass, wac.getClass(), String.format( "Could not add context initializer [%s] since its generic parameter [%s] " + "is not assignable from the type of application context used by this " + "framework servlet [%s]: ", initializerClass.getName(), initializerContextClass.getName(), wac.getClass().getName())); } return BeanUtils.instantiateClass(initializerClass, ApplicationContextInitializer.class); } catch (Exception ex) { throw new IllegalArgumentException( String.format( "Could not instantiate class [%s] specified " + "via 'contextInitializerClasses' init-param", className), ex); } }
@Override public void initialize(ConfigurableApplicationContext context) { if (context instanceof DefaultResourceLoader) { ((DefaultResourceLoader) context) .setClassLoader(new ServiceClassLoader(new WinletClassLoader(context.getClassLoader()))); } }