Hi,

According to the documentation, Ignite resource injection should be used
for injecting into the Ignite compute tasks, jobs, closures or SPIs. In
your example you're just trying to inject Spring Bean in your custom class,
it's not related to Ignite. For this case you should use Spring's
annotation @Autowired and register your AccessMultipleDB as bean in Spring
context.
https://apacheignite.readme.io/docs/resource-injection#section-overview

Regards,
Igor

On Thu, Sep 19, 2019 at 5:23 PM vitalys <[email protected]>
wrote:

> hi,
>
> I am trying to Inject an object in my Ignite application using
> @SpringResource annotation. On the startup of the application I can see (
> in
> debug mode ) that an object that I define in my "ignite-server-config.xml"
> is being initialized. However when I am trying to inject it in my
> application it returns NULL.
> According to Ignite documentation I can use @SpringResource annotation
> anywhere in Ignite application.
>
> Here is my code
>
> Starting an Ignite Node :
>
> public class MultipleDBConnectionTest {
>
>         @Test
>         void testIt() {
>
>                 try{
>                         System.setProperty("INSTANCE", "EAFDEV");
>
>                         Ignite ignite =
> Ignition.start("ignite-server-conf.xml");
>
>                         AccessMultipleDB access = new AccessMultipleDB();
>                         access.verifyDBConnection();
>                 }
>                 catch(Exception ex) {
>                         ex.printStackTrace();
>                 }
>         }
> }
>
> And here is the class where I am trying to inject a resource :
>
> public class AccessMultipleDB {
>
> *    @SpringResource(resourceName = "dataSource")
>     private BasicDataSourceManager dataSourceManager;*
>
>         public AccessMultipleDB() {
>
>         }
>
>         public void verifyDBConnection() {
>
>                 try {
>                         *// Next Line prints NULL
>                         System.out.println("DataSourceManager : " +
> dataSourceManager);*
>
>                         HashMap<String,BasicDataSource> allDS =
> dataSourceManager.getDataSourcesMap();
>                         Connection conn1 =
> allDS.get("db1").getConnection();
>                         Connection conn2 =
> allDS.get("db2").getConnection();
>                         System.out.println("DB1 connection is valid : " +
> conn1.isValid(100));
>                         System.out.println("DB2 connection is valid : " +
> conn2.isValid(100));
>                         conn1.close();
>                         conn2.close();
>                 }
>                 catch(SQLException ex) {
>                         System.out.println("Exception : " + ex);
>                         ex.printStackTrace();
>                 }
>         }
> }
>
> And that's how I define the bean in my XML :
>
>      <bean id="dataSource" class="BasicDataSourceManager">
>                         <constructor-arg>
>                                 <value>ConnectionPool</value>
>                         </constructor-arg>
>                         <constructor-arg>
>                                 <value>db1,db2</value>
>                         </constructor-arg>
>       </bean>
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Reply via email to