若依 + nacos 源码启动
前提:若依官网下载微服务并启动成功
一: 新增模块

二、创建模块 填写对应的信息

三、 下载nacos 源码 : https://github.com/alibaba/nacos
1、只需要 console 模块 复制到新建的模块中 其余可以删除

2、结构

3、修改application文件
### Default web context path: server.servlet.contextPath=/nacos ### If use MySQL as datasource: spring.main.allow-circular-references=true nacos.naming.empty-service.auto-clean=true nacos.naming.empty-service.clean.initial-delay-ms=50000 nacos.naming.empty-service.clean.period-time-ms=30000 management.metrics.export.elastic.enabled=false management.metrics.export.influx.enabled=false spring.datasource.platform=mysql db.num=1 db.url.0=jdbc:mysql://127.0.0.1:3306/ry-config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC db.user=root db.password=root #*************** Access Control Related Configurations ***************# ### The ignore urls of auth, is deprecated in 1.2.0: nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/** ### The auth system to use, currently only 'nacos' and 'ldap' is supported: nacos.core.auth.system.type=nacos ### If turn on auth system: nacos.core.auth.enabled=false ### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay. nacos.core.auth.caching.enabled=true ### Since 1.4.1, Turn on/off white auth for user-agent: nacos-server, only for upgrade from old version. nacos.core.auth.enable.userAgentAuthWhite=false nacos.core.auth.server.identity.key=serverIdentity nacos.core.auth.server.identity.value=security nacos.core.auth.plugin.nacos.token.expire.seconds=18000 nacos.core.auth.plugin.nacos.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789 #*************** Istio Related Configurations ***************# ### If turn on the MCP server: nacos.istio.mcp.server.enabled=false
4、添加类配置类:ConfigConstants
/** * @author :wx * @date :2022/9/7 10:10 * @description: 配置类 */ public interface ConfigConstants { /** * The System property name of Standalone mode */ String STANDALONE_MODE = "nacos.standalone"; /** * 是否开启认证 */ String AUTH_ENABLED = "nacos.core.auth.enabled"; /** * 日志目录 */ String LOG_BASEDIR = "server.tomcat.basedir"; /** * access_log日志开关 */ String LOG_ENABLED = "server.tomcat.accesslog.enabled"; }
5、在启动类中增加配置
/** * Nacos starter. * * @author nacos */ @SpringBootApplication(scanBasePackages = "com.alibaba.nacos") @ServletComponentScan @EnableScheduling public class NacosApplication { public static void main(String[] args) { if (initEnv()) { SpringApplication.run(NacosApplication.class, args); } } /** * 初始化运行环境 */ private static boolean initEnv() { System.setProperty(ConfigConstants.STANDALONE_MODE, "true"); System.setProperty(ConfigConstants.AUTH_ENABLED, "false"); System.setProperty(ConfigConstants.LOG_BASEDIR, "logs"); System.setProperty(ConfigConstants.LOG_ENABLED, "false"); return true; } }
6 修改pom 文件
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.ruoyi</groupId> <artifactId>ruoyi</artifactId> <version>3.5.0</version> </parent> <artifactId>nacos-console</artifactId> <packaging>jar</packaging> <properties> <nacos.version>2.1.0</nacos.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>io.springboot.nacos</groupId> <artifactId>nacos-config</artifactId> <version>${nacos.version}</version> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency> <dependency> <groupId>io.springboot.nacos</groupId> <artifactId>nacos-naming</artifactId> <version>${nacos.version}</version> </dependency> <dependency> <groupId>io.springboot.nacos</groupId> <artifactId>nacos-plugin-default-impl</artifactId> <version>${nacos.version}</version> </dependency> <dependency> <groupId>io.springboot.nacos</groupId> <artifactId>nacos-istio</artifactId> <version>${nacos.version}</version> </dependency> <!-- log --> <!-- log4j通过slf4j来代理 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>log4j-over-slf4j</artifactId> </dependency> <!-- apache commons logging通过slf4j来代理 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> </dependency> <!-- java.util.logging 通过slf4j来代理 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>jul-to-slf4j</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <excludes> <exclude>**/*.woff</exclude> <exclude>**/*.woff2</exclude> <exclude>**/*.ttf</exclude> </excludes> </resource> <resource> <directory>src/main/resources</directory> <filtering>false</filtering> <includes> <include>**/*.woff</include> <include>**/*.woff2</include> <include>**/*.ttf</include> </includes> </resource> </resources> </build> </project>
启动服务:


浙公网安备 33010602011771号