使用DataSouceBuilder时,我得到DataSource Not Supported [英] I am getting DataSource Not Supported when using DataSouceBuilder
问题描述
我是Spring-Batch(以及一般的Spring)的新手,并且一直在关注在线文档,教我自己完成这项任务需要什么。我正在尝试连接到DB2数据库。
I am new to Spring-Batch (and Spring in general), and have been following on line documentation to teach myself what I need to do this task. I am trying to connect to a DB2 database.
如果我用这样的XML声明DB2连接:
If I declare the DB2 connection with XML like this:
<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 in my code like so:
@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;
}
完美无瑕。我想如何使用DataSourceBuilder这样的示例显示最终我想要:
It works perfectly. How ever I would like to use the DataSourceBuilder like the examples show so ultimately I would like to get to :
@ConfigurationProperties(prefix="DEV.datasource")
public DataSource Wcs_DataSource(){
return DataSourceBuilder.create().build();
}
但由于某些原因不起作用。我得到了
But for some reason that does not work. I get
引起:java.lang.IllegalStateException:找不到支持的DataSource类型
Caused by: java.lang.IllegalStateException: No supported DataSource type found
我也尝试过:
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;
}
我得到同样的错误。如果我在调试器中运行它,我可以看到错误发生在.build()上。
And I get the same error. If I run it in the debugger, I can see that the error happens on the .build().
我确信我错过了一些简单的事情,但我无法理解。
I am sure I am missing something easy, but I can not figure it out.
推荐答案
M. Deinum回答说。我错过了我的依赖项中的commons-dbcp!我觉得这很简单。
M. Deinum answered it. I was missing commons-dbcp from my dependencies! I figured it was something easy like that.
要使用DataSourceBuilder,您需要 commons-dbcp 或
tomcat你的类路径上的-jdbc 或 hikaricp ,否则它将无效。我你
没有其中一个你得到的信息。
To use the DataSourceBuilder you need to have commons-dbcp, or tomcat-jdbc or hikaricp on your classpath else it won't work. I you don't have one of those you will get the message as you get.
这篇关于使用DataSouceBuilder时,我得到DataSource Not Supported的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!