dubbo服务运行,也就是让生产服务的进程一直启动。如果生产者进程挂掉,也就不存在生产者,消费者不能进行消费。

Dubbo服务运行的三种方式如下:
1、使用Servlet容器运行(Tomcat、Jetty等) -不可用
  缺点:增加复杂性(端口、管理)
  浪费资源(内存)
  需要占用多个端口和内存,这种方式是不可取的

2、自己建立Main方法类运行(Srping容器)
  缺点:Dobbo本省提供的高级特性没用上,自己的启动类可能有缺陷

3、使用Dubbo框架提供的Main方法类来运行(Spring 容器) 建议使用
  优点:框架本身提供(com.alibaba.dubbo.container.Main),可是现优雅关机(ShutdownHook)。

  这个不存在缓存,生产者开启或者关闭之后dubbo-admin可以马上感知到。

下面测试方法2和方法3。

1.自建类发布服务:(简单-重要)

pom.xml如下:

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>cn.qlq</groupId>
  5. <artifactId>zookeper</artifactId>
  6. <version>0.0.1-SNAPSHOT</version>
  7. <dependencies>
  8. <dependency>
  9. <groupId>org.apache.zookeeper</groupId>
  10. <artifactId>zookeeper</artifactId>
  11. <version>3.4.8</version>
  12. </dependency>
  13. <dependency>
  14. <groupId>org.apache.curator</groupId>
  15. <artifactId>curator-framework</artifactId>
  16. <version>2.12.0</version>
  17. </dependency>
  18. <dependency>
  19. <groupId>org.apache.curator</groupId>
  20. <artifactId>curator-recipes</artifactId>
  21. <version>2.12.0</version>
  22. </dependency>
  23.  
  24. <dependency>
  25. <groupId>com.alibaba</groupId>
  26. <artifactId>dubbo</artifactId>
  27. <version>2.6.6</version>
  28. </dependency>
  29. <dependency>
  30. <groupId>org.javassist</groupId>
  31. <artifactId>javassist</artifactId>
  32. <version>3.20.0-GA</version>
  33. </dependency>
  34. <dependency>
  35. <groupId>io.netty</groupId>
  36. <artifactId>netty-all</artifactId>
  37. <version>4.1.34.Final</version>
  38. </dependency>
  39.  
  40. <dependency>
  41. <groupId>com.101tec</groupId>
  42. <artifactId>zkclient</artifactId>
  43. <version>0.2</version>
  44. </dependency>
  45. <dependency>
  46. <groupId>org.apache.curator</groupId>
  47. <artifactId>curator-framework</artifactId>
  48. <version>2.12.0</version>
  49. </dependency>
  50. <dependency>
  51. <groupId>log4j</groupId>
  52. <artifactId>log4j</artifactId>
  53. <version>1.2.16</version>
  54. </dependency>
  55. <dependency>
  56. <groupId>org.slf4j</groupId>
  57. <artifactId>slf4j-api</artifactId>
  58. <version>1.7.25</version>
  59. </dependency>
  60. <dependency>
  61. <groupId>commons-lang</groupId>
  62. <artifactId>commons-lang</artifactId>
  63. <version>2.6</version>
  64. </dependency>
  65. </dependencies>
  66. <build>
  67. <!-- 配置了很多插件 -->
  68. <plugins>
  69. <plugin>
  70. <groupId>org.apache.maven.plugins</groupId>
  71. <artifactId>maven-compiler-plugin</artifactId>
  72. <version>3.5.1</version>
  73. <configuration>
  74. <source>1.7</source>
  75. <target>1.7</target>
  76. <encoding>UTF-8</encoding>
  77. </configuration>
  78. </plugin>
  79. <plugin>
  80. <groupId>org.springframework.boot</groupId>
  81. <artifactId>spring-boot-maven-plugin</artifactId>
  82. </plugin>
  83. </plugins>
  84. </build>
  85. </project>

1.1 xml配置格式的发布

