gpt4 book ai didi

mysql - 无法在 spring-boot 中访问 mysql

转载 作者:行者123 更新时间:2023-11-29 02:46:47 24 4
gpt4 key购买 nike

我无法在 spring-boot 中使用 JPA 访问 mysql

我是 spring-boot 和 spring 的新手。

我得到的错误在下面

Description:

Parameter 0 of constructor in org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration required a bean of type 'javax.sql.DataSource' that could not be found.

- Bean method 'dataSource' not loaded because @ConditionalOnProperty (spring.datasource.jndi-name) did not find property 'jndi-name'

- Bean method 'dataSource' not loaded because @ConditionalOnBean (types: org.springframework.boot.jta.XADataSourceWrapper; SearchStrategy: all) did not find any beans
Action:
Consider revisiting the conditions above or defining a bean of type 'javax.sql.DataSource' in your configuration.

我的 application.properties 文件有以下几行

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase
spring.datasource.username=root
spring.datasource.password=mypassword
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update

查看错误我认为是 spring-boot 提示我没有设置 (spring.datasource.jndi-name) 属性.....我认为这是没有必要的,因为我已经给出了数据源 url & 登录凭据。

我不知道应该给 spring.datasource.jndi-name 什么值。

我很感激任何帮助。我对此感到震惊。

最佳答案

在应用程序开发开始时,我在主类中添加了:

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

我不想配置我的数据库。然后我就忘记了。删除此行后,上述错误消失。

关于mysql - 无法在 spring-boot 中访问 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41077526/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com