java.lang.IllegalStateException: Nein unterstützt DataSource-Typ gefunden
Spring boot kann nicht mich datasource Postgres. Der Fehler ist ab hier:
at org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder.getType(DataSourceBuilder.java:138) ~[spring-boot-autoconfigure-1.5.7.RELEASE.jar:1.5.7.RELEASE]
Letztlich wirft Fehler:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: No supported DataSource type found
Habe ich gebaut Spring-Anwendungen mittels xml-Konfiguration und Maven, aber Spring Boot und Gradle sind für mich neu. Ich bin verwendet, um @Autowire
ziehen Sie die datasource aus der config-Datei. Basierend auf SO einige Antworten, ich habe eine Datenbank config-Klasse:
import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;
@Configuration
@PropertySource({ "classpath:application.properties" })
public class DatabaseConfig {
@Bean
@Primary
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
}
Ich versuche, autowire der datasource in meiner JDBC-Implementierung:
@Component
public class JDBCRegionNameDAO implements RegionNameDAO {
private JdbcTemplate jdbcTemplate;
@Autowired
public JDBCRegionNameDAO (DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
}
Meiner Anwendung.Eigenschaften, ich habe mein postgres-Anmeldeinformationen, und sichergestellt, dass der Dienst ausgeführt wird:
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/world_builder
spring.datasource.platform=postgres
spring.datasource.username=postgres
spring.datasource.password=postgres
Meine bauen.gradle, von dem, was ich sah, es scheint, ich habe hier alles, was ich brauche, aber der Fehler geworfen wird, oben schlägt vor, bin ich etwas fehlt:
buildscript {
ext {
springBootVersion = '1.5.7.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
group = 'group.group'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
configurations {
providedRuntime
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-devtools')
compile group: 'org.postgresql', name: 'postgresql', version: '42.1.4'
runtime('org.postgresql:postgresql')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
- Möglich, Duplikat der ich bin immer DataSource Nicht Unterstützt, wenn DataSouceBuilder
Du musst angemeldet sein, um einen Kommentar abzugeben.
Wurde das Problem mit der
compile('org.springframework.boot:spring-boot-starter-jdbc')
Abhängigkeit. Ändern diese in der folgenden löste das Problem für mich:compile 'org.springframework.boot:spring-boot-starter-data-jpa:1.5.6.RELEASE'
Möglicherweise die
jdbc
Paket oder eine Ihrer Abhängigkeiten ist nicht mehr unterstützt.`