Shouldn't you rather check if the fileNameGenerator is an instance of *BeanFactoryAware*?