私はスプリングブートアプリケーションを持っており、いくつかのコントローラを定義するスプリングブートで書かれた依存関係をインポートしたいと思います。インポートされたモジュールのスプリングブートとコントローラ
おそらく簡単ですが、メインアプリケーションでインポートされたモジュールのこれらのコントローラをすべて初期化できるようにするにはどうすればよいですか?これらのコントローラのパスにアクセスしようとすると、指定されたパスのハンドラメソッドが見つからないというエラーが発生します。次のように私が試した:
@SpringBootApplication
@ComponentScan(basePackages = {"com.main.project", "com.imported.dependency"})
public class MyApplication
implements CommandLineRunner {
public static void main(final String... args) {
SpringApplication app = new SpringApplication(MyApplication.class);
app.setWebEnvironment(true);
app.run(args);
}
}
つまり私は@ComponentScan
と試みたが、何も起こりません。
私はまた、コントローラがロードされているかどうかを確認してみました:
ApplicationContext ctx = SpringApplication.run(FrontendApplication.class, args);
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
彼らはそうではありません。 @SpringBootApplication
を削除して@EnableAutoConfiguration
と@ComponentScan
を使用しようとしましたが、これは機能しません。
提案?
@SpringBootApplicationと@ComponentScan:
ComponentScanの "依存関係"のスペルが間違っています。 –
これは私の例のタイプミスです。実際のパッケージ名ではありません。私が使用しているものはうまく動作します –
SpringApplicationコンストラクタにリストしてみましたか?例えばSpringApplication app =新しいSpringApplication(MyApplication.class、MyAnnotatedBean.class); –