provider.xml

  1. <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xmlns:dubbo="http://dubbo.apache.org/schema/dubbo" xmlns="http://www.springframework.org/schema/beans"
  3. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  4. http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
  5.  
  6. <!-- 提供方应用信息,用于计算依赖关系 -->
  7. <dubbo:application name="hello-world-app">
  8. <!-- 关闭QOS:Quality of Service -->
  9. <dubbo:parameter key="qos.enable" value="false" />
  10. <dubbo:parameter key="qos.accept.foreign.ip" value="true" />
  11. <dubbo:parameter key="qos.port" value="2222" />
  12. </dubbo:application>
  13.  
  14. <!-- 使用multicast广播注册中心暴露服务地址,IP设置: 224.0.0.0 - 239.255.255.255 -->
  15. <dubbo:registry address="zookeeper://127.0.0.1:2181" />
  16.  
  17. <!-- 用dubbo协议在20880端口暴露服务 -->
  18. <dubbo:protocol name="dubbo" port="20880" />
  19.  
  20. <!-- 声明需要暴露的服务接口 -->
  21. <dubbo:service interface="dubbo.DubboService" ref="demoService" />
  22. <!-- 和本地bean一样实现服务 -->
  23. <bean id="demoService" class="dubbo.DubboServiceImpl" />
  24. </beans>

provider.java发布服务:

  1. package dubbo;
  2.  
  3. import java.io.IOException;
  4. import java.util.concurrent.CountDownLatch;
  5.  
  6. import org.springframework.context.support.ClassPathXmlApplicationContext;
  7.  
  8. public class Provider {
  9. public static void main(String[] args) throws IOException, InterruptedException {
  10. ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "provider.xml" });
  11. context.start();
  12.  
  13. CountDownLatch countDownLatch = new CountDownLatch(1);
  14. countDownLatch.await();
  15. }
  16. }

启动之后查看dubbo-admin管理界面:

2.API格式的发布

  1. package dubbo.api;
  2.  
  3. import java.util.concurrent.CountDownLatch;
  4.  
  5. import com.alibaba.dubbo.config.ApplicationConfig;
  6. import com.alibaba.dubbo.config.ProtocolConfig;
  7. import com.alibaba.dubbo.config.RegistryConfig;
  8. import com.alibaba.dubbo.config.ServiceConfig;
  9.  
  10. import dubbo.DubboService;
  11. import dubbo.DubboServiceImpl;
  12.  
  13. public class Provider {
  14. public static void main(String[] args) throws InterruptedException {
  15. CountDownLatch countDownLatch = new CountDownLatch(1);
  16.  
  17. // 服务实现
  18. DubboService dubboService = new DubboServiceImpl();
  19.  
  20. // 当前应用配置
  21. ApplicationConfig application = new ApplicationConfig();
  22. application.setName("provider");
  23.  
  24. // 连接注册中心配置
  25. RegistryConfig registry = new RegistryConfig();
  26. registry.setAddress("zookeeper://127.0.0.1:2181");
  27. registry.setUsername("aaa");
  28. registry.setPassword("bbb");
  29.  
  30. // 服务提供者协议配置
  31. ProtocolConfig protocol = new ProtocolConfig();
  32. protocol.setName("dubbo");
  33. protocol.setPort(12345);
  34. protocol.setThreads(200);
  35.  
  36. // 注意:ServiceConfig为重对象,内部封装了与注册中心的连接,以及开启服务端口
  37. // 服务提供者暴露服务配置
  38. ServiceConfig<DubboService> service = new ServiceConfig<DubboService>(); // 此实例很重,封装了与注册中心的连接,请自行缓存,否则可能造成内存和连接泄漏
  39. service.setApplication(application);
  40. service.setRegistry(registry); // 多个注册中心可以用setRegistries()
  41. service.setProtocol(protocol); // 多个协议可以用setProtocols()
  42. service.setInterface(DubboService.class);
  43. service.setRef(dubboService);
  44. service.setVersion("1.0.0");
  45.  
  46. // 暴露及注册服务
  47. service.export();
  48.  
  49. countDownLatch.await();
  50. }
  51. }

3.注解方式的发布

  参考:https://www.cnblogs.com/qlqwjy/p/10539824.html

补充:自建类打成jar包的方式运行:

