mysql Java Springboot没有像预期的那样工作,我的代码有什么问题

vxf3dgd4  于 2023-10-15  发布在  Mysql
关注(0)|答案(2)|浏览(103)

我们刚刚开始用springboot。我做了我的教授所展示的所有步骤,但它似乎没有创建一个数据库。

**Application**
spring.datasource.url = jdbc:mysql://localhost:3306/dbLastNameDemo

spring.datasource.username = root
spring.datasource.password = password

spring.jpa.database-platform = org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.ddl-auto = update

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

server.error.include.stacktrace=never
**Console**
2023-10-04 21:24:10.672  INFO 24832 --- [  restartedMain] c.c.delapena.DelapenaApplication         : Starting DelapenaApplication using Java 19.0.1 on Daesut with PID 24832 (C:\Users\Daesut\Downloads\delapena\delapena\target\classes started by Daesut in C:\Users\Daesut\Downloads\delapena\delapena)
2023-10-04 21:24:10.673  INFO 24832 --- [  restartedMain] c.c.delapena.DelapenaApplication         : No active profile set, falling back to 1 default profile: "default"
2023-10-04 21:24:10.717  INFO 24832 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2023-10-04 21:24:10.717  INFO 24832 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2023-10-04 21:24:11.134  INFO 24832 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-10-04 21:24:11.145  INFO 24832 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 4 ms. Found 0 JPA repository interfaces.
2023-10-04 21:24:11.702  INFO 24832 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2023-10-04 21:24:11.714  INFO 24832 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-10-04 21:24:11.714  INFO 24832 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.80]
2023-10-04 21:24:11.774  INFO 24832 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-10-04 21:24:11.774  INFO 24832 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1057 ms
2023-10-04 21:24:11.821 ERROR 24832 --- [  restartedMain] com.zaxxer.hikari.HikariConfig           : Failed to load driver class com.mysql.cj.jdbc.Driver from HikariConfig class classloader jdk.internal.loader.ClassLoaders$AppClassLoader@c387f44
2023-10-04 21:24:11.823  WARN 24832 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.RuntimeException: Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig class loader or Thread context classloader
2023-10-04 21:24:11.825  INFO 24832 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2023-10-04 21:24:11.835  INFO 24832 --- [  restartedMain] ConditionEvaluationReportLoggingListener :

这些都在控制台日志里
我们应该为工作台创建一个表

r1zhe5dt

r1zhe5dt1#

检查此步骤

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>
tyu7yeag

tyu7yeag2#

你可以错过:

<dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driverapplication.properties
确保每个文件,文件夹作为parent包的子包

相关问题