新增spring-annotation-dependsOn模块
parent
bafdd98e30
commit
7d4b15c59e
|
@ -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>
|
|
@ -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>
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.xcs.spring;
|
||||||
|
|
||||||
|
import com.xcs.spring.config.MyConfiguration;
|
||||||
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xcs
|
||||||
|
* @date 2023年08月07日 16时21分
|
||||||
|
**/
|
||||||
|
public class DependsOnApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.xcs.spring.bean;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.DependsOn;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 林雷
|
||||||
|
* @date 2023年10月09日 16时45分
|
||||||
|
**/
|
||||||
|
@DependsOn("classBeanSecond")
|
||||||
|
@Component
|
||||||
|
public class ClassBeanFirst {
|
||||||
|
public ClassBeanFirst() {
|
||||||
|
System.out.println("ClassBeanFirst Initialized");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.xcs.spring.bean;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 林雷
|
||||||
|
* @date 2023年10月09日 16时46分
|
||||||
|
**/
|
||||||
|
@Component
|
||||||
|
public class ClassBeanSecond {
|
||||||
|
public ClassBeanSecond() {
|
||||||
|
System.out.println("ClassBeanSecond Initialized");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.xcs.spring.bean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 林雷
|
||||||
|
* @date 2023年10月09日 16时45分
|
||||||
|
**/
|
||||||
|
public class MethodBeanFirst {
|
||||||
|
public MethodBeanFirst() {
|
||||||
|
System.out.println("MethodBeanFirst Initialized");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.xcs.spring.bean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 林雷
|
||||||
|
* @date 2023年10月09日 16时46分
|
||||||
|
**/
|
||||||
|
public class MethodBeanSecond {
|
||||||
|
public MethodBeanSecond() {
|
||||||
|
System.out.println("MethodBeanSecond Initialized");
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 2023年08月07日 16时25分
|
||||||
|
**/
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue