【发布时间】:2018-04-26 13:21:26
【问题描述】:
我已经从 git 导入了 spring-boot maven 项目。本项目使用Mysql。 我在工作台中创建了具有自定义名称的数据库。
application.properties 文件:
spring.datasource.url = jdbc:mysql://localhost:3306/myDb?autoReconnect=true&useSSL=false
spring.datasource.username = root
spring.datasource.password= root
我放入 intellij 的 db-connection 窗口的凭据相同。 当我点击“测试连接”时,我得到了:
Connection to myDb@localhost failed.
[42000][1049] Unknown database 'myDb'
Pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>
.....
============更新==============
应用程序无法以错误开始:
2018-04-26 13:12:22.404 ERROR 3988 --- [ost-startStop-1] o.s.b.c.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'jwtFilterRegistration' defined in com.edsson.expopromoter.api.Application: Unsatisfied dependency expressed through method 'jwtFilterRegistration' parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService' defined in file [C:\Users\koliada\Desktop\IdeaProjects\ExpoPromoter\expopromoter-api\target\classes\com\edsson\expopromoter\api\user\service\UserService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Cannot create inner bean '(inner bean)#64607e71' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#64607e71': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
2018-04-26 13:12:22.428 WARN 3988 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
2018-04-26 13:12:22.478 ERROR 3988 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.edsson.expopromoter.api.user.service.UserService required a bean named 'entityManagerFactory' that could not be found.
【问题讨论】:
-
您的应用程序是否启动并能够找到数据库?
-
我已经更新了。请检查
-
您遇到的错误与 IntelliJ 无关。本地计算机上无法访问您的数据库。
-
看来你是对的。无论如何你能帮我解决这个问题吗?