我是Spring-Batch(以及一般的Spring)的新手,并且一直在跟踪在线文档,教我自己完成这项任务需要什么.我正在尝试连接到DB2数据库.
如果我像这样用XML声明DB2连接:
<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>
Run Code Online (Sandbox Code Playgroud)
然后将其加载到我的代码中,如下所示:
@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;
}
Run Code Online (Sandbox Code Playgroud)
它完美地运作.我想如何使用DataSourceBuilder这样的示例显示最终我想要:
@ConfigurationProperties(prefix="DEV.datasource")
public DataSource Wcs_DataSource(){
return DataSourceBuilder.create().build();
}
Run Code Online (Sandbox Code Playgroud)
但由于某种原因,这是行不通的.我明白了
引起:java.lang.IllegalStateException:找不到支持的DataSource类型
我也尝试过:
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 …Run Code Online (Sandbox Code Playgroud) 我试图从.Net调用Service Now的web服务,我可以使它在插入记录时工作正常,但我无法使用任何GET工作.这是我的工作INSERT代码:
public void insertTable(string tableName, string schema, string columnInfo, string shortDesrcipt, string longDescript)
{
using (ServiceNow_u_database_table tableReference = new ServiceNow_u_database_table())
{
insertResponse response = new insertResponse();
System.Net.ICredentials cred = new System.Net.NetworkCredential(Properties.Settings.Default.UserName, Properties.Settings.Default.Password);
tableReference.Credentials = cred;
insert tableInsert = this.getTableData(tableName, schema, columnInfo, shortDesrcipt, longDescript);
try
{
response = tableReference.insert(tableInsert);
}
catch (Exception error)
{
Console.WriteLine(error.Message);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这很好.以下代码不适用于GET:
using (ServiceNow_u_database_table tableReference = new ServiceNow_u_database_table())
{
ServiceNowExport.com.servicenow.libertydev.u_database_table.getRecords recordGet = new getRecords();
System.Net.ICredentials cred = …Run Code Online (Sandbox Code Playgroud) 首先是问题陈述:我在DEV环境中使用Spring-Batch很好.当我将代码移动到生产环境时,我遇到了问题.在我的DEV环境中,Spring-Batch能够在我们的DB2数据库服务器中创建它的事务数据表而没有问题.当我们去PROD时这不是一个选项,因为这是一个只读工作.
尝试解决方案:
搜索Stack Overflow我发现这个帖子: Spring-Batch没有将元数据保存到数据库?
这听起来很完美,所以我补充道
@Bean
public ResourcelessTransactionManager transactionManager() {
return new ResourcelessTransactionManager();
}
@Bean
public JobRepository jobRepository(ResourcelessTransactionManager transactionManager) throws Exception {
MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean = new MapJobRepositoryFactoryBean(transactionManager);
mapJobRepositoryFactoryBean.setTransactionManager(transactionManager);
return mapJobRepositoryFactoryBean.getObject();
}
Run Code Online (Sandbox Code Playgroud)
我还通过调用.reporitory(jobRepository)将它添加到我的Job中.
但我明白了
Caused by: java.lang.NullPointerException: null
at org.springframework.batch.core.repository.dao.MapJobExecutionDao.synchronizeStatus(MapJobExecutionDao.java:158) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
Run Code Online (Sandbox Code Playgroud)
所以我不知道该怎么做.我是春天的新手,所以我一边教我自己.我对其他解决方案持开放态度,例如内存数据库,但我也无法让它们工作.我不需要在运行之间保存任何状态或会话信息,但我运行的数据库查询将返回大约一百万行左右,因此我需要以块的形式获取.
任何建议或帮助将不胜感激.