简体   繁体   中英

Specify JDBI default plugin (SqlObjectPlugin)

Is there a way to tell JDBI I want to use a specific plugin (SqlObjectPlugin in my case) throughout my entire application, without having to re-specify upon each use? Throughout my application code I have the following:

var jdbi = Jdbi.create(dataSource);
jdbi.installPlugin(new SqlObjectPlugin());  // <== I want to make this part DRY

I'm tired of having that second boilerplate line repeated all over my code.

To the JDBI devs: I totally love the product: thx! :)

You have two options, which of the is best depends on the code of your application:

  1. Instantiate Jdbi once and reuse it everywhere (using DI, static singleton, etc)
  2. Use org.jdbi.v3.core.Jdbi#installPlugins , which, according to documentation, uses the ServiceLoader API to detect and install plugins automagically. Some people consider this feature dangerous; some consider it essential -- use at your own risk uses the ServiceLoader API to detect and install plugins automagically. Some people consider this feature dangerous; some consider it essential -- use at your own risk uses the ServiceLoader API to detect and install plugins automagically. Some people consider this feature dangerous; some consider it essential -- use at your own risk . But you still would need to call this method every time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM