2017-09-06 19 views
0

Springアプリケーションの実行中に次のエラーが発生しました。私はこの問題を解決するためにいくつかの助けが必要ですか、誰かがこの問題のデバッグと解決にどのようにアプローチできるか教えていただければ幸いです。私はちょうどインターネットを経由して、私のpom.xmlファイルでさまざまな組み合わせをしています。クラスパスリソースで定義された 'entityManagerFactory'という名前のBeanを作成中にエラーが発生しました

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1716) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:499) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1083) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3] 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:858) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.0.0.RC3.jar:5.0.0.RC3] 
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:122) ~[spring-boot-2.0.0.M3.jar:2.0.0.M3] 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.0.0.M3.jar:2.0.0.M3] 
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.0.M3.jar:2.0.0.M3] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.M3.jar:2.0.0.M3] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1245) [spring-boot-2.0.0.M3.jar:2.0.0.M3] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1233) [spring-boot-2.0.0.M3.jar:2.0.0.M3] 
    at ca.naijaconnects.naijaconnectsproject.NaijaconnectsProjectApplication.main(NaijaconnectsProjectApplication.java:15) [classes/:na] 
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:271) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:858) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:885) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-5.0.0.RC3.jar:5.0.0.RC3] 
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:358) ~[spring-orm-5.0.0.RC3.jar:5.0.0.RC3] 
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:384) ~[spring-orm-5.0.0.RC3.jar:5.0.0.RC3] 
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-5.0.0.RC3.jar:5.0.0.RC3] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1776) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1712) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] 
    ... 16 common frames omitted 
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.dialect.MYSQL5Dialect] as strategy [org.hibernate.dialect.Dialect] 
    at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:126) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:194) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:152) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:139) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:133) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:74) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:51) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final] 
    ... 32 common frames omitted 

これは私のpom.xmlある

<?xml version="1.0" encoding="UTF-8"?> 
    <project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
    http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>ca.naijaconnects</groupId> 
    <artifactId>naijaconnectsProject</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>naijaconnectsProject</name> 
    <description>none</description> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>2.0.0.M3</version> 
     <relativePath/> <!-- lookup parent from repository --> 
    </parent> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding 
     > 
     <java.version>1.8</java.version> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
    <groupId>org.apache.tomcat</groupId> 
    <artifactId>tomcat-servlet-api</artifactId> 
    <version>8.0.15</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.data</groupId> 
     <artifactId>spring-data-jpa</artifactId> 

    </dependency> 
    <!-- https://mvnrepository.com/artifact/javax.persistence/persistence-api --> 
    <dependency> 
    <groupId>javax.persistence</groupId> 
    <artifactId>persistence-api</artifactId> 
    <version>1.0.2</version> 
    </dependency> 

    <dependency> 
    <groupId>org.springframework.data</groupId> 
    <artifactId>spring-data-rest-core</artifactId> 

    </dependency> 

    <dependency> 
    <groupId>mysql</groupId> 
    <artifactId>mysql-connector-java</artifactId> 

    </dependency> 
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot- 
    starter-data-jpa --> 
    <dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-data-jpa</artifactId> 

    </dependency> 
    <dependency> 
    <groupId>org.javassist</groupId> 
    <artifactId>javassist</artifactId> 

    </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 

    <repositories> 
    <repository> 
     <id>spring-libs-release</id> 
     <name>Spring Releases</name> 
     <url>https://repo.spring.io/libs-release</url> 
     <snapshots> 
      <enabled>false</enabled> 
     </snapshots> 
    </repository> 

     <repository> 
      <id>spring-snapshots</id> 
      <name>Spring Snapshots</name> 
      <url>https://repo.spring.io/snapshot</url> 
      <snapshots> 
       <enabled>true</enabled> 
      </snapshots> 
     </repository> 
     <repository> 
      <id>spring-milestones</id> 
      <name>Spring Milestones</name> 
      <url>https://repo.spring.io/milestone</url> 
      <snapshots> 
       <enabled>false</enabled> 
      </snapshots> 
     </repository> 
    </repositories> 

    <pluginRepositories> 
     <pluginRepository> 
      <id>spring-snapshots</id> 
      <name>Spring Snapshots</name> 
      <url>https://repo.spring.io/snapshot</url> 
      <snapshots> 
       <enabled>true</enabled> 
      </snapshots> 
     </pluginRepository> 
     <pluginRepository> 
      <id>spring-milestones</id> 
      <name>Spring Milestones</name> 
      <url>https://repo.spring.io/milestone</url> 
      <snapshots> 
       <enabled>false</enabled> 
      </snapshots> 
     </pluginRepository> 
    </pluginRepositories> 


    </project> 

これは私のアプリケーションを実行する

package ca.naijaconnects.naijaconnectsproject; 

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.context.ApplicationContext; 
import org.springframework.context.annotation.AnnotationConfigApplicationContext; 
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 

@SpringBootApplication 
public class NaijaconnectsProjectApplication { 

    public static void main(String[] args) { 

     ApplicationContext factory = new AnnotationConfigApplicationContext(); 
     SpringApplication.run(NaijaconnectsProjectApplication.class, args); 
    } 
} 

は、これは私の設定ファイルです

package ca.naijaconnects.naijaconnectsproject.config; 

import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 

import ca.naijaconnects.naijaconnectsproject.entity.UserLoginDetails; 

@Configuration 
@EnableJpaRepositories 
public class ApplicationConfig 
{ 
    @Bean 
    public UserLoginDetails userLoginDetails() 
    { 
     return new UserLoginDetails(); 
    } 

} 

これは私のコントローラ

です
package ca.naijaconnects.naijaconnectsproject.controller; 
import java.util.List; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.context.annotation.Bean; 
import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.ResponseBody; 
import org.springframework.web.bind.annotation.RestController; 
import ca.naijaconnects.naijaconnectsproject.entity.UserLoginDetails; 
import ca.naijaconnects.naijaconnectsproject.repo.UserLoginRepo; 
@Controller 
@RequestMapping(value="/testing") 
public class NaijaConnectsController 
{ 
    @Autowired 
    UserLoginRepo userLoginRepo; 
    @SuppressWarnings("unchecked") 
    @RequestMapping(value = "/insertLogins", method = RequestMethod.POST) 
    public @ResponseBody List<UserLoginDetails> PostFormDataJSONArray() { 
     UserLoginDetails userLoginDetail = new UserLoginDetails(); 
     userLoginDetail.setUserName("timisenco"); 
     userLoginDetail.setUserPassword("[email protected]"); 
     return (List<UserLoginDetails>) userLoginRepo.save(userLoginDetail); 
    } 

} 

これはこれは、レポ

package ca.naijaconnects.naijaconnectsproject.repo; 
import java.util.List; 
import javax.sql.DataSource; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.context.annotation.Bean; 
import org.springframework.data.jpa.repository.*; 
import org.springframework.stereotype.Repository; 
import ca.naijaconnects.naijaconnectsproject.entity.UserLoginDetails; 

@org.springframework.data.rest.core.annotation.RepositoryRestResource(exported=false) 

public interface UserLoginRepo extends JpaRepository<UserLoginDetails, String> 
{ 

    //UserLoginDetails findOne(String); 
    @SuppressWarnings("unchecked") 
    UserLoginDetails save(UserLoginDetails account); 
    //UserLoginDetails findByEmailAddress(EmailAddress emailAddress); 
} 

EDIT

application.properties

spring.datasource.driver-class-name=com.mysql.jdbc.Driver 
spring.datasource.url=jdbc:mysql://localhost/naijaconnectsdb 
spring.datasource.username=naijaConnects 
[email protected] 
spring.datasource.name=naijaconnectsdb 
spring.jpa.hibernate.ddl-auto=null 
spring.jpa.generate-ddl=true 
spring.jpa.show-sql=true 
spring.data.jpa.repositories.enabled=true 
spring.jpa.database-platform=org.hibernate.dialect.MYSQL5Dialect 
である私のエンティティ

package ca.naijaconnects.naijaconnectsproject.entity; 
import java.io.Serializable; 

import javax.persistence.*; 

import org.springframework.context.annotation.Bean; 

@Entity 
//@Table(name = "userlogindetails") 
public class UserLoginDetails 
{ 
    @Id 
    @Column(name = "USER_NAME", nullable = false,columnDefinition="varchar2(40)") 
    private String userName; 

    @Column(name = "USER_Pawword", nullable = false,columnDefinition="varchar2(40)") 
    private String userPassword; 


    public UserLoginDetails() 
    { 

    } 
    @Bean 
    public String getUserName() 
    { 
     return userName; 
    } 
    @Bean 
    public void setUserName(String userName) 
    { 
     this.userName = userName; 
    } 
    @Bean 
    public String getUserPassword() 
    { 
     return userPassword; 
    } 
    @Bean 
    public void setUserPassword(String userPasword) 
    { 
     this.userPassword = userPassword; 
    } 
} 

ですそこに通常application.propertiesファイルが存在するSpring Bootアプリケーションで

Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.dialect.MYSQL5Dialect] as strategy [org.hibernate.dialect.Dialect] 

答えて

2

さて、この一つが理由です。そこでは、あなたが使用する必要がある方言と、あなたの場合にはorg.hibernate.dialect.MYSQL5Dialectという方言を宣言しておくべきです。私はそこに入力ミスがあると信じて、それはorg.hibernate.dialect.MySQL5Dialect(MYSQLのYは小文字でなければなりません)でなければなりません。

* .propertiesファイルも投稿できますか?

だからあなたapplication.propertiesファイルに:

application.properties:

spring.datasource.driver-class-name=com.mysql.jdbc.Driver 
spring.datasource.url=jdbc:mysql://localhost/naijaconnectsdb 
spring.datasource.username=naijaConnects 
[email protected] 
spring.datasource.name=naijaconnectsdb 
spring.jpa.hibernate.ddl-auto=null 
spring.jpa.generate-ddl=true 
spring.jpa.show-sql=true 
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.Impro‌​vedNamingStrategy 
spring.data.jpa.repositories.enabled=true 
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dia‌​lect 
+0

spring.datasourceを

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

UPDATE 私はあなたのアプリケーションの性質は、以下のファイルを編集しました.driver-class-name = com.mysql.jdbc.Driver spring.datasource.url = JDBCます。mysql:// localhost /をnaijaconnectsdb spring.datasource.username = naijaConnects [email protected] spring.datasource.name = naijaconnectsdb spring.jpa.hibernate.ddl -auto =ヌル spring.jpa.generate-DDL =真 spring.jpa.show-SQL =真 spring.jpa.hibernate.naming-戦略= org.hibernate.cfg.ImprovedNamingStrategy spring.data.jpa。リポジトリ。enabled = true spring.jpa.database-platform = org.hibernate.dialect.MYSQL5Dialect – timisenco

+0

私はこの行を追加しましたspring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialectしかし、同じエラーを表示しています – timisenco

+0

同じエラーMYSQL5DialectまたはMySQL5Dialectを使用していますか? – pleft

関連する問題