Skip to content

Instantly share code, notes, and snippets.

Created May 16, 2011 15:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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);
protected SpringBasedContainer getContainer() {
final SpringBasedContainer delegate = super.getContainer();
final ConfigurableWebApplicationContext parentContext = new Mirror().on(delegate).get().field("parentContext");
return new SpringBasedContainer(parentContext) {
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