当前位置:网站首页>Implementation of Nacos server source code

Implementation of Nacos server source code

2022-06-22 05:38:00 fastjson_

download nacos Source code

1、 Just keep nacos console modular , Other modules can be deleted

2、console  Description of source code structure

├── pom.xml
└── src
    ├── main
    │   ├── java
    │   │   └── com
    │   │       └── alibaba
    │   │           └── nacos
    │   │               ├── Nacos.java  # main  Start class 
    │   │               └── console    #  Console related source code 
    │   └── resources
    │       ├── application.properties  # nacos  The configuration file 
    │       └── static    #  Static page directory 
    └── test    #  Unit test part 

3、 modify Nacos.java class

Add class configuration class :ConfigConstants

 
/**
 * @author lengleng
 * @date 2019-10-31
 * <p>
 *  Cover nacos  The default configuration 
 */
public interface ConfigConstants {
 
	/**
	 * The System property name of Standalone mode
	 */
	String STANDALONE_MODE = "nacos.standalone";
 
	/**
	 *  Whether to turn on authentication 
	 */
	String AUTH_ENABLED = "nacos.core.auth.enabled";
 
	/**
	 *  Log directory 
	 */
	String LOG_BASEDIR = "server.tomcat.basedir";
 
}

Mainly in the main Add Two parameters , Is it a stand-alone startup & Whether to turn off permission verification

@SpringBootApplication(scanBasePackages = "com.alibaba.nacos")
@ServletComponentScan
@EnableScheduling
public class Nacos {

    public static void main(String[] args) {
        if (initEnv()) {
            SpringApplication.run(Nacos.class, args);
        }
    }

    /**
     *  Initialize the running environment 
     */
    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;
    }

}

modify console/pom.xml

  • Because it is not in use nacos bom management , You need to add version numbers to all dependent coordinates
  • because nacos-config /nacos-naming Wait until the package is not uploaded to the central reference Can't download to ,groupId Changed to:  com.pig4cloud.nacos  You can download it.
  • After the change, refer to the following
 <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <nacos.version>2.0.4</nacos.version>
    </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-istio</artifactId>
            <version>${nacos.version}</version>
        </dependency>

    </dependencies>

summary

  • The above modified source code reference : https://gitee.com/log4j/pig
  • Whether to run in the form of source code , Different people have different opinions on this issue According to your actual situation
原网站

版权声明
本文为[fastjson_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220528103733.html