gpt4 book ai didi

mysql - Spring Boot 和 MySQL 找不到数据库

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

我试图在我的项目中解决这个问题,但它每次都出现。我已经添加了前缀为 spring.datasource 的属性,但它仍然无法正常工作。

有人能帮帮我吗?

我想使用 Spring Boot、MySQL 和 Hibernate 构建 Web 应用程序。我还没有在互联网上找到答案。谢谢。

2016-10-22 14:49:15.072 ERROR 23100 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 
***************************
APPLICATION FAILED TO START
***************************
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).

这是我的代码:

<groupId>com</groupId>
<artifactId>lardi</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Phone Book</name>

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

<!-- JSON -->
<jackson-json.version>2.8.0</jackson-json.version>

<!-- WEB jars -->
<webjars-bootstrap.version>3.3.6</webjars-bootstrap.version>
<webjars-jquery.version>2.2.4</webjars-jquery.version>
<webjars-noty.version>2.3.8</webjars-noty.version>
<webjars-datatables.version>1.10.12</webjars-datatables.version>
</properties>

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

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>

<dependencies>
<!-- Spring Boot WEB -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!-- Spring Boot TEST -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Spring Boot Validation -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- Spring Boot Security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- Spring Boot JPA -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- JSON -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-json.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate5</artifactId>
<version>${jackson-json.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson-json.version}</version>
</dependency>
<!-- Webjars -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>${webjars-bootstrap.version}</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>${webjars-jquery.version}</version>
</dependency>
<dependency>
<groupId>org.webjars.bower</groupId>
<artifactId>noty</artifactId>
<version>${webjars-noty.version}</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>datatables</artifactId>
<version>${webjars-datatables.version}</version>
</dependency>
</dependencies>

@SpringBootApplication
@EnableJpaRepositories(basePackageClasses = {Contact.class, User.class, BaseEntity.class})
public class SpringBootWebApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootWebApplication.class, args);
}
}

这是我的属性:

spring.jpa.database=MYSQL
spring.datasource.url=jdbc:mysql://localhost:3306/lardi
spring.datasource.username=root
spring.datasource.password=2940063
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
useSSL=false
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

最佳答案

您需要告诉 Spring Boot 如何连接到您的数据库。如果您已添加驱动程序,我们无法为您猜测位置和身份验证信息。您会找到更多信息 in the documentation

尝试在src/main/resources/application.properties中添加以下内容

spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.username=dbuser
spring.datasource.password=dbpass

当然,您必须调整数据库名称 (test) 和用户名/密码。

关于mysql - Spring Boot 和 MySQL 找不到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40192072/

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