ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vitalys <vitaly.seliva...@prudential.com>
Subject @SpringResource annotation is not injecting
Date Thu, 19 Sep 2019 14:22:55 GMT
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/

Mime
View raw message