Skip to content

Instantly share code, notes, and snippets.

@lucascs
Created May 16, 2011 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucascs/974684 to your computer and use it in GitHub Desktop.
Save lucascs/974684 to your computer and use it in GitHub Desktop.
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