前提:Linux一定保持联网状态
一·、首先将linux中的redis配置文件redis.conf更改三个地方
1、注释掉bind
2、更改protected-mode为no
3、添加登录密码(也可不添加)
这三个修改完成后Esc然后:wq保存退出
二、登录redis
正常登录只不过需要输入密码auth 密码
三、需要关闭防火墙
在一个新的终端输入
#关闭防火墙;
systemctl stop firewalld.service
#禁止防火墙启动;
systemctl disable firewalld.service
四、idea创建一个springboot的项目
1、导入依赖: pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
</parent>
<dependencies>
<!-- 映入tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.10</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.5</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<!--Redis 依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
在配置文件application.properties中添加配置
Linux的ip地址,端口号和密码
server:
port: 8080
spring:
datasource:
url: jdbc:mysql://localhost:3306/codelife?userUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull&tinyIntlisBit=false&serverTimezone=UTC
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
redis:
host: 192.168.73.130 #Redis服务器连接IP
port: 6379 #Redis服务器连接端口
timeout: 5000 #Redis服务器连接超时设置
mybatis-plus:
mapper-locations: classpath:/mapper/*/*.xml
config-location: classpath:mybatis-config.xml
------------(Linux中ip地址,在Linux中输入ifconfiginet后面的就是)---------------
然后在测试类中测试即可
package com.test.law;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
@SpringBootTest
public class RedisTest {
@Autowired
private RedisTemplate redisTemplate;
@Test
public void contextLoads(){
redisTemplate.opsForValue().set("name", "xuesheng");
System.out.println(redisTemplate.opsForValue().get("name"));
}
}
————————————————
版权声明:本文为CSDN博主「暴走的山交」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_43649223/article/details/109326300