このように注釈が付けられた基本的なSpringBootアプリケーションがあります。
@SpringBootApplication
public class ApiApplication {
public static void main(String[] args) {
SpringApplication.run(ApiApplication.class, args);
}
}
application.properties
ファイルに次のエントリがあります。
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/db
spring.datasource.username=dbuser
spring.datasource.password=dbpassword
私の理解では、SpringBootはこれらのプロパティからデータソースBeanを自動的に自動配線できるはずです。
しかし、私が試してみると:
@Autowired
DataSource dataSource;
アプリケーションのどこか(@Configurationファイル内)で、IntelliJで次のエラーが発生します:
自動配線できませんでした。「DataSource」タイプのBeanが見つかりませんでした。」
これが機能するために私が欠けている明らかな何かがありますか?
単一のデータソースがあります。
Beanは実際には正しく初期化されます。これはおそらくIntelliJツールチップのバグです。
@SuppressWarningsを追加してメッセージを非表示にすると、問題なく機能します。
Intelijは、2016.2でも、@ SpringBootApplicationアノテーションをサポートしていないようです。 @SpringBootApplicationアノテーションを削除して、@ Configuration、@ EnableAutoConfiguration、および@ComponentScanアノテーションに置き換えるか、エラーを無視する必要があります。