I am new to Spring -Batch (and Spring in general) and have been following the documentation to teach myself what I need to complete this task. I am trying to connect to a DB2 database.
If I declare a DB2 connection with XML as follows:
<bean id="wcs_dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver" /> <property name="url" value="jdbc:db2://127.0.0.1/DEV" /> <property name="username" value="user" /> <property name="password" value="pass5" /> </bean>
Then load it into your code like this:
@Bean public JdbcCursorItemReader<Product> databaseItemReader() { ApplicationContext context = new ClassPathXmlApplicationContext("context-datasource.xml"); DataSource dataSource = (DataSource) context.getBean("wcs_dataSource"); ((ConfigurableApplicationContext)context).close(); JdbcCursorItemReader<Product> result = new JdbcCursorItemReader<Product>(); result.setDataSource(dataSource); result.setSql(sqlString); result.setRowMapper(new ProductRowMapper()); return result; }
It works great. Be that as it may, I would like to use a DataSourceBuilder, as shown in the examples, so in the end I would like to go to:
@ConfigurationProperties(prefix="DEV.datasource") public DataSource Wcs_DataSource(){ return DataSourceBuilder.create().build(); }
But for some reason this does not work. I get
Called: java.lang.IllegalStateException: DataSource data type not supported
I also tried:
public DriverManagerDataSource dataSource() { DataSourceBuilder DSBuilder = DataSourceBuilder.create(); DSBuilder.url("jdbc:db2://127.0.0.1/DEV"); DSBuilder.username("user"); DSBuilder.password("password"); DSBuilder.driverClassName("com.ibm.db2.jcc.DB2Driver"); DriverManagerDataSource result = (DriverManagerDataSource) DSBuilder.build(); return result; }
And I get the same error. If I run it in the debugger, I see that the error is happening in .build ().
I'm sure I miss something easy, but I canβt understand.
source share