File tree Expand file tree Collapse file tree 4 files changed +31
-1
lines changed
myTest/src/main/java/com/hand
zzj-spring-boot-stater/src/main/java/com/hand Expand file tree Collapse file tree 4 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 4
4
import org .springframework .boot .autoconfigure .SpringBootApplication ;
5
5
6
6
@ SpringBootApplication
7
+ @ EnableRegisterServer
7
8
public class MyTestApplication {
8
9
9
10
public static void main (String [] args ) {
Original file line number Diff line number Diff line change
1
+ package com .hand ;
2
+
3
+ import java .lang .annotation .ElementType ;
4
+ import java .lang .annotation .Retention ;
5
+ import java .lang .annotation .RetentionPolicy ;
6
+ import java .lang .annotation .Target ;
7
+
8
+ import com .hand .config .ConfigMarker ;
9
+ import org .springframework .context .annotation .Import ;
10
+
11
+ /**
12
+ * @author zijian.zeng@hand-china.com
13
+ * @since 2023-01-27
14
+ */
15
+ @ Target (ElementType .TYPE )
16
+ @ Retention (RetentionPolicy .RUNTIME )
17
+ @ Import (ConfigMarker .class ) // 将某个组件类生成实例,添加到容器中
18
+ public @interface EnableRegisterServer {
19
+ }
Original file line number Diff line number Diff line change
1
+ package com .hand .config ;
2
+
3
+
4
+ /**
5
+ * @author zijian.zeng@hand-china.com
6
+ * @since 2023-01-27
7
+ */
8
+ public class ConfigMarker {
9
+ }
Original file line number Diff line number Diff line change 1
1
package com .hand .config ;
2
2
3
3
import com .hand .pojo .SimpleBean ;
4
+ import org .springframework .boot .autoconfigure .condition .ConditionalOnBean ;
4
5
import org .springframework .context .annotation .Bean ;
5
6
import org .springframework .context .annotation .Configuration ;
6
7
9
10
* @since 2023-01-27
10
11
*/
11
12
@ Configuration
13
+ @ ConditionalOnBean (ConfigMarker .class ) // 上下文中必须存在ConfigMarker bean,才会让当前自动配置类生效
12
14
public class MyAutoConfiguration {
13
15
14
16
static {
@@ -19,5 +21,4 @@ public class MyAutoConfiguration {
19
21
public SimpleBean simpleBean () {
20
22
return new SimpleBean ();
21
23
}
22
-
23
24
}
You can’t perform that action at this time.
0 commit comments