2017-07-20 118 views
0

我在intellij上啓動了一個tomcat服務器(沒有部署任何東西),並且出現以下錯誤。我一直在尋找它,但沒有運氣。你能幫我麼?使用tomcat啓動服務器時創建bean時出錯

非常感謝提前。

的錯誤是以下之一:

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). 
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:296) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:829) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE] 
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE] 
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE] 
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE] 
at org.springframework.boot.context.web.SpringBootServletInitializer.run(SpringBootServletInitializer.java:149) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE] 
at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:129) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE] 
at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:85) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE] 
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175) [spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE] 
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196) [catalina.jar:8.5.16] 
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.5.16] 
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752) [catalina.jar:8.5.16] 
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728) [catalina.jar:8.5.16] 
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734) [catalina.jar:8.5.16] 
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1144) [catalina.jar:8.5.16] 
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1878) [catalina.jar:8.5.16] 
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_91] 
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_91] 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_91] 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_91] 
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91] 

造成的:org.springframework.beans.factory.BeanCreationException:難道 沒有自動裝配領域:私人的javax.sql.DataSource org.springframework.boot。 autoconfigure.liquibase.LiquibaseAutoConfiguration $ LiquibaseConfiguration.dataSource;嵌套異常是org.springframework.beans.factory.BeanCreationException:在類路徑資源[org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration $ NonEmbeddedConfiguration.class]中定義名稱爲'dataSource'的bean時出錯:通過工廠方法的Bean實例化失敗;嵌套異常是org.springframework.beans.BeanInstantiationException:無法實例化[javax.sql.DataSource]:工廠方法'dataSource'拋出異常;嵌套異常是org.springframework.boot.autoconfigure.jdbc.DataSourceProperties $ DataSourceBeanCreationException:無法確定數據庫類型爲NONE的嵌入式數據庫驅動程序類。如果你想要一個嵌入式數據庫,請在類路徑中放一個支持的數據庫。如果您要從特定配置文件加載數據庫設置,則可能需要激活它(沒有配置文件當前處於活動狀態)。 at org.springframework。org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)〜[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 。 beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)〜[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor。 postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)〜[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] ... 41常見幀被遺漏 引起:org.springframework.beans.factory.BeanCreationException:在類路徑資源[org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration $ NonEmbeddedConfiguration.clas中定義名稱'dataSource'時創建bean時出錯s]:通過工廠方法的Bean實例化失敗;嵌套異常是org.springframework.beans.BeanInstantiationException:無法實例化[javax.sql.DataSource]:工廠方法'dataSource'拋出異常;嵌套異常是org.springframework.boot.autoconfigure.jdbc.DataSourceProperties $ DataSourceBeanCreationException:無法確定數據庫類型爲NONE的嵌入式數據庫驅動程序類。如果你想要一個嵌入式數據庫,請在類路徑中放一個支持的數據庫。如果您要從特定配置文件加載數據庫設置,則可能需要激活它(沒有配置文件當前處於活動狀態)。 at org.springframework.beans。org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)〜[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] 。 factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)〜[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance( AbstractAutowireCapableBeanFactory.java:1018)〜[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)〜[ spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory .createBean(AbstractAutowireCapableBeanFactory.java:482)〜[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java: 306)〜[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.support。DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)〜[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java: 302)〜[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)〜[spring-beans- 4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)〜[spring-beans-4.2.5.RELEASE.jar: 4.2.5.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)〜[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.suppor t.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)〜[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject( AutowiredAnnotationBeanPostProcessor.java:545)〜[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] ... 43常見幀被遺漏 引起:org.springframework.beans.BeanInstantiationException:無法實例化[ javax.sql.DataSource]:工廠方法'dataSource'拋出異常;嵌套異常是org.springframework.boot.autoconfigure.jdbc.DataSourceProperties $ DataSourceBeanCreationException:無法確定數據庫類型爲NONE的嵌入式數據庫驅動程序類。如果你想要一個嵌入式數據庫,請在類路徑中放一個支持的數據庫。如果您要從特定配置文件加載數據庫設置,則可能需要激活它(沒有配置文件當前處於活動狀態)。 at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)〜[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.beans。 factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)〜[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE] ... 55常見幀遺漏 引起:org.springframework。 boot.autoconfigure.jdbc.DataSourceProperties $ DataSourceBeanCreationException:無法確定數據庫類型爲NONE的嵌入式數據庫驅動程序類。如果你想要一個嵌入式數據庫,請在類路徑中放一個支持的數據庫。如果您要從特定配置文件加載數據庫設置,則可能需要激活它(沒有配置文件當前處於活動狀態)。 at org.springframework。org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.getDriverClassName(DataSourceProperties.java:180)〜[spring-boot-autoconfigure-1.3.3.RELEASE.jar:1.3.3.RELEASE] 。 boot.autoconfigure.jdbc.DataSourceAutoConfiguration $ NonEmbeddedConfiguration.dataSource(DataSourceAutoConfiguration.java:121)〜[spring-boot-autoconfigure-1.3.3.RELEASE.jar:1.3.3.RELEASE] at sun.reflect.NativeMethodAccessorImpl.invoke0( Native Method)〜[na:1.8.0_91] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)〜[na:1.8.0_91] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43 )〜[na:1.8.0_91] at java.lang.reflect.Method.invoke(Method.java:498)〜[na:1.8.0_91] at org.springframework.beans.factor y.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)〜[彈簧豆-4.2.5.RELEASE.jar:4.2.5.RELEASE] ... 56個共同幀省略

編輯:

Application.properties:

server.port=8081 

spring.datasource.database-platform=org.hibernate.dialect.PostgreSQLDialect 
spring.datasource.driverClassName=org.postgresql.Driver 
spring.datasource.url=jdbc:postgresql://***.com:5432/postgres 
spring.datasource.username=*** 
spring.datasource.password=*** 
liquibase.change-log=classpath:/db/changelog-master.xml 
liquibase.enabled=true 
+1

'無法確定數據庫類型爲NONE的嵌入式數據庫驅動程序類。如果你想要一個嵌入式數據庫,請在類路徑中放一個支持的數據庫。如果你的數據庫設置是從一個特定的配置文件加載的,你可能需要激活它(沒有配置文件當前處於活動狀態)。' –

+0

不是很有幫助,但是謝謝 –

回答

1

正如所說的@伊萬 - 普羅寧,則需要依賴到classpath。例如,如果您想使用H2,請將其添加到您的pom.xml文件中。

<dependency> 
    <groupId>com.h2database</groupId> 
    <artifactId>h2</artifactId> 
</dependency> 

如果您使用gradle,然後將其添加到build.gradle。這適用於在類路徑中使用自動發現的可嵌入數據庫。如果您想使用其他數據庫(例如Mysql),則必須配置您的application.properties或application.yml。

spring: 
    datasource: 
     url: jdbc:mysql://myserver:3306/mydb?autoReconnect=true&useSSL=false 
     username: foo 
     password: bar 
     driver-class-name: com.mysql.jdbc.Driver 
+0

非常感謝@rvillablanca我已經用我的application.properties更新了這個問題。我想這肯定是一個錯字,但我無法識別它,你看到有什麼不對嗎? –

+0

@albertocarmona你有沒有把postgress的驅動添加到你的類路徑中?你是否得到相同的異常? – rvillablanca

+0

是的,它包含在類路徑中 –