我从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>
.....
============更新==============
Apllication不能以错误开头:
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.
答案 0 :(得分:0)
它说
未知数据库'myDb'
所以你检查过这个数据库是否已经存在?
由于intellij的db-connection无法访问该数据库,因此问题可能存在于您的连接参数(URL,用户名,密码)或mysql中,而不是代码中。