java - Monitor bean injection failure -


we have application spring beans (3 levels) running on tomcat, beans annotated @autowired , mandatory.

what monitor bean injection failure (which can indicate deployment problem).

the way i'm thinking have 2 options so:

  1. instead of using @autowired load beans in static block, if load fails do something

  2. surround code try{...} catch (nullpointerexception e), if bean null exception thrown.

  3. check if beans equal null @ every method.

i think #1 elegant , least amount of code add, wondering whether there elegant way without static block.

thanks

there quiet few options here.
favorite annotate required dependency @autowired(required=false) , in method anotated @postconstruct test , handle missing dependency:

... @autowired(required = false) private bean dependency;  @postconstruct private void init() {   if(dependency==null) {      // handle missing dependecy   } } 

there quiet interesting article checking of required dendecies in spring. it's bit older still beneficilal.
http://blog.springsource.org/2007/07/11/setter-injection-versus-constructor-injection-and-the-use-of-required/


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -