2015-08-07 14 views
7

Erhalte diesen Fehler während der Ausführung der Anwendung. Ich verwende MongoDb mit Federdaten. Außerdem benutze ich Springboot.Ausnahme bei der Konfiguration von MongoDb mit Spring-Data

[org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext] (MSC service thread 1-3) Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': 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.orm.jpa.JpaBaseConfiguration.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.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. 
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956) [spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747) [spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) [spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE] 
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE] 
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE] 
at org.springframework.boot.context.web.SpringBootServletInitializer.run(SpringBootServletInitializer.java:117) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE] 
at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:108) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE] 
at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:68) [spring-boot-1.2.2.RELEASE.jar:1.2.2.RELEASE] 
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175) [spring-web-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:182) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final] 
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:87) 
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.start(UndertowDeploymentService.java:72) 
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) 
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_80] 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_80] 
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_80] 
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource    org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.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.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. 
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561) [spring- beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
... 34 more 
Caused by: 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.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. 
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111) [spring- beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) [spring- beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
... 36 more 
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is  org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the  classpath. 
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) [spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE] 
... 48 more 

Ich habe unten Linien in meiner Datei application.properties.

spring.data.mongodb.host=127.0.0.1 
spring.data.mongodb.port=27017 
spring.datasource.driverClassName=com.mongodb.Mongo 
spring.data.mongodb.database=DigitalDiary 
spring.data.mongodb.repositories.enabled=true 

My Entity (Dokument), ist diese Klasse in verschiedenen Paket als Hauptklasse.

@Document(collection = "blood_group_collection") 
public class BloodGroup { 

@Id 
private String _id; 
@Indexed(unique=true) 
private String blood_group_type; 

public BloodGroup(String blood_group_type) { 
    super(); 
    this.blood_group_type = blood_group_type; 
} 

public String get_id() { 
    return _id; 
} 

public String getBlood_group_type() { 
    return blood_group_type; 
} 

public void setBlood_group_type(String blood_group_type) { 
    this.blood_group_type = blood_group_type; 
} 

} 

Meine MongoRepository Klasse. Diese Klasse befindet sich in einem anderen Paket als die Hauptklasse und die Entitätsklasse (Dokument).

public interface BloodGroupRepository extends MongoRepository<BloodGroup, String>{ 

} 

Ich habe @EnableMongoRepositories ("com.awt.mongo.repository") in Hauptklasse.
Ich kann keine Lösung finden.
Jede Hilfe wird geschätzt. Vielen Dank.

+0

einen Blick auf http://stackoverflow.com/questions/13311603/autowired-beans-not-loading-after-using-beansprofiles-in haben -Spring-3-1 Die Ausnahme scheint durch die automatische Verdrahtung verursacht wurde nicht richtig –

+0

Ursache die Ursache ist: verursacht durch: org.springframework.beans.factory.BeanCreationException: Konnte nicht Autowire-Feld: private javax.sql.DataSource. Sehen Sie sich die Sprint-Dokumentation zur Konfiguration der Datenquelle an: http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-two-datasources –

+0

Ich habe Ihren angegebenen Link überprüft, aber ich Ich bin nicht in der Lage, das Problem herauszufinden. Können Sie mir helfen, dies zu beheben, habe ich auch Protokolle und Klassen veröffentlicht. –

Antwort

19

Die Ausnahme wegen der Feder JPA war. Ich habe die Spring-JPA-Abhängigkeit von pom.xml entfernt und mein Problem gelöst. Danke an alle für Hilfe und schnelle Antwort.

+0

Es löste auch mein Problem und fragte mich, was der Grund war. Mongodb ist von JPA nicht konfiguriert? – Manish

+1

Mongodb wird durch Federdaten konfiguriert –

1

Ich kann von Ihrem Fehler sehen, die Ihre Datenquelle nicht richtig konfiguriert ist:

„Verursacht durch: org.springframework.beans.BeanInstantiationException: Fehler instanziiert [javax.sql.DataSource]: Factory-Methode‚datasource 'Ausnahme wurde ausgelöst; die verschachtelte Ausnahme ist org.springframework.beans.factory.BeanCreationException: Die Klasse des eingebetteten Datenbanktreibers für den Datenbanktyp NONE kann nicht ermittelt werden. Wenn Sie eine eingebettete Datenbank verwenden möchten, legen Sie eine unterstützte auf den Klassenpfad. "

Ich vermute, dass die Linie, die besagt:

spring.datasource.driverClassName=com.mongodb.Mongo 

falsch ist - dies wie ein JDBC-Treiber sieht, sondern als MongoDB eine NoSQL ist Datenbank sein Fahrer entspricht nicht den gleichen Standards.

Die spring documentation schlägt vor, die folgenden Eigenschaften für MongoDB:

spring.data.mongodb.host= # the db host 
spring.data.mongodb.port=27017 # the connection port (defaults to 27107) 
spring.data.mongodb.uri=mongodb://localhost/test # connection URL 
spring.data.mongodb.database= 
spring.data.mongodb.authentication-database= 
spring.data.mongodb.grid-fs-database= 
spring.data.mongodb.username= 
spring.data.mongodb.password= 
spring.data.mongodb.repositories.enabled=true # if spring data repository support is enabled 
+0

Ich entfernte spring.datasource.driverClassName = com.mongodb.Mongo, immer noch die gleiche Ausnahme. Es gibt keinen Benutzernamen und kein Passwort für meinen lokalen mongoDb. –

+0

Ist es immer noch genau der gleiche Fehler? Spring Exceptions enthalten viele Informationen und manchmal ist es einfach, den echten Fehler tief im Stack-Trace zu übersehen. – Trisha

+0

Ja, ich habe es noch einmal überprüft. Dieselbe Ausnahme. –

1

Ich entfernte die <version> Tag in POM-Datei, das Problem behoben

Verwandte Themen