SpringとJavaを同時に学んでいます。私は自分のアプリケーションコンテキストに取り組んでいます。これが私の豆の1つです:
package com.example.app.context;
@Configuration
public class ApplicationContextConfiguration {
@Bean
public ComboPooledDataSource comboPooledDataSource() {
// ... setup pool here
return pool;
}
}
今、私はこのBeanを使いたいです:
package com.example.db.queries;
import javax.inject.Inject;
public class DatabaseQueries {
@Inject private ComboPooledDataSource comboPooledDataSource;
public static List<Records> getData() {
Connection connection = comboPooledDataSource.getConnection();
// ... create sql query and execute
}
しかし、コンパイル時に次のエラーが発生します。
[ERROR] non-static variable comboPooledDataSource cannot be referenced from a static context
この Bean にアクセスするにはどうすればよいですか?
事前に感謝します。覚えておいてください、私は学んでいます!