2

私は3つのMavenモジュールを持っています:

  • Dao (DAO インターフェイスを含む)、
  • DaoImpl (Dao を実装する DAO クラスを含む)、
  • サービス (DaoImpl オブジェクトを使用するサービスを含む)。

3 つのモジュール間の依存関係は次のようになります。

DaoImpl -> Dao <- サービス

「->」は「依存」を意味します

DaoImpl Bean を Service Bean に注入したいと思います。問題は Service が DaoImpl に依存していないため、そのクラスパスにアクセスできないことです。したがって、Service で宣言された DaoImpl Bean は、DaoImpl のアプリケーション コンテキストで宣言された Bean にオートワイヤーできません。

1 つの解決策は、Service を DaoImpl に依存させることです。

Dao <- DaoImpl <- サービス

しかし、このケースでは、DAO 用のインターフェイスを持つ意味はありません。モジュール Dao は不要になり、DaoImpl が公開されます。

この主題について何か議論はありますか?

よろしくお願いします。

4

2 に答える 2

1

私見では、dao、daoimpl (の 1 つ)、およびサービスに依存する 4 番目のモジュールを導入する必要があります。

これは「アプリケーション展開」モジュールの一種で、通常は WAR などです。

  • アプリケーション -> サービス -> Dao
  • アプリケーション -> DaoImpl -> Dao

Application モジュールの主な役割は、完全なクラスパスを準備することです。

于 2012-11-16T16:56:00.007 に答える
0

It can also be resolved by

Service
  |_DaoIface
  |_DaoImpl

Here spring can be loaded from the service so it has both IFace and Impl visible.

Since Impl is directly visible to the service, it doesn't mean that DaoIface is not necessary. It is your design decisions. If the DAOImpls implementation will change on run time or if there are any other component to which you want to expose your DAO layer, then iface will be handy.

于 2012-11-16T17:23:40.890 に答える