From 793532cbbfe422aa5c626b38311c7f6ac8f1f26d Mon Sep 17 00:00:00 2001 From: "763856958@qq.com" Date: Sun, 4 Jun 2023 17:49:18 +0800 Subject: [PATCH] =?UTF-8?q?start=E5=AE=8C=E6=95=B4=E6=89=93=E5=8C=85?= =?UTF-8?q?=E6=A1=88=E4=BE=8B=E5=AE=8C=E6=88=90=EF=BC=8C=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E6=B3=A8=E6=84=8Fstart=E6=94=BE=E5=88=B0maven=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E4=B8=AD=EF=BC=8C=E6=89=8D=E8=83=BD=E8=A2=AB=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E6=89=93=E6=88=90=E8=BF=90=E8=A1=8Cjar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- boot_start_com1/.gitignore | 33 ++++++++++ boot_start_com1/pom.xml | 60 +++++++++++++++++++ .../TestAutoConfiguration.java | 22 +++++++ .../annotation/EnableRobot.java | 23 +++++++ .../controller/TestController.java | 20 +++++++ .../properties/TestProperties.java | 19 ++++++ .../kk/boot_start_com1/properties/User.java | 8 +++ .../boot_start_com1/service/TestService.java | 16 +++++ ...ot.autoconfigure.AutoConfiguration.imports | 1 + boot_start_pro1/pom.xml | 32 ++++++---- .../BootStartPro1Application.java | 2 +- .../src/main/resources/application.properties | 2 + .../src/main/resources/application.yml | 8 +++ .../BootStartPro1ApplicationTests.java | 13 ---- 14 files changed, 233 insertions(+), 26 deletions(-) create mode 100644 boot_start_com1/.gitignore create mode 100644 boot_start_com1/pom.xml create mode 100644 boot_start_com1/src/main/java/com/kk/boot_start_com1/TestAutoConfiguration.java create mode 100644 boot_start_com1/src/main/java/com/kk/boot_start_com1/annotation/EnableRobot.java create mode 100644 boot_start_com1/src/main/java/com/kk/boot_start_com1/controller/TestController.java create mode 100644 boot_start_com1/src/main/java/com/kk/boot_start_com1/properties/TestProperties.java create mode 100644 boot_start_com1/src/main/java/com/kk/boot_start_com1/properties/User.java create mode 100644 boot_start_com1/src/main/java/com/kk/boot_start_com1/service/TestService.java create mode 100644 boot_start_com1/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports create mode 100644 boot_start_pro1/src/main/resources/application.yml delete mode 100644 boot_start_pro1/src/test/java/com/kk/boot_start_pro1/BootStartPro1ApplicationTests.java diff --git a/boot_start_com1/.gitignore b/boot_start_com1/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/boot_start_com1/.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/boot_start_com1/pom.xml b/boot_start_com1/pom.xml new file mode 100644 index 0000000..22c042c --- /dev/null +++ b/boot_start_com1/pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.7.1 + + com.kk + boot_start_com1 + 0.0.1-SNAPSHOT + jar + + + 8 + + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-web + + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + org.projectlombok + lombok + true + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.2.0 + + + + + + + + + + + + diff --git a/boot_start_com1/src/main/java/com/kk/boot_start_com1/TestAutoConfiguration.java b/boot_start_com1/src/main/java/com/kk/boot_start_com1/TestAutoConfiguration.java new file mode 100644 index 0000000..fe6237d --- /dev/null +++ b/boot_start_com1/src/main/java/com/kk/boot_start_com1/TestAutoConfiguration.java @@ -0,0 +1,22 @@ +package com.kk.boot_start_com1; + +import com.kk.boot_start_com1.controller.TestController; +import com.kk.boot_start_com1.properties.TestProperties; +import com.kk.boot_start_com1.service.TestService; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + + +//给容器中导入Robot功能要用的所有组件 +@Import({TestProperties.class, TestService.class}) +@Configuration +public class TestAutoConfiguration { + + @Bean //把组件导入到容器中 + public TestController robotController(){ + return new TestController(); + } + + +} diff --git a/boot_start_com1/src/main/java/com/kk/boot_start_com1/annotation/EnableRobot.java b/boot_start_com1/src/main/java/com/kk/boot_start_com1/annotation/EnableRobot.java new file mode 100644 index 0000000..390c4dc --- /dev/null +++ b/boot_start_com1/src/main/java/com/kk/boot_start_com1/annotation/EnableRobot.java @@ -0,0 +1,23 @@ +package com.kk.boot_start_com1.annotation; + +import com.kk.boot_start_com1.TestAutoConfiguration; +import org.springframework.context.annotation.Import; + +import java.lang.annotation.*; + +/* + * @Description: 注解方式驱动引入 + * @Author: 阿K + * @CreateDate: 2023/6/4 10:53 + * @Param: + * @Return: +*/ + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE}) +@Documented +@Import(TestAutoConfiguration.class)// 实际扫描文件 +public @interface EnableRobot { + + +} diff --git a/boot_start_com1/src/main/java/com/kk/boot_start_com1/controller/TestController.java b/boot_start_com1/src/main/java/com/kk/boot_start_com1/controller/TestController.java new file mode 100644 index 0000000..1c9268a --- /dev/null +++ b/boot_start_com1/src/main/java/com/kk/boot_start_com1/controller/TestController.java @@ -0,0 +1,20 @@ +package com.kk.boot_start_com1.controller; + +import com.kk.boot_start_com1.service.TestService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class TestController { + + @Autowired + TestService testService; + + @GetMapping("/test/hello") + public String sayHello() { + String s = testService.sayHello ( ); + return s; + } +} + diff --git a/boot_start_com1/src/main/java/com/kk/boot_start_com1/properties/TestProperties.java b/boot_start_com1/src/main/java/com/kk/boot_start_com1/properties/TestProperties.java new file mode 100644 index 0000000..0b392e1 --- /dev/null +++ b/boot_start_com1/src/main/java/com/kk/boot_start_com1/properties/TestProperties.java @@ -0,0 +1,19 @@ +package com.kk.boot_start_com1.properties; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import java.util.List; + +@ConfigurationProperties(prefix = "test") //此属性类和配置文件指定前缀绑定 +@Component +@Data +public class TestProperties { + + private String name; + private String age; + private String email; + private User user; + private List favorites; +} diff --git a/boot_start_com1/src/main/java/com/kk/boot_start_com1/properties/User.java b/boot_start_com1/src/main/java/com/kk/boot_start_com1/properties/User.java new file mode 100644 index 0000000..357b89d --- /dev/null +++ b/boot_start_com1/src/main/java/com/kk/boot_start_com1/properties/User.java @@ -0,0 +1,8 @@ +package com.kk.boot_start_com1.properties; + +import lombok.Data; + +@Data +public class User { + private String name; +} diff --git a/boot_start_com1/src/main/java/com/kk/boot_start_com1/service/TestService.java b/boot_start_com1/src/main/java/com/kk/boot_start_com1/service/TestService.java new file mode 100644 index 0000000..180f157 --- /dev/null +++ b/boot_start_com1/src/main/java/com/kk/boot_start_com1/service/TestService.java @@ -0,0 +1,16 @@ +package com.kk.boot_start_com1.service; + +import com.kk.boot_start_com1.properties.TestProperties; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class TestService { + + @Autowired + TestProperties testProperties; + + public String sayHello() { + return "你好:名字:【" + testProperties.getName ( ) + "】;年龄:【" + testProperties.getAge ( ) + "】
"+testProperties.getFavorites ()+"
user:"+testProperties.getUser ().getName (); + } +} diff --git a/boot_start_com1/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/boot_start_com1/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000..2eadc5c --- /dev/null +++ b/boot_start_com1/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +com.kk.boot_start_com1.TestAutoConfiguration diff --git a/boot_start_pro1/pom.xml b/boot_start_pro1/pom.xml index bdd1216..b9aaeaa 100644 --- a/boot_start_pro1/pom.xml +++ b/boot_start_pro1/pom.xml @@ -5,27 +5,31 @@ org.springframework.boot spring-boot-starter-parent - 3.1.0 + 2.7.1 com.kk boot_start_pro1 1.0.0-SNAPSHOT - boot_start_pro1 - Demo project for Spring Boot + jar + 8 + + org.springframework.boot + spring-boot-starter + org.springframework.boot spring-boot-starter-web - org.projectlombok - lombok - true + com.kk + boot_start_com1 + 0.0.1-SNAPSHOT org.springframework.boot @@ -40,13 +44,17 @@ org.springframework.boot spring-boot-maven-plugin - - - org.projectlombok - lombok - - + + com.kk.boot_start_pro1.BootStartPro1Application + true + + + + repackage + + + diff --git a/boot_start_pro1/src/main/java/com/kk/boot_start_pro1/BootStartPro1Application.java b/boot_start_pro1/src/main/java/com/kk/boot_start_pro1/BootStartPro1Application.java index dd1e3fd..24fa825 100644 --- a/boot_start_pro1/src/main/java/com/kk/boot_start_pro1/BootStartPro1Application.java +++ b/boot_start_pro1/src/main/java/com/kk/boot_start_pro1/BootStartPro1Application.java @@ -4,7 +4,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class BootStartPro1Application { +public class BootStartPro1Application { public static void main(String[] args) { SpringApplication.run (BootStartPro1Application.class, args); diff --git a/boot_start_pro1/src/main/resources/application.properties b/boot_start_pro1/src/main/resources/application.properties index 8b13789..bde051f 100644 --- a/boot_start_pro1/src/main/resources/application.properties +++ b/boot_start_pro1/src/main/resources/application.properties @@ -1 +1,3 @@ +test.age=18 +test.name=mykk2 diff --git a/boot_start_pro1/src/main/resources/application.yml b/boot_start_pro1/src/main/resources/application.yml new file mode 100644 index 0000000..886502e --- /dev/null +++ b/boot_start_pro1/src/main/resources/application.yml @@ -0,0 +1,8 @@ +test: + user: + name: kk + name: + favorites: + - mykk + - 22 + - shuai diff --git a/boot_start_pro1/src/test/java/com/kk/boot_start_pro1/BootStartPro1ApplicationTests.java b/boot_start_pro1/src/test/java/com/kk/boot_start_pro1/BootStartPro1ApplicationTests.java deleted file mode 100644 index c70f738..0000000 --- a/boot_start_pro1/src/test/java/com/kk/boot_start_pro1/BootStartPro1ApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.kk.boot_start_pro1; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class BootStartPro1ApplicationTests { - - @Test - void contextLoads() { - } - -} -- Gitee