新增spring-annotation-dependsOn模块

master
xuchengsheng 2023-10-09 18:01:48 +08:00
parent bafdd98e30
commit 7d4b15c59e
8 changed files with 110 additions and 0 deletions

View File

@ -18,6 +18,7 @@
<module>spring-annotation-import</module> <module>spring-annotation-import</module>
<module>spring-annotation-propertySource</module> <module>spring-annotation-propertySource</module>
<module>spring-annotation-componentScan</module> <module>spring-annotation-componentScan</module>
<module>spring-annotation-dependsOn</module>
</modules> </modules>
</project> </project>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
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">
<parent>
<artifactId>spring-annotation</artifactId>
<groupId>com.xcs.spring</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-annotation-dependsOn</artifactId>
</project>

View File

@ -0,0 +1,15 @@
package com.xcs.spring;
import com.xcs.spring.config.MyConfiguration;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
/**
* @author xcs
* @date 20230807 1621
**/
public class DependsOnApplication {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
}
}

View File

@ -0,0 +1,16 @@
package com.xcs.spring.bean;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
/**
* @author
* @date 20231009 1645
**/
@DependsOn("classBeanSecond")
@Component
public class ClassBeanFirst {
public ClassBeanFirst() {
System.out.println("ClassBeanFirst Initialized");
}
}

View File

@ -0,0 +1,14 @@
package com.xcs.spring.bean;
import org.springframework.stereotype.Component;
/**
* @author
* @date 20231009 1646
**/
@Component
public class ClassBeanSecond {
public ClassBeanSecond() {
System.out.println("ClassBeanSecond Initialized");
}
}

View File

@ -0,0 +1,11 @@
package com.xcs.spring.bean;
/**
* @author
* @date 20231009 1645
**/
public class MethodBeanFirst {
public MethodBeanFirst() {
System.out.println("MethodBeanFirst Initialized");
}
}

View File

@ -0,0 +1,11 @@
package com.xcs.spring.bean;
/**
* @author
* @date 20231009 1646
**/
public class MethodBeanSecond {
public MethodBeanSecond() {
System.out.println("MethodBeanSecond Initialized");
}
}

View File

@ -0,0 +1,28 @@
package com.xcs.spring.config;
import com.xcs.spring.bean.MethodBeanFirst;
import com.xcs.spring.bean.MethodBeanSecond;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
/**
* @author xcs
* @date 20230807 1625
**/
@Configuration
@ComponentScan("com.xcs.spring.bean")
public class MyConfiguration {
@Bean
@DependsOn("methodBeanSecond")
public MethodBeanFirst methodBeanFirst() {
return new MethodBeanFirst();
}
@Bean
public MethodBeanSecond methodBeanSecond() {
return new MethodBeanSecond();
}
}