Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
spring provider accepting overridings from jars
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