views:

31

answers:

1

I like the ease of using @Resource annotation to get a DataSource, but as far as I know, it's not possible to use it in a regular JavaBean. Would it be considered a bad practice if I pass the DataSource object from a servlet to a bean along with the other data to avoid having that lookup code in the bean?

+1  A: 

It is certainly a bad practice to pass the data source to bean calls. You better use one of the dependency inversion frameworks, such as Spring or Guice. The former has utilities to inject required DataSources to configured beans, among to many other useful things.

Eugene Kuleshov
Спасибо, Евгений.
Slavko