0

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?autoReconne‌​ct=true")
 .username("‌​root")
 .password("mysql")
 .driverClassName("com.mysql.jdbc.Drive‌​r")
 .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
5
  • 1
    You 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. Commented 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); } ` Commented Jun 20, 2017 at 0:40
  • That is fine and all, but can we have all of that in the question itself? Commented Jun 20, 2017 at 6:13
  • I got error when run the app. Commented Jun 20, 2017 at 15:59
  • Possible duplicate of I am getting DataSource Not Supported when using DataSouceBuilder Commented Oct 11, 2018 at 2:54

1 Answer 1

8

In terms to use DataSourceBuilder you need to have one of the following on your classpath:

  1. COMMONS-DBCP
  2. TOMCAT-JDBC
  3. HIKARICP

Otherwise you will get an IllegalStateException for no supported type, as you get now.

answered Jun 20, 2017 at 7:14
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks lazarov. I added common-dbcp library and run.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.