Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
武汉红喜
whatsmars
提交
f7a1c9f8
W
whatsmars
项目概览
武汉红喜
/
whatsmars
通知
3
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
f7a1c9f8
编写于
6月 23, 2020
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
EnvironmentProcessor
上级
cf87d033
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
86 addition
and
25 deletion
+86
-25
whatsmars-spring-boot-samples/whatsmars-boot-sample-bean/src/main/java/org/hongxi/whatsmars/boot/sample/bean/Application.java
...va/org/hongxi/whatsmars/boot/sample/bean/Application.java
+0
-25
whatsmars-spring-boot-samples/whatsmars-boot-sample-bean/src/main/java/org/hongxi/whatsmars/boot/sample/bean/ApplicationConfiguration.java
.../whatsmars/boot/sample/bean/ApplicationConfiguration.java
+42
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-bean/src/main/java/org/hongxi/whatsmars/boot/sample/bean/ConditionalBean.java
...rg/hongxi/whatsmars/boot/sample/bean/ConditionalBean.java
+11
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-bean/src/main/java/org/hongxi/whatsmars/boot/sample/bean/EnvironmentProcessor.java
...ngxi/whatsmars/boot/sample/bean/EnvironmentProcessor.java
+12
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-bean/src/main/java/org/hongxi/whatsmars/boot/sample/bean/OrCondition.java
...va/org/hongxi/whatsmars/boot/sample/bean/OrCondition.java
+18
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-bean/src/main/resources/META-INF/spring.factories
...-sample-bean/src/main/resources/META-INF/spring.factories
+2
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-bean/src/main/resources/application.yml
...smars-boot-sample-bean/src/main/resources/application.yml
+1
-0
未找到文件。
whatsmars-spring-boot-samples/whatsmars-boot-sample-bean/src/main/java/org/hongxi/whatsmars/boot/sample/bean/Application.java
浏览文件 @
f7a1c9f8
...
...
@@ -2,9 +2,6 @@ package org.hongxi.whatsmars.boot.sample.bean;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.core.annotation.Order
;
/**
* Created by shenhongxi on 2020/6/8.
...
...
@@ -15,26 +12,4 @@ public class Application {
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
Application
.
class
,
args
);
}
@Order
(
1
)
@ConditionalOnMissingBean
@Bean
public
DemoBean
demoBean
()
{
return
new
DemoBean
();
}
@Bean
public
DemoBean
demoBean2
()
{
return
new
DemoBean
();
}
@Bean
public
OrderedDemoBean
orderedDemoBean
()
{
return
new
OrderedDemoBean
();
}
@Bean
public
DemoBeanPostProcessor
demoBeanPostProcessor
()
{
return
new
DemoBeanPostProcessor
();
}
}
whatsmars-spring-boot-samples/whatsmars-boot-sample-bean/src/main/java/org/hongxi/whatsmars/boot/sample/bean/ApplicationConfiguration.java
0 → 100644
浏览文件 @
f7a1c9f8
package
org.hongxi.whatsmars.boot.sample.bean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.annotation.Order
;
/**
* Created by shenhongxi on 2020/6/22.
*/
@Configuration
public
class
ApplicationConfiguration
{
@Order
(
1
)
@ConditionalOnMissingBean
@Bean
public
DemoBean
demoBean
()
{
return
new
DemoBean
();
}
@Bean
public
DemoBean
demoBean2
()
{
return
new
DemoBean
();
}
@Bean
public
OrderedDemoBean
orderedDemoBean
()
{
return
new
OrderedDemoBean
();
}
@Bean
public
DemoBeanPostProcessor
demoBeanPostProcessor
()
{
return
new
DemoBeanPostProcessor
();
}
@Bean
@Conditional
(
OrCondition
.
class
)
public
ConditionalBean
conditionalBean
()
{
return
new
ConditionalBean
();
}
}
whatsmars-spring-boot-samples/whatsmars-boot-sample-bean/src/main/java/org/hongxi/whatsmars/boot/sample/bean/ConditionalBean.java
0 → 100644
浏览文件 @
f7a1c9f8
package
org.hongxi.whatsmars.boot.sample.bean
;
/**
* Created by shenhongxi on 2020/6/22.
*/
public
class
ConditionalBean
{
public
ConditionalBean
()
{
System
.
out
.
println
(
"new ConditionalBean"
);
}
}
whatsmars-spring-boot-samples/whatsmars-boot-sample-bean/src/main/java/org/hongxi/whatsmars/boot/sample/bean/EnvironmentProcessor.java
0 → 100644
浏览文件 @
f7a1c9f8
package
org.hongxi.whatsmars.boot.sample.bean
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.env.EnvironmentPostProcessor
;
import
org.springframework.core.env.ConfigurableEnvironment
;
public
class
EnvironmentProcessor
implements
EnvironmentPostProcessor
{
@Override
public
void
postProcessEnvironment
(
ConfigurableEnvironment
environment
,
SpringApplication
application
)
{
System
.
out
.
println
(
"postProcessEnvironment"
);
}
}
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-bean/src/main/java/org/hongxi/whatsmars/boot/sample/bean/OrCondition.java
0 → 100644
浏览文件 @
f7a1c9f8
package
org.hongxi.whatsmars.boot.sample.bean
;
import
org.springframework.context.annotation.Condition
;
import
org.springframework.context.annotation.ConditionContext
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
/**
* Created by shenhongxi on 2020/6/22.
*/
public
class
OrCondition
implements
Condition
{
@Override
public
boolean
matches
(
ConditionContext
context
,
AnnotatedTypeMetadata
metadata
)
{
Environment
environment
=
context
.
getEnvironment
();
return
environment
.
containsProperty
(
"a"
)
||
environment
.
containsProperty
(
"b"
);
}
}
whatsmars-spring-boot-samples/whatsmars-boot-sample-bean/src/main/resources/META-INF/spring.factories
0 → 100644
浏览文件 @
f7a1c9f8
org.springframework.boot.env.EnvironmentPostProcessor=\
org.hongxi.whatsmars.boot.sample.bean.EnvironmentProcessor
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-bean/src/main/resources/application.yml
浏览文件 @
f7a1c9f8
a
:
xx
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录