How to @Inject A Bean into a Java Class?
I am working on learning Spring and Java. I created a Spring 3 app and
tried to make a connection pool as a bean:
@Bean
public ComboPooledDataSource comboPooledDataSource() {
ComboPooledDataSource pool = new ComboPooledDataSource();
// configure here
}
Then in another class:
@Inject private ComboPooledDataSource comboPooledDataSource;
From some debugging statements I can see the connection pool is
successfully created, but when I use the comboPooledDataSource, I get a
NullPointerException. How to I get the bean and use it?
No comments:
Post a Comment