springboot 连接mysql,不使用sll配置
时间: 2024-10-16 14:12:59 浏览: 39
Spring Boot连接MySQL时,如果不需要使用SSL加密,你可以通过以下步骤进行配置:
1. **添加依赖**:首先,在你的`pom.xml`文件中添加Spring Data JPA和MySQL Connector/J驱动的依赖:
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope> <!-- 非生产环境使用 -->
</dependency>
```
记得删除`spring-boot-starter-data-jpa`自动引入的对HikariCP或Poolman的支持。
2. **创建数据库配置**:在`application.properties`或`application.yml`中,设置数据库的相关信息,例如URL、用户名、密码等,示例:
```properties
spring.datasource.url=jdbc:mysql://localhost:3306/mydb?useSSL=false
spring.datasource.username=myusername
spring.datasource.password=mypassword
spring.jpa.hibernate.ddl-auto=update 或 create-drop
```
注意将`useSSL=false`设置为不使用SSL。
3. **JPA实体映射**:如果你有实体类(如`MyEntity.java`),确保它有一个`@Entity`注解,并且有一个`@Table`注解指定表名。
4. **启用数据源扫描**:在启动类上添加`@EnableJpaRepositories`和`@EntityScan`注解,以便Spring Data JPA能够扫描到你的实体类和Repository接口。
5. **运行应用**:现在你可以启动Spring Boot应用了。Spring Boot会自动处理与数据库的连接。
阅读全文
相关推荐
![7z](https://img-home.csdnimg.cn/images/20241231044736.png)
![7z](https://img-home.csdnimg.cn/images/20241231044736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![application/pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)