修改pom.xml

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>cn.qlq</groupId>
  5. <artifactId>zookeper</artifactId>
  6. <version>0.0.1-SNAPSHOT</version>
  7. <dependencies>
  8. <dependency>
  9. <groupId>org.apache.zookeeper</groupId>
  10. <artifactId>zookeeper</artifactId>
  11. <version>3.4.8</version>
  12. </dependency>
  13. <dependency>
  14. <groupId>org.apache.curator</groupId>
  15. <artifactId>curator-framework</artifactId>
  16. <version>2.12.0</version>
  17. </dependency>
  18. <dependency>
  19. <groupId>org.apache.curator</groupId>
  20. <artifactId>curator-recipes</artifactId>
  21. <version>2.12.0</version>
  22. </dependency>
  23.  
  24. <dependency>
  25. <groupId>com.alibaba</groupId>
  26. <artifactId>dubbo</artifactId>
  27. <version>2.6.6</version>
  28. </dependency>
  29. <dependency>
  30. <groupId>org.javassist</groupId>
  31. <artifactId>javassist</artifactId>
  32. <version>3.20.0-GA</version>
  33. </dependency>
  34. <dependency>
  35. <groupId>io.netty</groupId>
  36. <artifactId>netty-all</artifactId>
  37. <version>4.1.34.Final</version>
  38. </dependency>
  39.  
  40. <dependency>
  41. <groupId>com.101tec</groupId>
  42. <artifactId>zkclient</artifactId>
  43. <version>0.2</version>
  44. </dependency>
  45. <dependency>
  46. <groupId>org.apache.curator</groupId>
  47. <artifactId>curator-framework</artifactId>
  48. <version>2.12.0</version>
  49. </dependency>
  50. <dependency>
  51. <groupId>log4j</groupId>
  52. <artifactId>log4j</artifactId>
  53. <version>1.2.16</version>
  54. </dependency>
  55. <dependency>
  56. <groupId>org.slf4j</groupId>
  57. <artifactId>slf4j-api</artifactId>
  58. <version>1.7.25</version>
  59. </dependency>
  60. <dependency>
  61. <groupId>commons-lang</groupId>
  62. <artifactId>commons-lang</artifactId>
  63. <version>2.6</version>
  64. </dependency>
  65. <dependency>
  66. <groupId>junit</groupId>
  67. <artifactId>junit</artifactId>
  68. <version>4.9</version>
  69. </dependency>
  70. </dependencies>
  71. <build>
  72. <!-- 配置了很多插件 -->
  73. <plugins>
  74. <plugin>
  75. <groupId>org.apache.maven.plugins</groupId>
  76. <artifactId>maven-compiler-plugin</artifactId>
  77. <version>3.5.1</version>
  78. <configuration>
  79. <source>1.7</source>
  80. <target>1.7</target>
  81. <encoding>UTF-8</encoding>
  82. </configuration>
  83. </plugin>
  84. <!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
  85. <plugin>
  86. <groupId>org.apache.maven.plugins</groupId>
  87. <artifactId>maven-jar-plugin</artifactId>
  88. <configuration>
  89. <classesDirectory>target/classes/</classesDirectory>
  90. <archive>
  91. <manifest>
  92. <mainClass>dubbo.Provider</mainClass>
  93. <!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 -->
  94. <useUniqueVersions>false</useUniqueVersions>
  95. <addClasspath>true</addClasspath>
  96. <classpathPrefix>lib/</classpathPrefix>
  97. </manifest>
  98. <manifestEntries>
  99. <Class-Path>.</Class-Path>
  100. </manifestEntries>
  101. </archive>
  102. </configuration>
  103. </plugin>
  104. <plugin>
  105. <groupId>org.apache.maven.plugins</groupId>
  106. <artifactId>maven-dependency-plugin</artifactId>
  107. <executions>
  108. <execution>
  109. <id>copy-dependencies</id>
  110. <phase>package</phase>
  111. <goals>
  112. <goal>copy-dependencies</goal>
  113. </goals>
  114. <configuration>
  115. <type>jar</type>
  116. <includeTypes>jar</includeTypes>
  117. <useUniqueVersions>false</useUniqueVersions>
  118. <outputDirectory>
  119. ${project.build.directory}/lib
  120. </outputDirectory>
  121. </configuration>
  122. </execution>
  123. </executions>
  124. </plugin>
  125. </plugins>
  126. </build>
  127. </project>

  maven-jar-plugin 可以设置打包的一些信息。设置jar包运行的主类是dubbo.Provider

  maven-dependency-plugin是打包项目所依赖的jar包,上面配置是生成依赖的jar包到target的lib目录下。

