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 { +}