Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
springboot-demo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Leona
W
web
backend
springboot-demo
Commits
3e5002da
Commit
3e5002da
authored
Aug 03, 2020
by
duanledexianxianxian
😁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Example
parent
1a1280bf
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
99 additions
and
6 deletions
+99
-6
core/src/main/java/com/duanledexianxianxian/core/SpringWebApplication.java
...a/com/duanledexianxianxian/core/SpringWebApplication.java
+17
-5
core/src/main/java/com/duanledexianxianxian/core/config/SystemEnvironmentProperties.java
...xianxianxian/core/config/SystemEnvironmentProperties.java
+18
-0
core/src/main/java/com/duanledexianxianxian/core/config/SystemPropertySourceValueProperties.java
...xian/core/config/SystemPropertySourceValueProperties.java
+30
-0
core/src/main/java/com/duanledexianxianxian/core/config/SystemValueProperties.java
...anledexianxianxian/core/config/SystemValueProperties.java
+25
-0
core/src/main/resources/application.yml
core/src/main/resources/application.yml
+5
-1
core/src/main/resources/config/system.properties
core/src/main/resources/config/system.properties
+4
-0
No files found.
core/src/main/java/com/duanledexianxianxian/core/SpringWebApplication.java
View file @
3e5002da
package
com.duanledexianxianxian.core
;
import
com.duanledexianxianxian.core.config.SystemEnvironmentProperties
;
import
com.duanledexianxianxian.core.config.SystemProperties
;
import
com.duanledexianxianxian.core.config.SystemPropertySourceValueProperties
;
import
com.duanledexianxianxian.core.config.SystemValueProperties
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.ApplicationContext
;
/**
* springboot 应用程序入口
*
* @author duanledexianxianxian
*/
@SpringBootApplication
public
class
SpringWebApplication
{
public
static
void
main
(
String
[]
args
)
{
ApplicationContext
applicationContext
=
(
ApplicationContext
)
SpringApplication
.
run
(
SpringWebApplication
.
class
,
args
);
SystemProperties
properties
=
applicationContext
.
getBean
(
SystemProperties
.
class
);
System
.
out
.
println
(
"用户的当前工作目录:"
+
System
.
getProperty
(
"user.dir"
));
// 打印出配置参数
System
.
out
.
println
(
properties
.
getName
());
ApplicationContext
applicationContext
=
SpringApplication
.
run
(
SpringWebApplication
.
class
,
args
);
SystemProperties
systemProperties
=
applicationContext
.
getBean
(
SystemProperties
.
class
);
SystemValueProperties
valueProperties
=
applicationContext
.
getBean
(
SystemValueProperties
.
class
);
SystemEnvironmentProperties
environmentProperties
=
applicationContext
.
getBean
(
SystemEnvironmentProperties
.
class
);
SystemPropertySourceValueProperties
propertySourceValueProperties
=
applicationContext
.
getBean
(
SystemPropertySourceValueProperties
.
class
);
System
.
out
.
println
(
"用户的当前工作目录:"
+
System
.
getProperty
(
"user.dir"
));
// 通过@value加载配置方式
System
.
out
.
println
(
"@Value:"
+
valueProperties
);
System
.
out
.
println
(
"@ConfigurationProperties:"
+
systemProperties
);
System
.
out
.
println
(
"Environment:"
+
environmentProperties
.
getEnvironment
().
getProperty
(
"system.name"
));
System
.
out
.
println
(
"@PropertySource+@Value+@ConfigurationProperties:"
+
propertySourceValueProperties
);
}
...
...
core/src/main/java/com/duanledexianxianxian/core/config/SystemEnvironmentProperties.java
0 → 100644
View file @
3e5002da
package
com.duanledexianxianxian.core.config
;
import
lombok.Data
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.core.env.Environment
;
import
org.springframework.stereotype.Component
;
/**
* 通过Environment加载配置参数
* @author duanledexianxianxian
*/
@Component
@Data
public
class
SystemEnvironmentProperties
{
@Autowired
private
Environment
environment
;
}
core/src/main/java/com/duanledexianxianxian/core/config/SystemPropertySourceValueProperties.java
0 → 100644
View file @
3e5002da
package
com.duanledexianxianxian.core.config
;
import
lombok.Data
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.stereotype.Component
;
/**
* 通过@value加载配置参数
* @author duanledexianxianxian
*/
@Component
@ConfigurationProperties
(
prefix
=
"system.property"
)
@PropertySource
(
value
=
{
"/config/system.properties"
})
@Data
public
class
SystemPropertySourceValueProperties
{
/**
* 名称
* //最好设置默认值,否则配置文件即使有相应key,也会应用启动失败
*/
@Value
(
"${name:null}"
)
private
String
name
;
/**
* 编码
* //最好设置默认值,否则配置文件即使有相应key,也会应用启动失败
*/
@Value
(
"${code:null}"
)
private
String
code
;
}
core/src/main/java/com/duanledexianxianxian/core/config/SystemValueProperties.java
0 → 100644
View file @
3e5002da
package
com.duanledexianxianxian.core.config
;
import
lombok.Data
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.stereotype.Component
;
/**
* 通过@value加载配置参数
* @author duanledexianxianxian
*/
@Component
@Data
public
class
SystemValueProperties
{
/**
* 名称
*/
@Value
(
"${system.name}"
)
private
String
name
;
/**
* 编码
*/
@Value
(
"${system.code}"
)
private
String
code
;
}
core/src/main/resources/application.yml
View file @
3e5002da
server
:
port
:
8080
#系统相关配置
system
:
# 系统名称
name
:
"
classpath
root
config"
# 系统编码
code
:
"
classpath
root
code"
\ No newline at end of file
core/src/main/resources/config/system.properties
0 → 100644
View file @
3e5002da
system.property.name
=
\u
7CFB
\u
7EDF
\u
540D
\u
79F0
system.property.code
=
\u
7CFB
\u
7EDF
\u
7F16
\u7801
#name=ssss
#
code
=
ssss
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment