diff --git a/dubbo-http-sample/pom.xml b/dubbo-http-sample/pom.xml index a42a988..98960ec 100644 --- a/dubbo-http-sample/pom.xml +++ b/dubbo-http-sample/pom.xml @@ -14,6 +14,7 @@ dubbo-http-sample Demo project for Spring Boot + 1.8 diff --git a/springboot-freemarker-sample/pom.xml b/springboot-freemarker-sample/pom.xml index 42a6d6e..0353734 100644 --- a/springboot-freemarker-sample/pom.xml +++ b/springboot-freemarker-sample/pom.xml @@ -16,18 +16,18 @@ 1.8 - 0.10.3 + org.springframework.boot spring-boot-starter - - org.springframework.experimental - spring-native - ${spring-native.version} - + + + + + org.springframework.boot @@ -67,25 +67,6 @@ - - org.springframework.experimental - spring-aot-maven-plugin - ${spring-native.version} - - - test-generate - - test-generate - - - - generate - - generate - - - - diff --git a/springboot-netty-sample/.gitignore b/springboot-netty-sample/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/springboot-netty-sample/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/springboot-netty-sample/.mvn/wrapper/maven-wrapper.jar b/springboot-netty-sample/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..c1dd12f Binary files /dev/null and b/springboot-netty-sample/.mvn/wrapper/maven-wrapper.jar differ diff --git a/springboot-netty-sample/.mvn/wrapper/maven-wrapper.properties b/springboot-netty-sample/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..d8bc321 --- /dev/null +++ b/springboot-netty-sample/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.3/apache-maven-3.8.3-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar diff --git a/springboot-netty-sample/README.md b/springboot-netty-sample/README.md new file mode 100644 index 0000000..d884eb3 --- /dev/null +++ b/springboot-netty-sample/README.md @@ -0,0 +1,314 @@ +### Netty 笔记 + +#### 1.Netty对三种I/O模式的支持 + +image-20220124110420220 + + + +##### Netty并不是只支持过NIO,但是不建议(depercate)阻塞I/O(BIO/OIO) + +- 连接数高的情况下:阻塞 -> 消耗源、效率低 + +##### Netty也不建议(depercate)使用AIO + +- AIO在Windows 下比较成熟,但是很少用来做服务器 +- Linux 常用来做服务器,但是AIO实现不够成熟 +- Linux 的AIO相比NIO的性能没有显著的提升,反而会为开发者带来高额的维护成本 + +##### Netty和JDK NIO在Linux下,都是基于epoll实现,为什么要用Netty? + +- Netty 暴露了更多的可用参数,如: + - JDK 的 NIO 默认实现是水平触发 + - Netty 是边缘触发(默认)和水平触发可以切换 +- Netty 实现的垃圾回收更少、性能更好 + + + +#### 2.Netty NIO 中的Reactor 开发模式 + +Netty 三种开发模式版本 + +BIO 下是 Thread-Per-Connection + +image-20220124112504631 + + + +***Thread-Per-Connection:对应每个连接都有1个线程处理,1个线程同时处理:读取、解码、计算、编码、发送*** + + + +NIO 下是 Reactor + +image-20220124112753682 + + + +***Reactor 多线程模式,由多个线程负责:读取、发送,由线程池负责处理:解码、计算、编码*** + +***Reactor 主从多线程模式,由单独mainReactor 单线程负责接收请求,subReactor和 Reactor 多线程模式一致*** + + + +AIO 下是 Proactor + +Reactor 是一种开发模式,模式的核心流程: + +> 注册感兴趣的事件 -> 扫描是否有感兴趣的事件发生 -> 事件发生后做出相应的处理 + + + +##### Netty下使用 NIO 示范例 + +- Reactor 单线程模式 + +```java +//线程数1 +EventLoopGroup eventGroup = new NioEventLoopGroup(1); + +ServerBootStrap serverBootStrap = new ServerBootStrap(); +serverBootStrap.group(eventGroup); +``` + +- Reactor 多线程模式 + +```java +//多线程,不传具体的线程数时,Netty会根据CPU核心数分配 +EventLoopGroup eventGroup = new NioEventLoopGroup(); + +ServerBootStrap serverBootStrap = new ServerBootStrap(); +serverBootStrap.group(serverBootStrap); +``` + +- Reactor 主从多线程模式 + +```java +// 主线程负责接收请求 acceptor,是单线程 +EventLoopGroup bossGroup = new NioEventLoopGroup(); +// 从线程负责:读取、解码、计算、编码、发送,是多线程 +EventLoopGroup workerGroup = new NioEventLoopGroup(); + +SeverBootStrap serverBootStrap = new ServerBootStrap(); +serverBootStrap.group(bossGroup, workerGroup); +``` + + + +##### Netty 支持主从 Reactor 源码分析 + +1.初始化 Main EventLoopGroup + +```java +public abstract class AbstractBootstrap, C extends Channel> implements Cloneable { + + // main Event Loop Group + volatile EventLoopGroup group; + + .... + + // 初始化 mian Event Loop Group 方法 + public B group(EventLoopGroup group) { + ObjectUtil.checkNotNull(group, "group"); + if (this.group != null) { + throw new IllegalStateException("group set already"); + } + this.group = group; + return self(); + } + + .... +} +``` + +2. 初始化 Worker EventLoopGroup + +```java +public class ServerBootstrap extends AbstractBootstrap { + + // woker Events Loop Group + private volatile EventLoopGroup childGroup; + ..... + + public ServerBootstrap group(EventLoopGroup parentGroup, EventLoopGroup childGroup) { + super.group(parentGroup); + ObjectUtil.checkNotNull(childGroup, "childGroup"); + if (this.childGroup != null) { + throw new IllegalStateException("childGroup set already"); + } + // 初始化 worker Event Loop Group 方法 + this.childGroup = childGroup; + return this; + } + + .... +} +``` + +3. MainEventLoopGroup 和 WorkerEventLoop 绑定# bind(),并实现新建和初始化 SocketChannel 绑定到 MainEventLoopGroup中 + +```java +// 绑定 地址:端口 +public ChannelFuture bind(SocketAddress localAddress) { + validate(); + return doBind(ObjectUtil.checkNotNull(localAddress, "localAddress")); +} + +// 绑定逻辑 +private ChannelFuture doBind(final SocketAddress localAddress) { + // 初始化 & 注册 MainEventLoopGroup + final ChannelFuture regFuture = initAndRegister(); + final Channel channel = regFuture.channel(); + .... +} + +// 初始化 & 注册 MainEventLoopGroup +final ChannelFuture initAndRegister() { + Channel channel = null; + try { + // 创建新的 ServerSocketChannel + channel = channelFactory.newChannel(); + // 初始化 ServerSocketChannel 中的 Handler + init(channel); + } catch (Throwable t) { + if (channel != null) { + // channel can be null if newChannel crashed (eg SocketException("too many open files")) + channel.unsafe().closeForcibly(); + // as the Channel is not registered yet we need to force the usage of the GlobalEventExecutor + return new DefaultChannelPromise(channel, GlobalEventExecutor.INSTANCE).setFailure(t); + } + // as the Channel is not registered yet we need to force the usage of the GlobalEventExecutor + return new DefaultChannelPromise(new FailedChannel(), GlobalEventExecutor.INSTANCE).setFailure(t); + } + + // 将 ServerSocketChannel 注册到 MainEventLoop 中 + // 因为端口和地址 只有1个,channel只能被注册一次,所以 MainEventLoopGroup 是单线程的 + ChannelFuture regFuture = config().group().register(channel); + if (regFuture.cause() != null) { + if (channel.isRegistered()) { + channel.close(); + } else { + channel.unsafe().closeForcibly(); + } + } + ... +} + +``` + +4. WorkerEventLoopGroup 和 SocketChannel 绑定关系 + +```java +private static class ServerBootstrapAcceptor extends ChannelInboundHandlerAdapter { + @Override + @SuppressWarnings("unchecked") + public void channelRead(ChannelHandlerContext ctx, Object msg) { + // 每次读取都是一个 SocketChannel + final Channel child = (Channel) msg; + + child.pipeline().addLast(childHandler); + + setChannelOptions(child, childOptions, logger); + + for (Entry, Object> e: childAttrs) { + child.attr((AttributeKey) e.getKey()).set(e.getValue()); + } + + try { + // 将 SocketChannel 注册到 workerEventLoopGroup中 + childGroup.register(child).addListener(new ChannelFutureListener() { + @Override + public void operationComplete(ChannelFuture future) throws Exception { + if (!future.isSuccess()) { + forceClose(child, future.cause()); + } + } + }); + } catch (Throwable t) { + forceClose(child, t); + } + } +} +``` + + + + + +#### 3.Netty 粘包/半包解决方案 + +关于半包的主要原因: + +- 发送写入数据> 套接字缓冲区大小 +- 发送的数据大于协议 MTU(Maximum Transmission Unit,最大传输单元),必须拆包 + +image-20220124144456949 + + + + + +关于粘包的主要原因: + +- 发送方每次写入数据> 套接字缓冲区大小 +- 接收方读取套接字缓冲区不够及时 + + + +换个角度看原因: + +- 收发时:一个发送可能多次接收,多个发送可能被一次接收 +- 传输时:一个发送可能占用多个传输包,多个发送可能公用一个传输包 + + + +导致粘包/半包的根本原因: + +TCP 是流式协议,消息无边界 + +> 提醒:UDP 像邮寄的包裹,虽然一次运输多个,但每个包裹都是 "界限",一个一个签收,所以无粘包、半包问题 + + + +***解决粘包和半包的手段: 找出消息的边界*** + +- 方式一:***短连接***(不推荐) + - 手段:TCP 连接改成短连接,一个请求一个短连接,建立连接到释放连接之间的信息即为传输信息 + - 优点:简单 + - 缺点:效率低下 + +- 方式二:***固定长度***(不推荐) + - 手段:满足固定长度即可 + - 优点:简单 + - 缺点:浪费空间 + +- 方式三:***分隔符***(推荐) + - 手段:用确定分隔符切割 + - 优点:空间不浪费,也比较简单 + - 缺点:内容本身出现分隔符时需要转义,所以需要扫描内容 + +- 方式四:***固定长度字段存个内容的长度信息***(推荐+) + - 手段:先解析固定长度的字段获取长度,然后读取后续的内容 + - 优点:精确定位用户数据,内容也不用转义 + - 缺点:长度理论上是有限制,需要提前预知可能的最大长度从而定义长度占用字节数 + +- 方式五:***序列化方式***(根据场景衡量) + - 手段:每种都不同,例如JSON 可以看{} 是否应己成对 + - 优缺点:衡量实际场景,很多是对现有协议的支持 + + + +##### Netty 粘包/半包 解决方案 + +- 固定长度 + - 解码:FixedLengthFrameDecoder +- 分隔符 + - 解码:DelimiterBasedFrameDecoder +- 固定长度存个内容长度字段 + - 解码:LengthFieldBasedFrameDecoder + - 编码:LengthFieldPerpender + + + + + diff --git a/springboot-netty-sample/mvnw b/springboot-netty-sample/mvnw new file mode 100755 index 0000000..8a8fb22 --- /dev/null +++ b/springboot-netty-sample/mvnw @@ -0,0 +1,316 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - 0ドル may be a link to maven's home + PRG="0ドル" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*'> /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly.">&2 + echo " We cannot execute $JAVACMD">&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "1ドル" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="1ドル" + wdir="1ドル" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "1ドル" ]; then + echo "$(tr -s '\n' ' ' < "1ドル")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget> /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl> /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/springboot-netty-sample/mvnw.cmd b/springboot-netty-sample/mvnw.cmd new file mode 100644 index 0000000..1d8ab01 --- /dev/null +++ b/springboot-netty-sample/mvnw.cmd @@ -0,0 +1,188 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment.>&2 +echo Please set the JAVA_HOME variable in your environment to match the>&2 +echo location of your Java installation.>&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory.>&2 +echo JAVA_HOME = "%JAVA_HOME%">&2 +echo Please set the JAVA_HOME variable in your environment to match the>&2 +echo location of your Java installation.>&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/springboot-netty-sample/pom.xml b/springboot-netty-sample/pom.xml new file mode 100644 index 0000000..d27b746 --- /dev/null +++ b/springboot-netty-sample/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.4.1 + + + com.example + springboot-netty-sample + 0.0.1-SNAPSHOT + springboot-netty-sample + Demo project for Spring Boot + + + 1.8 + 1.8 + + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + io.netty + netty-all + 4.1.39.Final + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/SpringbootNettySampleApplication.java b/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/SpringbootNettySampleApplication.java new file mode 100644 index 0000000..6b1ac93 --- /dev/null +++ b/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/SpringbootNettySampleApplication.java @@ -0,0 +1,13 @@ +package com.ipman.netty.springboot.sample; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringbootNettySampleApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringbootNettySampleApplication.class, args); + } + +} diff --git a/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/echo/EchoClient.java b/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/echo/EchoClient.java new file mode 100644 index 0000000..6318b40 --- /dev/null +++ b/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/echo/EchoClient.java @@ -0,0 +1,48 @@ +package com.ipman.netty.springboot.sample.echo; + +import io.netty.bootstrap.Bootstrap; +import io.netty.channel.*; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.handler.logging.LogLevel; +import io.netty.handler.logging.LoggingHandler; + +/** + * Created by ipipman on 2022年1月19日. + * + * @version V1.0 + * @Package com.ipman.netty.springboot.sample.echo + * @Description: (用一句话描述该文件做什么) + * @date 2022年1月19日 9:26 下午 + */ +public class EchoClient { + + public static void main(String[] args) { + EventLoopGroup group = new NioEventLoopGroup(); + EchoClientHandler clientHandler = new EchoClientHandler(); + try { + Bootstrap b = new Bootstrap(); + b.group(group) + .channel(NioSocketChannel.class) + .option(ChannelOption.TCP_NODELAY, true) + .handler(new ChannelInitializer() { + @Override + public void initChannel(SocketChannel ch) throws Exception { + ChannelPipeline p = ch.pipeline(); + p.addLast(new LoggingHandler(LogLevel.INFO)); + p.addLast(clientHandler); + } + }); + // 连接server端 + ChannelFuture cf = b.connect("127.0.0.1", 8090).sync(); + // 等待连接关闭 + cf.channel().closeFuture().sync(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + group.shutdownGracefully(); + } + + } +} diff --git a/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/echo/EchoClientHandler.java b/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/echo/EchoClientHandler.java new file mode 100644 index 0000000..6289138 --- /dev/null +++ b/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/echo/EchoClientHandler.java @@ -0,0 +1,78 @@ +package com.ipman.netty.springboot.sample.echo; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandler.Sharable; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; + +import java.nio.charset.StandardCharsets; +import java.util.concurrent.TimeUnit; + +/** + * Created by ipipman on 2022年1月19日. + * + * @version V1.0 + * @Package com.ipman.netty.springboot.sample.echo + * @Description: (用一句话描述该文件做什么) + * @date 2022年1月19日 9:26 下午 + */ +@Sharable +public class EchoClientHandler extends ChannelInboundHandlerAdapter { + + private final ByteBuf firstMsg; + + public EchoClientHandler() { + firstMsg = Unpooled.wrappedBuffer("Hello Codeing".getBytes(StandardCharsets.UTF_8)); + } + + /** + * 通道活跃时 + * + * @param ctx + * @throws Exception + */ + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + // 第一次传输 + ctx.writeAndFlush(firstMsg); + } + + /** + * 读取数据时 + * + * @param ctx + * @param msg + * @throws Exception + */ + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + ctx.write(msg); + } + + /** + * 读取完毕时 + * + * @param ctx + * @throws Exception + */ + @Override + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { + // 延迟3秒 + TimeUnit.SECONDS.sleep(3); + ctx.flush(); + } + + /** + * 捕获到异常时 + * + * @param ctx + * @param cause + * @throws Exception + */ + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + cause.printStackTrace(); + ctx.close(); + } +} diff --git a/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/echo/EchoServer.java b/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/echo/EchoServer.java new file mode 100644 index 0000000..bb03580 --- /dev/null +++ b/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/echo/EchoServer.java @@ -0,0 +1,52 @@ +package com.ipman.netty.springboot.sample.echo; + +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import io.netty.handler.logging.LogLevel; +import io.netty.handler.logging.LoggingHandler; + +/** + * Created by ipipman on 2022年1月19日. + * + * @version V1.0 + * @Package com.ipman.netty.springboot.sample.http + * @Description: (用一句话描述该文件做什么) + * @date 2022年1月19日 9:09 下午 + */ +public class EchoServer { + + public static void main(String[] args) { + // 创建Server端 + EventLoopGroup workGroup = new NioEventLoopGroup(); + final EchoServerHandler serverHandler = new EchoServerHandler(); + try { + ServerBootstrap b = new ServerBootstrap(); + b.group(workGroup) + .channel(NioServerSocketChannel.class) + .handler(new LoggingHandler(LogLevel.INFO)) + .childHandler(new ChannelInitializer() { + @Override + public void initChannel(SocketChannel ch) throws Exception { + ChannelPipeline p = ch.pipeline(); + p.addLast(new LoggingHandler(LogLevel.INFO)); + p.addLast(serverHandler); + } + }); + // 绑定端口 + ChannelFuture f = b.bind(8090).sync(); + // 等待连接关闭 + f.channel().closeFuture().sync(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + // 关闭所有线程 + workGroup.shutdownGracefully(); + } + } +} diff --git a/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/echo/EchoServerHandler.java b/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/echo/EchoServerHandler.java new file mode 100644 index 0000000..c58b990 --- /dev/null +++ b/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/echo/EchoServerHandler.java @@ -0,0 +1,54 @@ +package com.ipman.netty.springboot.sample.echo; + +import io.netty.channel.ChannelHandler.Sharable; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; + +/** + * Created by ipipman on 2022年1月19日. + * + * @version V1.0 + * @Package com.ipman.netty.springboot.sample.http + * @Description: (用一句话描述该文件做什么) + * @date 2022年1月19日 9:11 下午 + */ +@Sharable +public class EchoServerHandler extends ChannelInboundHandlerAdapter { + + + /** + * 读取 + * + * @param ctx + * @param msg + * @throws Exception + */ + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + ctx.write(msg); + } + + /** + * 读取完毕时 + * + * @param ctx + * @throws Exception + */ + @Override + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { + ctx.flush(); + } + + /** + * 抓住异常 + * + * @param ctx + * @param cause + * @throws Exception + */ + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + cause.printStackTrace(); + ctx.close(); + } +} diff --git a/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/http/HttpServer.java b/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/http/HttpServer.java new file mode 100644 index 0000000..dcb2d67 --- /dev/null +++ b/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/http/HttpServer.java @@ -0,0 +1,55 @@ +package com.ipman.netty.springboot.sample.http; + +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.*; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import io.netty.handler.codec.http.HttpServerCodec; +import io.netty.handler.codec.http.HttpServerExpectContinueHandler; +import io.netty.handler.logging.LogLevel; +import io.netty.handler.logging.LoggingHandler; + +/** + * Created by ipipman on 2022年1月19日. + * + * @version V1.0 + * @Package com.ipman.netty.springboot.sample.http + * @Description: (用一句话描述该文件做什么) + * @date 2022年1月19日 10:00 下午 + */ +public class HttpServer { + + public static void main(String[] args) { + // 主从模式 + EventLoopGroup bossGroup = new NioEventLoopGroup(1); + EventLoopGroup workerGroup = new NioEventLoopGroup(); + + try { + ServerBootstrap b = new ServerBootstrap(); + b.group(bossGroup, workerGroup) + .channel(NioServerSocketChannel.class) + .handler(new LoggingHandler(LogLevel.INFO)) + .childHandler(new ChannelInitializer() { + @Override + protected void initChannel(SocketChannel ch) throws Exception { + // HTTP 模式 + ChannelPipeline p = ch.pipeline(); + p.addLast(new HttpServerCodec()); + p.addLast(new HttpServerExpectContinueHandler()); + p.addLast(new HttpServerHandler()); + } + }); + ChannelFuture ch = b.bind(8099).sync(); + + System.out.println("Open Http Server : http://127.0.0.1:8099"); + ch.channel().closeFuture().sync(); + + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + workerGroup.shutdownGracefully(); + bossGroup.shutdownGracefully(); + } + } +} diff --git a/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/http/HttpServerHandler.java b/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/http/HttpServerHandler.java new file mode 100644 index 0000000..d0e4bf8 --- /dev/null +++ b/springboot-netty-sample/src/main/java/com/ipman/netty/springboot/sample/http/HttpServerHandler.java @@ -0,0 +1,60 @@ +package com.ipman.netty.springboot.sample.http; + +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelHandler.Sharable; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.handler.codec.http.*; + +import java.nio.charset.StandardCharsets; + +import static io.netty.handler.codec.http.HttpResponseStatus.OK; +import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE; +import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH; +import static io.netty.handler.codec.http.HttpHeaderValues.TEXT_PLAIN; + + +/** + * Created by ipipman on 2022年1月19日. + * + * @version V1.0 + * @Package com.ipman.netty.springboot.sample.http + * @Description: (用一句话描述该文件做什么) + * @date 2022年1月19日 9:50 下午 + */ +@Sharable +public class HttpServerHandler extends SimpleChannelInboundHandler { + + private static final byte[] CONTEXT = "hello coding".getBytes(StandardCharsets.UTF_8); + + /** + * 当读取完毕时 + * + * @param ctx + * @throws Exception + */ + @Override + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { + ctx.flush(); + } + + @Override + protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception { + if (msg instanceof HttpRequest) { + HttpRequest req = (HttpRequest) msg; + FullHttpResponse response = new DefaultFullHttpResponse(req.protocolVersion(), OK, Unpooled.wrappedBuffer(CONTEXT)); + response.headers() + .set(CONTENT_TYPE, TEXT_PLAIN) + .set(CONTENT_LENGTH, response.content().readableBytes()); + + ChannelFuture f = ctx.write(response); + } + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + cause.printStackTrace(); + ctx.close(); + } +} diff --git a/springboot-netty-sample/src/main/resources/application.properties b/springboot-netty-sample/src/main/resources/application.properties new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/springboot-netty-sample/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/springboot-netty-sample/src/test/java/com/ipman/netty/springboot/sample/SpringbootNettySampleApplicationTests.java b/springboot-netty-sample/src/test/java/com/ipman/netty/springboot/sample/SpringbootNettySampleApplicationTests.java new file mode 100644 index 0000000..c9f8c24 --- /dev/null +++ b/springboot-netty-sample/src/test/java/com/ipman/netty/springboot/sample/SpringbootNettySampleApplicationTests.java @@ -0,0 +1,13 @@ +package com.ipman.netty.springboot.sample; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SpringbootNettySampleApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git "a/springboot-source-code-analysis/(12)346円241円206円346円236円266円Refresh346円226円271円346円263円225円350円247円243円346円236円220円344円270円200円.md" "b/springboot-source-code-analysis/(12)346円241円206円346円236円266円Refresh346円226円271円346円263円225円350円247円243円346円236円220円344円270円200円.md" index d1c35e0..507ca80 100644 --- "a/springboot-source-code-analysis/(12)346円241円206円346円236円266円Refresh346円226円271円346円263円225円350円247円243円346円236円220円344円270円200円.md" +++ "b/springboot-source-code-analysis/(12)346円241円206円346円236円266円Refresh346円226円271円346円263円225円350円247円243円346円236円220円344円270円200円.md" @@ -24,7 +24,7 @@ prepareRefresh(); // Tell the subclass to refresh the internal bean factory. - // 获取BeanFacotry + // 获取BeanFacotry -> DefaultListablesBeanFacotory ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory(); // Prepare the bean factory for use in this context. diff --git a/springcloud-consul-config-sample/src/main/java/com/ipman/springcloud/consul/config/center/sample/SpringcloudConsulConfigSampleApplication.java b/springcloud-consul-config-sample/src/main/java/com/ipman/springcloud/consul/config/center/sample/SpringcloudConsulConfigSampleApplication.java index cd4c623..e833700 100644 --- a/springcloud-consul-config-sample/src/main/java/com/ipman/springcloud/consul/config/center/sample/SpringcloudConsulConfigSampleApplication.java +++ b/springcloud-consul-config-sample/src/main/java/com/ipman/springcloud/consul/config/center/sample/SpringcloudConsulConfigSampleApplication.java @@ -8,6 +8,7 @@ @EnableDiscoveryClient //让注册中心进行服务发现,将服务注册到服务组件上 public class SpringcloudConsulConfigSampleApplication { + // hello public static void main(String[] args) { SpringApplication.run(SpringcloudConsulConfigSampleApplication.class, args); }

AltStyle によって変換されたページ (->オリジナル) /