I am learning Spring and Java at the same time. I am working on my application context. Here is one of my beans:
package com.example.app.context;
@Configuration
public class ApplicationContextConfiguration {
@Bean
public ComboPooledDataSource comboPooledDataSource() {
// ... setup pool here
return pool;
}
}
Now I want to use this 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
}
But I get this error at compile time:
[ERROR] non-static variable comboPooledDataSource cannot be referenced from a static context
How do I access this bean?
Thanks in advance, and please remember, I'm learning!