From 17425eed0a4f9c233203062f36118bbb0ef514e5 Mon Sep 17 00:00:00 2001 From: xuchengsheng Date: Mon, 16 Oct 2023 22:53:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Espring-jsr-inject=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spring-jsr-330/pom.xml | 8 ++++++++ spring-jsr-330/spring-jsr-inject/README.md | 0 spring-jsr-330/spring-jsr-inject/pom.xml | 3 +-- .../java/com/xcs/spring/InjectApplication.java | 18 ++++++++++++++++++ .../com/xcs/spring/config/MyConfiguration.java | 10 ++++++++++ .../xcs/spring/controller/MyController.java | 18 ++++++++++++++++++ .../java/com/xcs/spring/service/MyService.java | 7 +++++++ 7 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 spring-jsr-330/spring-jsr-inject/README.md create mode 100644 spring-jsr-330/spring-jsr-inject/src/main/java/com/xcs/spring/InjectApplication.java create mode 100644 spring-jsr-330/spring-jsr-inject/src/main/java/com/xcs/spring/config/MyConfiguration.java create mode 100644 spring-jsr-330/spring-jsr-inject/src/main/java/com/xcs/spring/controller/MyController.java create mode 100644 spring-jsr-330/spring-jsr-inject/src/main/java/com/xcs/spring/service/MyService.java diff --git a/spring-jsr-330/pom.xml b/spring-jsr-330/pom.xml index ff6df96..a07a730 100644 --- a/spring-jsr-330/pom.xml +++ b/spring-jsr-330/pom.xml @@ -21,4 +21,12 @@ spring-jsr-provider + + + javax.inject + javax.inject + 1 + + + \ No newline at end of file diff --git a/spring-jsr-330/spring-jsr-inject/README.md b/spring-jsr-330/spring-jsr-inject/README.md new file mode 100644 index 0000000..e69de29 diff --git a/spring-jsr-330/spring-jsr-inject/pom.xml b/spring-jsr-330/spring-jsr-inject/pom.xml index fc2437f..3073354 100644 --- a/spring-jsr-330/spring-jsr-inject/pom.xml +++ b/spring-jsr-330/spring-jsr-inject/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - spring-annotation + spring-jsr-330 com.xcs.spring 0.0.1-SNAPSHOT @@ -11,5 +11,4 @@ 4.0.0 spring-jsr-inject - \ No newline at end of file diff --git a/spring-jsr-330/spring-jsr-inject/src/main/java/com/xcs/spring/InjectApplication.java b/spring-jsr-330/spring-jsr-inject/src/main/java/com/xcs/spring/InjectApplication.java new file mode 100644 index 0000000..2e50c1c --- /dev/null +++ b/spring-jsr-330/spring-jsr-inject/src/main/java/com/xcs/spring/InjectApplication.java @@ -0,0 +1,18 @@ +package com.xcs.spring; + +import com.xcs.spring.config.MyConfiguration; +import com.xcs.spring.controller.MyController; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +/** + * @author xcs + * @date 2023年08月07日 16时21分 + **/ +public class InjectApplication { + + public static void main(String[] args) { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class); + MyController controller = context.getBean(MyController.class); + controller.showService(); + } +} diff --git a/spring-jsr-330/spring-jsr-inject/src/main/java/com/xcs/spring/config/MyConfiguration.java b/spring-jsr-330/spring-jsr-inject/src/main/java/com/xcs/spring/config/MyConfiguration.java new file mode 100644 index 0000000..0ca0d88 --- /dev/null +++ b/spring-jsr-330/spring-jsr-inject/src/main/java/com/xcs/spring/config/MyConfiguration.java @@ -0,0 +1,10 @@ +package com.xcs.spring.config; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan("com.xcs.spring") +public class MyConfiguration { + +} diff --git a/spring-jsr-330/spring-jsr-inject/src/main/java/com/xcs/spring/controller/MyController.java b/spring-jsr-330/spring-jsr-inject/src/main/java/com/xcs/spring/controller/MyController.java new file mode 100644 index 0000000..d52d1a7 --- /dev/null +++ b/spring-jsr-330/spring-jsr-inject/src/main/java/com/xcs/spring/controller/MyController.java @@ -0,0 +1,18 @@ +package com.xcs.spring.controller; + +import com.xcs.spring.service.MyService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; + +import javax.inject.Inject; + +@Controller +public class MyController { + + @Inject + private MyService myService; + + public void showService(){ + System.out.println("myService = " + myService); + } +} diff --git a/spring-jsr-330/spring-jsr-inject/src/main/java/com/xcs/spring/service/MyService.java b/spring-jsr-330/spring-jsr-inject/src/main/java/com/xcs/spring/service/MyService.java new file mode 100644 index 0000000..7c03538 --- /dev/null +++ b/spring-jsr-330/spring-jsr-inject/src/main/java/com/xcs/spring/service/MyService.java @@ -0,0 +1,7 @@ +package com.xcs.spring.service; + +import org.springframework.stereotype.Service; + +@Service +public class MyService { +}