spring provider accepting overridings from jars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Provider extends SpringProvider { | |
private static final Logger logger = LoggerFactory.getLogger(Provider.class); | |
@Override | |
protected SpringBasedContainer getContainer() { | |
final SpringBasedContainer delegate = super.getContainer(); | |
final ConfigurableWebApplicationContext parentContext = new Mirror().on(delegate).get().field("parentContext"); | |
return new SpringBasedContainer(parentContext) { | |
@Override | |
public <T> T instanceFor(Class<T> type) { | |
try { | |
return delegate.instanceFor(type) | |
} catch (NoSuchBeanDefinitionException e) { | |
Map<String, T> beans = parentContext.getBeansOfType(type); | |
for (Entry<String, T> def : beans.entrySet()) { | |
BeanDefinition definition = parentContext.getBeanFactory().getBeanDefinition(def.getKey()); | |
if (!cameFromJar(definition)) { | |
return def.getValue(); | |
} | |
} | |
throw e; | |
} | |
} | |
public boolean cameFromJar(BeanDefinition definition) { | |
//Do the magic here!!! | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment