2015-08-07 18 views
7

Ottenere questo errore durante l'esecuzione dell'applicazione. Sto usando MongoDb con i dati di primavera. Inoltre, sto usando lo stivale a molla.Eccezione durante la configurazione di MongoDb con 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 

Ho sotto le righe nel mio file 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 

Mia entità (documento), questa classe è in un pacchetto diverso rispetto alla classe principale.

@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; 
} 

} 

Classe My MongoRepository. Questa è una classe in un pacchetto diverso rispetto alla classe main e alla classe entity (document).

public interface BloodGroupRepository extends MongoRepository<BloodGroup, String>{ 

} 

devo @EnableMongoRepositories ("com.awt.mongo.repository") in classe principale.
Non riesco a trovare alcuna soluzione.
Qualsiasi aiuto sarà apprezzato. Grazie.

+0

Dai un'occhiata alla http://stackoverflow.com/questions/13311603/autowired-beans-not-loading-after-using-beansprofiles-in -spring-3-1 L'eccezione sembra essere causata dal fatto che il cablaggio automatico non è stato impostato correttamente –

+0

la causa principale è: Causato da: org.springframework.beans.factory.BeanCreationException: Impossibile eseguire il campo autowire: private javax.sql.DataSource. Dai un'occhiata alla documentazione di sprint riguardante la configurazione della fonte dei dati: http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-two-datasources –

+0

Ho controllato il tuo dato link ma io non sono in grado di scoprire il problema. Puoi aiutare a risolvere questo problema, ho anche inviato log e corsi. –

risposta

19

L'eccezione era perché jpa molla. Ho rimosso la dipendenza da spring-jpa da pom.xml e ha risolto il mio problema. Grazie a tutti per l'aiuto e una rapida risposta.

+0

Risolve anche il mio problema, chiedendomi quale fosse la ragione. Mongodb è configurato da JPA non è? – Manish

+1

Mongodb è configurato da dati primaverili –

1

posso vedere dal vostro errore che l'origine dati non è configurato correttamente:

"causato da: org.springframework.beans.BeanInstantiationException: Impossibile creare un'istanza [javax.sql.DataSource]: metodo di fabbrica 'dataSource 'ha gettato un'eccezione, l'eccezione nidificata è org.springframework.beans.factory.BeanCreationException: impossibile determinare la classe del driver del database incorporato per il tipo di database NONE. Se si desidera un database incorporato, si prega di inserirne uno supportato nel classpath. "

ho il sospetto la linea che afferma:

spring.datasource.driverClassName=com.mongodb.Mongo 

è sbagliato - questo sembra un driver JDBC, ma come MongoDB è un database NoSQL il suo driver non è conforme agli stessi standard.

Il spring documentation suggerisce le seguenti proprietà per 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

Ho rimosso spring.datasource.driverClassName = com.mongodb.Mongo, ottenendo sempre la stessa eccezione. Non c'è nome utente e password per il mio mongoDb locale. –

+0

È ancora esattamente lo stesso errore? Le eccezioni di primavera contengono molte informazioni e talvolta è facile perdere l'errore reale in profondità nella traccia dello stack – Trisha

+0

Sì, l'ho controllato di nuovo. La sua stessa eccezione. –

1

ho rimosso il tag <version> nel file di POM, il problema risolto

Problemi correlati