开发者

Passing DataSource object from a servlet to a JavaBean

开发者 https://www.devze.com 2022-12-30 08:44 出处:网络
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 DataSou

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消