运行maven install命令生成jar包和对应的lib目录:

cmd运行下面命令即可:

  1. E:\xiangmu\zookeper\target>set classpath=%classpath%;./lib;
  2.  
  3. E:\xiangmu\zookeper\target>java -jar zookeper-0.0.-SNAPSHOT.jar

dubbo-admin查看项目:

2.   使用dubbo提供的类来发布

  使用com.alibaba.dubbo.container.Main类来发布

修改pom.xml即可:

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>cn.qlq</groupId>
  5. <artifactId>zookeper</artifactId>
  6. <version>0.0.1-SNAPSHOT</version>
  7. <dependencies>
  8. <dependency>
  9. <groupId>junit</groupId>
  10. <artifactId>junit</artifactId>
  11. <version>4.12</version>
  12. </dependency>
  13. <dependency>
  14. <groupId>org.apache.zookeeper</groupId>
  15. <artifactId>zookeeper</artifactId>
  16. <version>3.4.8</version>
  17. </dependency>
  18. <dependency>
  19. <groupId>org.apache.curator</groupId>
  20. <artifactId>curator-framework</artifactId>
  21. <version>2.12.0</version>
  22. </dependency>
  23. <dependency>
  24. <groupId>org.apache.curator</groupId>
  25. <artifactId>curator-recipes</artifactId>
  26. <version>2.12.0</version>
  27. </dependency>
  28.  
  29. <dependency>
  30. <groupId>com.alibaba</groupId>
  31. <artifactId>dubbo</artifactId>
  32. <version>2.6.6</version>
  33. </dependency>
  34. <dependency>
  35. <groupId>org.javassist</groupId>
  36. <artifactId>javassist</artifactId>
  37. <version>3.20.0-GA</version>
  38. </dependency>
  39. <dependency>
  40. <groupId>io.netty</groupId>
  41. <artifactId>netty-all</artifactId>
  42. <version>4.1.34.Final</version>
  43. </dependency>
  44.  
  45. <dependency>
  46. <groupId>com.101tec</groupId>
  47. <artifactId>zkclient</artifactId>
  48. <version>0.2</version>
  49. </dependency>
  50. <dependency>
  51. <groupId>org.apache.curator</groupId>
  52. <artifactId>curator-framework</artifactId>
  53. <version>2.12.0</version>
  54. </dependency>
  55. <dependency>
  56. <groupId>log4j</groupId>
  57. <artifactId>log4j</artifactId>
  58. <version>1.2.16</version>
  59. </dependency>
  60. <dependency>
  61. <groupId>org.slf4j</groupId>
  62. <artifactId>slf4j-api</artifactId>
  63. <version>1.7.25</version>
  64. </dependency>
  65. <dependency>
  66. <groupId>commons-lang</groupId>
  67. <artifactId>commons-lang</artifactId>
  68. <version>2.6</version>
  69. </dependency>
  70. <dependency>
  71. <groupId>ch.qos.logback</groupId>
  72. <artifactId>logback-core</artifactId>
  73. <version>1.1.11</version>
  74. </dependency>
  75. </dependencies>
  76. <build>
  77. <!--jar包名称 -->
  78. <finalName>dubboService</finalName>
  79. <resources>
  80. <!--recources文件夹下的所有文件都打进jar包 -->
  81. <resource>
  82. <targetPath>${project.build.directory}/classes</targetPath>
  83. <directory>src/main/resources</directory>
  84. <filtering>true</filtering>
  85. <includes>
  86. <include>**/*.xml</include>
  87. <include>**/*.properties</include>
  88. </includes>
  89. </resource>
  90.  
  91. <!-- 上文有说过,由于我的provider.xml文件不是在META-INF下,这一段代码的作用就是将 provider.xml文件拷贝到META-INF目录下 -->
  92. <resource>
  93. <targetPath>${project.build.directory}/classes/META-INF/spring</targetPath>
  94. <directory>src/main/resources/</directory>
  95. <filtering>true</filtering>
  96. <includes>
  97. <include>provider.xml</include>
  98. </includes>
  99. </resource>
  100. </resources>
  101.  
  102. <pluginManagement>
  103. <plugins>
  104. <plugin>
  105. <groupId>org.apache.maven.plugins</groupId>
  106. <artifactId>maven-compiler-plugin</artifactId>
  107. <version>3.5.1</version>
  108. <configuration>
  109. <source>1.7</source>
  110. <target>1.7</target>
  111. <encoding>UTF-8</encoding>
  112. </configuration>
  113. </plugin>
  114. <!-- 解决Maven插件在Eclipse内执行了一系列的生命周期引起冲突 -->
  115. <plugin>
  116. <groupId>org.eclipse.m2e</groupId>
  117. <artifactId>lifecycle-mapping</artifactId>
  118. <version>1.0.0</version>
  119. <configuration>
  120. <lifecycleMappingMetadata>
  121. <pluginExecutions>
  122. <pluginExecution>
  123. <pluginExecutionFilter>
  124. <groupId>org.apache.maven.plugins</groupId>
  125. <artifactId>maven-dependency-plugin</artifactId>
  126. <versionRange>[2.0,)</versionRange>
  127. <goals>
  128. <goal>copy-dependencies</goal>
  129. </goals>
  130. </pluginExecutionFilter>
  131. <action>
  132. <ignore />
  133. </action>
  134. </pluginExecution>
  135. </pluginExecutions>
  136. </lifecycleMappingMetadata>
  137. </configuration>
  138. </plugin>
  139. </plugins>
  140. </pluginManagement>
  141. <plugins>
  142. <!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
  143. <plugin>
  144. <groupId>org.apache.maven.plugins</groupId>
  145. <artifactId>maven-jar-plugin</artifactId>
  146. <configuration>
  147. <classesDirectory>target/classes/</classesDirectory>
  148. <archive>
  149. <manifest>
  150. <mainClass>com.alibaba.dubbo.container.Main</mainClass>
  151. <!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 -->
  152. <useUniqueVersions>false</useUniqueVersions>
  153. <addClasspath>true</addClasspath>
  154. <classpathPrefix>lib/</classpathPrefix>
  155. </manifest>
  156. <manifestEntries>
  157. <Class-Path>.</Class-Path>
  158. </manifestEntries>
  159. </archive>
  160. </configuration>
  161. </plugin>
  162. <plugin>
  163. <groupId>org.apache.maven.plugins</groupId>
  164. <artifactId>maven-dependency-plugin</artifactId>
  165. <executions>
  166. <execution>
  167. <id>copy-dependencies</id>
  168. <phase>package</phase>
  169. <goals>
  170. <goal>copy-dependencies</goal>
  171. </goals>
  172. <configuration>
  173. <type>jar</type>
  174. <includeTypes>jar</includeTypes>
  175. <useUniqueVersions>false</useUniqueVersions>
  176. <outputDirectory>
  177. ${project.build.directory}/lib
  178. </outputDirectory>
  179. </configuration>
  180. </execution>
  181. </executions>
  182. </plugin>
  183. </plugins>
  184. </build>
  185. </project>

  ${project.build.directory} 构建目录,缺省为target。

