2017-07-22 8 views
0

私はスプリングブートアプリケーションのBeanを設定していますが、次のエラーが表示されます。 MyDataSourceクラスが正しいかどうか、またapplication.properties内に何かがないかどうかはわかりません。データソースdbプロジェクトのBeanを自動生成する

事前に感謝します。

2017-07-22 13:50:33.752 WARN 6872 --- [ost-startStop-1] 
ationConfigEmbeddedWebApplicationContext : Exception encountered during 
context initialization - cancelling refresh attempt: 
org.springframework.beans.factory.BeanCreationException: Error creating bean 
with name 
'org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$LiquibaseConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$LiquibaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: 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 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active). 
2017-07-22 13:50:33.780 ERROR 6872 --- [ost-startStop-1] o.s.boot.SpringApplication    : Application startup failed 

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$LiquibaseConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$LiquibaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: 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 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active). 

MyDatasourceのクラス:

public class MyDataSource { 

private static final String driverClassName = "org.postgresql.Driver"; 
private static final String url = "jdbc:postgresql://mydbinstance3.ckvnevtnxxbs.us-west-2.rds.amazonaws.com:5432/postgres"; 
private static final String dbUsername = "OnFocus"; 
private static final String dbPassword = "G0nk0p0rr0"; 

private static DataSource dataSource; 

public static void main(String[] args) throws Exception { 

    dataSource = getDataSource(); 

    // JdbcTemplate template = new JdbcTemplate(dataSource); // constructor 

    JdbcTemplate template = new JdbcTemplate(); 
    template.setDataSource(dataSource); 

    System.out.println(dataSource.getClass()); 

} 

public static DriverManagerDataSource getDataSource() { 

    DriverManagerDataSource dataSource = new DriverManagerDataSource(); 

    dataSource.setDriverClassName(driverClassName); 

    dataSource.setUrl(url); 

    dataSource.setUsername(dbUsername); 

    dataSource.setPassword(dbPassword); 

    return dataSource; 
} 

} 

Build.gradle:

buildscript { 
repositories { 
    mavenCentral() 
} 
dependencies { 
    classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE") 
    classpath 'io.spring.gradle:dependency-management-plugin:0.6.1.RELEASE' 
} 
} 

apply plugin: 'java' 
apply plugin: 'eclipse' 
apply plugin: 'idea' 
apply plugin: 'spring-boot' 
apply plugin: 'war' 

version = '1.0-SNAPSHOT' 
buildDir = 'target' 

jar { 
baseName = rootProject.name 
} 

war { 
baseName = 'myapp' 
version = '1.0.0' 
} 
repositories { 
jcenter() 
maven { url "http://repo.spring.io/libs-snapshot" } 
} 

sourceCompatibility = 1.8 
targetCompatibility = 1.8 

dependencies { 
compile("org.springframework.boot:spring-boot-starter-data-jpa:1.2.5.RELEASE") 
compile("org.springframework.boot:spring-boot-starter-web") 
compile("org.springframework.boot:spring-boot-starter-actuator") 
compile("org.postgresql:postgresql:9.4-1201-jdbc41") 
compile("org.springframework:spring-jdbc:4.2.4.RELEASE") 
compile("com.fasterxml.jackson.core:jackson-databind") 
compile("org.liquibase:liquibase-core:3.3.3") 
compile("org.springframework.boot:spring-boot-starter-data-mongodb") 
compile 'org.springframework.boot:spring-boot-starter-thymeleaf' 
compile("org.springframework.boot:spring-boot-starter-web") 

providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat' 

testCompile("junit:junit") 
} 

bootRepackage { 
mainClass = 'theproject.src.main.java.tutorialDatabaseServer.Application' 
} 

Application.properties:

server.port=8081 
spring.datasource.database-platform=org.hibernate.dialect.PostgreSQLDialect 
spring.datasource.driverClassName=org.postgresql.Driver 
spring.datasource.url=jdbc:postgresql://mydbinstance3.ckvnevtnxxbs.us-west- 
2.rds.amazonaws.com:5432/postgres 
spring.datasource.username=OnFocus 
spring.datasource.password=G0nk0p0rr0 
liquibase.change-log=classpath:/db/changelog-master.xml 
liquibase.enabled=true 

アプリケーションクラス:

@SpringBootApplication 
public class Application extends SpringBootServletInitializer { 

@Override 
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 
    return application.sources(Application.class); 
} 

public static void main(String[] args) throws Exception { 
    SpringApplication.run(Application.class, args); 
} 

答えて

0

あなたはあなたの特性でLiquiBaseをの使用を可能にしているが

liquibase.enabled=true 
を提出あなたが意図的にそれを起動したことがありますか?私はliquibaseの依存関係と変更ログファイルを参照しないでください。

+0

私はそれをfalseに変更しても、同じ問題 –

+0

@AlbertoCarmonaなぜあなたはそれらを使用しない場合、あなたはliquibaseプロパティを置いていますか? liquibase.change-log = classpath:/db/changelog-master.xml liquibase.enabled = true – rnside

+0

私は以前のバージョンのコードを持っていたと思います。私はそれを取ったが、まだ同じ... –

0

(LiquiBaseをを使用していない場合)、コメントまたは削除しようとするこれらの行は

liquibase.change-LOG =クラスパス:

真= liquibase.enabled /db/changelog-master.xml

私はあなたがliquibaseを使用していることを知っていると思います。あなたがliquibaseプロパティを設定すると、spring deはliquibase beanをインスタンス化しようとしています。あなたがそれを必要としないなら、それを使用しないでください。

関連する問題