1. Modify Nacos configuration
The configuration file is under conf in the nacos directory
Modification point:
Note: The corresponding database nacos needs to be added, and the corresponding SQL file is also in the conf directory
2. Modify the bootstrap.yaml configuration file
spring:
application:
name: servername
profiles:
active: dev
cloud:
nacos:
username: nacos #user表中的名字
password: nacos #user表中的密码
discovery:
server-addr: localhost:8848
username and password get:
Method 1: Modify the database directly
2.1 import pom file
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
2.2 Generate password using code
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
public class Demo {
public static void main(String[] args) {
//在控制台打印加密后的密码
System.out.println(new BCryptPasswordEncoder().encode("nacos")); //密码为nacos
}
}
2.3 Modify the database
Modify the database table generated in step 1: users
Finally, you can access Nacos after starting the project. You must add username and password to the configuration to access