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 servle开发者_开发知识库t to a bean along with the other data to avoid having that lookup code in the bean?
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.
精彩评论