diff --git a/lab-47/lab-47-demo/pom.xml b/lab-47/lab-47-demo/pom.xml index 63d63dd9..e4c5180e 100644 --- a/lab-47/lab-47-demo/pom.xml +++ b/lab-47/lab-47-demo/pom.xml @@ -12,6 +12,7 @@ lab-47-demo + cn.iocoder.springboot.labs yunai-server-spring-boot-starter diff --git a/lab-47/lab-47-demo/src/main/resources/application.yaml b/lab-47/lab-47-demo/src/main/resources/application.yaml new file mode 100644 index 00000000..6ceb1988 --- /dev/null +++ b/lab-47/lab-47-demo/src/main/resources/application.yaml @@ -0,0 +1,3 @@ +yunai: + server: + port: 8888 diff --git a/lab-47/yunai-server-spring-boot-starter/pom.xml b/lab-47/yunai-server-spring-boot-starter/pom.xml index 9f6b9fbe..f5c5d520 100644 --- a/lab-47/yunai-server-spring-boot-starter/pom.xml +++ b/lab-47/yunai-server-spring-boot-starter/pom.xml @@ -12,6 +12,7 @@ yunai-server-spring-boot-starter + org.springframework.boot spring-boot-starter diff --git a/lab-47/yunai-server-spring-boot-starter/src/main/java/cn/iocoder/springboot/lab47/yunaiserver/autoconfigure/YunaiServerAutoConfiguration.java b/lab-47/yunai-server-spring-boot-starter/src/main/java/cn/iocoder/springboot/lab47/yunaiserver/autoconfigure/YunaiServerAutoConfiguration.java index eafdb1dd..fe68dcc9 100644 --- a/lab-47/yunai-server-spring-boot-starter/src/main/java/cn/iocoder/springboot/lab47/yunaiserver/autoconfigure/YunaiServerAutoConfiguration.java +++ b/lab-47/yunai-server-spring-boot-starter/src/main/java/cn/iocoder/springboot/lab47/yunaiserver/autoconfigure/YunaiServerAutoConfiguration.java @@ -11,14 +11,14 @@ import org.springframework.context.annotation.Configuration; import java.io.IOException; import java.net.InetSocketAddress; -@Configuration -@EnableConfigurationProperties(YunaiServerProperties.class) +@Configuration // 声明配置类 +@EnableConfigurationProperties(YunaiServerProperties.class) // 使 YunaiServerProperties 配置属性类生效 public class YunaiServerAutoConfiguration { private Logger logger = LoggerFactory.getLogger(getClass()); - @Bean - @ConditionalOnClass(HttpServer.class) + @Bean // 声明创建 Bean + @ConditionalOnClass(HttpServer.class) // 需要项目中存在 com.sun.net.httpserver.HttpServer 类。该类为 JDK 自带,所以一定成立。 public HttpServer httpServer(YunaiServerProperties serverProperties) throws IOException { // 创建 HttpServer 对象,并启动 HttpServer server = HttpServer.create(new InetSocketAddress(serverProperties.getPort()), 0);