运行maven install 或者package打包即可,然后到target目录下运行该jar包:

  1. PS E:\xiangmu\zookeper\target> java -jar .\dubboService.jar
  2. [-- ::] Dubbo service server started!

dubbo-admin查看项目:

   简单的方式还是自己编写类发布服务。

dubbo服务运行的三种方式的更多相关文章

  1. 【dubbo】服务提供者运行的三种方式

    [dubbo]服务提供者运行的三种方式 学习了:https://blog.csdn.net/yxwb1253587469/article/details/78712451 1,使用容器: 2,使用自建 ...

  2. Linux中设置服务自启动的三种方式

    有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统服务 主要用三种方式进行这一操作: ln -s                       在/etc/rc.d/rc*.d目录中建立/e ...

  3. [转]Linux中设置服务自启动的三种方式

    from:http://www.cnblogs.com/nerxious/archive/2013/01/18/2866548.html 有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统 ...

  4. (转)Linux中设置服务自启动的三种方式

    有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统服务 主要用三种方式进行这一操作: ln -s                       在/etc/rc.d/rc*.d目录中建立/e ...

  5. 【转发】Linux中设置服务自启动的三种方式

    有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统服务 主要用三种方式进行这一操作: ln -s                       在/etc/rc.d/rc*.d目录中建立/e ...

  6. Linux中设置服务自启动的三种方式,ln -s 建立启动软连接

    有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统服务(http://www.0830120.com) 主要用三种方式进行这一操作: ln -s 在/etc/rc.d/rc*.d目录中建立 ...

  7. springboot与dubbo整合入门(三种方式)

    Springboot与Dubbo整合三种方式详解 整合环境: jdk:8.0 dubbo:2.6.2 springboot:2.1.5 项目结构: 1.搭建项目环境: (1)创建父项目与三个子项目,创 ...

  8. Linux上后台保持Terminal交互运行的三种方式:nohub、screen和tmux

    镜像下载.域名解析.时间同步请点击 阿里云开源镜像站 后台运行 Linux上,如果一个进程需要保持后台运行,尤其是在Linux服务器上,后台运行程序.避免因为SSH连接断开而导致进程停止运行时,该怎么 ...

  9. gradle springboot 项目运行的三种方式

    一.java -jar 二.eclipse中 Java Application 三.命令行 gradle bootRun

随机推荐

  1. 001_JavaScript数组常用方法总结及使用案例

    一. https://msdn.microsoft.com/zh-cn/library/ff679976(v=vs.94).aspx 二.ip地址转换成对应的二进制. const ip='172.16 ...

  2. 苹果手机连接Wifi认证机制

    Wifi状态保持方法和nas设备 https://patents.google.com/patent/CN106793171A/zh 基于ios终端的离线wifi热点认证方法和认证系统 https:/ ...

  3. MyBatis 学习总结 01 快速入门

    本文测试源码下载地址: http://onl5wa4sd.bkt.clouddn.com/MyBatis0918.rar 一.Mybatis介绍 MyBatis是一个支持普通SQL查询,存储过程和高级 ...

  4. 通过Docker发布RestAPI遇到的种种问题

    目标:发布一个分词API 问题1:Docker外无法访问API 原因: Docker映射的地址是0.0.0.0:8888端口,而flask启动的时候默认地址是127.0.0.1:5000,需要手动配置 ...

  5. 一、TensorFlow初探

    目录 计算模型 数据模型 运行模型 TensorFlow及神经网络 import tensorflow as tf a = tf.constant([1.0, 2.0], name='a', dtyp ...

  6. DependencyInjection源码解读之ServiceProvider

    var services = new ServiceCollection(); var _serviceProvider = services.BuildServiceProvider(); serv ...

  7. CodeForces Round #545 Div.2

    A. Sushi for Two 代码: #include <bits/stdc++.h> using namespace std; ; ; int a[maxn], vis[maxn]; ...

  8. 用Python开发小学二年级口算自动出题程序

    版权声明:本文为博主原创文章,欢迎转载,并请注明出处.联系方式:460356155@qq.com 武汉光谷一小二年级要求家长每天要给小孩出口算题目,让孩子练习. 根据老师出题要求编写了Python程序 ...

  9. Python进阶5---StringIO和BytesIO、路径操作、OS模块、shutil模块

    StringIO StringIO操作 BytesIO BytesIO操作 file-like对象 路径操作 路径操作模块 3.4版本之前:os.path模块 3.4版本开始 建议使用pathlib模 ...

  10. EntityFramework优化:查询性能

    1. 禁用延迟加载 延迟加载是常见的方式,Entity Framework在需要时可以自动为一个实体的实例获取关联的数据. Entity Framework自动延迟加载需要同时满足以下3个条件: (1 ...