@Componentクラスで@RestControllerクラスをautowireする必要があり春 - 私が好きなように同じMavenの親モジュールの下にウェブとコアプロジェクトの組み合わせを持っている
親 - ウェブ(com.parent.test.web) - コア(com.parent.test.core)
私は、Webモジュール
WebプロジェクトのサンプルからのAPIの一部を呼び出すためにコアプロジェクトのWebモジュールの依存関係を参照してくださいしたいと思い、
com.test.parent.web
public interface RestInterface {
public ResponseEntity load();
}
@RestController
public class RestInterfaceImpl implements RestInterface {
@Override
@RequestMapping(value = "/getData", method = RequestMethod.GET, produces = APPLICATION_JSON)
public @ResponseBody ResponseEntity<Object> load() {
}
}
プロジェクトは、同じ親ポンポンモジュール内で開発されているので
コアプロジェクトのサンプル、
com.test.parent.core
@Component
public class CoreImpl implements CoreInterface {
// Is this possible to autowire
@Autowired
private RestInterface restInterface;
public boolean getOptions() {
ResponseEntity<Object> results = restInterface.load();
for (Object o : results) {
//TODO
}
}
}
。すべてのプロジェクトはスプリングブーツジャーにグループ化され、同じ環境に展開されます。そこで、Webプロジェクトの依存関係をコアプロジェクトに取り込み、コアプロジェクト内のWebクラスをスキャンしようと考えています。
、私はいくつかのことに明確に取得したいのですが、
- は、それは良いアプローチですか?
- 良いアプローチであれば、どのように実装できますか?
- そうでない場合、正しいアプローチは何ですか?
コアプロジェクトに依存関係としてWebモジュールプロジェクトを追加してもよろしいですか?また、APIを呼び出すために依存関係を追加する必要はありません。そしてあなたはその見出しを何とかしていたのですか? –
はい。私はインタフェースをWebモジュールuriにアクセスする依存関係と呼んでいます。 WebモジュールのSpring BeanクラスをSpring Coreプロジェクトにautowiringしています。 – user3095047