hmsonline/dropwizard-spring — pull request #17 by bflad (2014-10-03 01:23:44+00:00)
Title: WARN on NoSuchBeanDefinitionException and continue initialization (master)

This PR helps folks that manage environments where Spring bean additions may be applied across all environments. In continuous deployment environments where a build may fail, we do not want to prevent Spring startup because of the non-existant bean should a webservice need to restart before it gets upgraded.

Instead of crashing on startup:
```
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'foobarResource' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:641)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1157)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:280)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:271)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973)
at com.hmsonline.dropwizard.spring.SpringService.loadResourceBeans(SpringService.java:104)
at com.hmsonline.dropwizard.spring.SpringService.run(SpringService.java:52)
at com.hmsonline.dropwizard.spring.SpringSwaggerService.run(SpringSwaggerService.java:30)
at com.hmsonline.dropwizard.spring.SpringSwaggerService.run(SpringSwaggerService.java:15)
at com.yammer.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:38)
at com.yammer.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:58)
at com.yammer.dropwizard.cli.Cli.run(Cli.java:53)
at com.yammer.dropwizard.Service.run(Service.java:61)
at com.hmsonline.dropwizard.spring.SpringSwaggerService.main(SpringSwaggerService.java:18)
# or maybe
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'foobarMapper' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:641)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1157)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:280)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:271)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973)
at com.hmsonline.dropwizard.spring.SpringService.loadJerseyProviders(SpringService.java:137)
at com.hmsonline.dropwizard.spring.SpringService.run(SpringService.java:56)
at com.hmsonline.dropwizard.spring.SpringSwaggerService.run(SpringSwaggerService.java:30)
at com.hmsonline.dropwizard.spring.SpringSwaggerService.run(SpringSwaggerService.java:15)
at com.yammer.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:38)
at com.yammer.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:58)
at com.yammer.dropwizard.cli.Cli.run(Cli.java:53)
at com.yammer.dropwizard.Service.run(Service.java:61)
at com.hmsonline.dropwizard.spring.SpringSwaggerService.main(SpringSwaggerService.java:18)
```

Let's log a WARN message and keep going:
```
WARN [2014-10-02 21:05:30,482] com.hmsonline.dropwizard.spring.SpringService: Skipping missing Spring bean:
! org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'foobarResource' is defined
! at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:575) ~[foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1114) ~[foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:279) ~[foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198) ~[foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:270) ~[foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117) ~[foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at com.hmsonline.dropwizard.spring.SpringService.loadResourceBeans(SpringService.java:139) [foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at com.hmsonline.dropwizard.spring.SpringService.run(SpringService.java:59) [foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at com.hmsonline.dropwizard.spring.SpringService.run(SpringService.java:33) [foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at com.yammer.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:38) [foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at com.yammer.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:58) [foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at com.yammer.dropwizard.cli.Cli.run(Cli.java:53) [foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at com.yammer.dropwizard.Service.run(Service.java:61) [foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at com.hmsonline.dropwizard.spring.SpringService.main(SpringService.java:37) [foobar-webservice-0.0.1-SNAPSHOT.jar:na]
WARN [2014-10-02 21:05:30,482] com.hmsonline.dropwizard.spring.SpringService: Skipping missing Spring bean:
! org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'foobarMapper' is defined
! at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:575) ~[foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1114) ~[foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:279) ~[foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198) ~[foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:270) ~[foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117) ~[foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at com.hmsonline.dropwizard.spring.SpringService.loadJerseyProviders(SpringService.java:188) [foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at com.hmsonline.dropwizard.spring.SpringService.run(SpringService.java:63) [foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at com.hmsonline.dropwizard.spring.SpringService.run(SpringService.java:33) [foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at com.yammer.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:38) [foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at com.yammer.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:58) [foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at com.yammer.dropwizard.cli.Cli.run(Cli.java:53) [foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at com.yammer.dropwizard.Service.run(Service.java:61) [foobar-webservice-0.0.1-SNAPSHOT.jar:na]
! at com.hmsonline.dropwizard.spring.SpringService.main(SpringService.java:37) [foobar-webservice-0.0.1-SNAPSHOT.jar:na]
```