コード例 #1
0
 private void invokeAwareInterfaces(Object bean) {
   if (bean instanceof Aware) {
     if (bean instanceof EnvironmentAware) {
       ((EnvironmentAware) bean).setEnvironment(this.applicationContext.getEnvironment());
     }
     if (bean instanceof EmbeddedValueResolverAware) {
       ((EmbeddedValueResolverAware) bean)
           .setEmbeddedValueResolver(
               new EmbeddedValueResolver(this.applicationContext.getBeanFactory()));
     }
     if (bean instanceof ResourceLoaderAware) {
       ((ResourceLoaderAware) bean).setResourceLoader(this.applicationContext);
     }
     if (bean instanceof ApplicationEventPublisherAware) {
       ((ApplicationEventPublisherAware) bean)
           .setApplicationEventPublisher(this.applicationContext);
     }
     if (bean instanceof MessageSourceAware) {
       ((MessageSourceAware) bean).setMessageSource(this.applicationContext);
     }
     if (bean instanceof ApplicationContextAware) {
       ((ApplicationContextAware) bean).setApplicationContext(this.applicationContext);
     }
   }
 }
コード例 #2
0
  @Override
  protected List<? extends ViewResolver> initViewResolvers() {
    viewResolvers =
        (viewResolvers == null) ? Arrays.asList(new FixedViewResolver(NOOP_VIEW)) : viewResolvers;

    for (Object vr : viewResolvers) {
      if (vr instanceof ApplicationContextAware) {
        ((ApplicationContextAware) vr).setApplicationContext(applicationContext);
      }
    }

    return viewResolvers;
  }