I get a spring boot application and trying create a DataSource bean defined by Java configuration:
@Bean(name = "dsBD") @Primary
public DataSource dsBD() {
 return DataSourceBuilder.create()
 .url("jdbc:mysql://localhost:3306/database?autoReconnect=true")
 .username("root")
 .password("mysql")
 .driverClassName("com.mysql.jdbc.Driver")
 .build();
}
@Bean(name = "jdbcBD") @Autowired
public JdbcTemplate jdbcBD(@Qualifier("dsBD") DataSource dsBD) {
 return new JdbcTemplate(dsBD);
}
But when starting application, I got the following error:
Caused by: java.lang.IllegalStateException: No supported DataSource type found
 at org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder.getType(DataSourceBuilder.java:138) ~[spring-boot-autoconfigure-1.5.4.RELEASE.jar:1.5.4.RELEASE]
 at org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder.build(DataSourceBuilder.java:69) ~[spring-boot-autoconfigure-1.5.4.RELEASE.jar:1.5.4.RELEASE]
 at com.package.DatabaseConfig.dsBD(DatabaseConfig.java:29) ~[classes/:na]
 at com.package.DatabaseConfig$$EnhancerBySpringCGLIB$$ac56d75a.CGLIB$dsBD0ドル(<generated>) ~[classes/:na]
 at com.package.DatabaseConfig$$EnhancerBySpringCGLIB$$ac56d75a$$FastClassBySpringCGLIB$159ドルbefb3.invoke(<generated>) ~[classes/:na]
 at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.9.RELEASE.jar:4.3.9.RELEASE]
 at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
 at com.package.DatabaseConfig$$EnhancerBySpringCGLIB$$ac56d75a.dsBD(<generated>) ~[classes/:na]
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131]
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131]
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131]
 at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131]
 at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
 ... 46 common frames omitted
 
 Brian Tompsett - 汤莱恩
 
 5,92772 gold badges63 silver badges135 bronze badges
 
 
 asked Jun 19, 2017 at 16:49
 
 
 
 Jonathan Choy Rivera 
 
 131 silver badge4 bronze badges
 
 - 
 1You did not configure the datasource, it looks like. Or there is a problem in your config, it's hard to tell since you don't show us the neither the code nor the config.M. Prokhorov– M. Prokhorov2017年06月19日 18:53:52 +00:00Commented Jun 19, 2017 at 18:53
 - 
 Hi @M. Prokhorov, this is my config code for the DataSource ` @Bean(name = "dsBD") @Primary public DataSource dsBD() { return DataSourceBuilder.create().url("jdbc:mysql://localhost:3306/database?autoReconnect=true").username("root") .password("mysql").driverClassName("com.mysql.jdbc.Driver").build(); } @Bean(name = "jdbcBD") @Autowired public JdbcTemplate jdbcBD(@Qualifier("dsBD") DataSource dsBD) { return new JdbcTemplate(dsBD); } `Jonathan Choy Rivera– Jonathan Choy Rivera2017年06月20日 00:40:48 +00:00Commented Jun 20, 2017 at 0:40
 - 
 That is fine and all, but can we have all of that in the question itself?M. Prokhorov– M. Prokhorov2017年06月20日 06:13:18 +00:00Commented Jun 20, 2017 at 6:13
 - 
 I got error when run the app.Jonathan Choy Rivera– Jonathan Choy Rivera2017年06月20日 15:59:43 +00:00Commented Jun 20, 2017 at 15:59
 - 
 Possible duplicate of I am getting DataSource Not Supported when using DataSouceBuilderAlex R– Alex R2018年10月11日 02:54:22 +00:00Commented Oct 11, 2018 at 2:54
 
1 Answer 1
In terms to use DataSourceBuilder you need to have one of the following on your classpath:
- COMMONS-DBCP
 - TOMCAT-JDBC
 - HIKARICP
 
Otherwise you will get an IllegalStateException for no supported type, as you get now.
 answered Jun 20, 2017 at 7:14
 
 
 
 Lazar Lazarov 
 
 2,5524 gold badges28 silver badges35 bronze badges
 
 
 Sign up to request clarification or add additional context in comments.
 
 
 
 1 Comment
Jonathan Choy Rivera
 Thanks lazarov. I added common-dbcp library and run.