新增spring-jsr-inject模块

master
xuchengsheng 2023-10-16 22:53:05 +08:00
parent 29d5e7f25c
commit 17425eed0a
7 changed files with 62 additions and 2 deletions

View File

@ -21,4 +21,12 @@
<module>spring-jsr-provider</module> <module>spring-jsr-provider</module>
</modules> </modules>
<dependencies>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
</dependencies>
</project> </project>

View File

@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>spring-annotation</artifactId> <artifactId>spring-jsr-330</artifactId>
<groupId>com.xcs.spring</groupId> <groupId>com.xcs.spring</groupId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
</parent> </parent>
@ -11,5 +11,4 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>spring-jsr-inject</artifactId> <artifactId>spring-jsr-inject</artifactId>
</project> </project>

View File

@ -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 20230807 1621
**/
public class InjectApplication {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
MyController controller = context.getBean(MyController.class);
controller.showService();
}
}

View File

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

View File

@ -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);
}
}

View File

@ -0,0 +1,7 @@
package com.xcs.spring.service;
import org.springframework.stereotype.Service;
@Service
public class MyService {
}