Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
ad241be2
Commit
ad241be2
authored
Mar 17, 2017
by
张乐
Committed by
GitHub
Mar 17, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #570 from nobodyiam/spring-boot-demo
add spring boot configuration properties example
parents
aefdea8c
7e10b67c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
2 deletions
+94
-2
pom.xml
apollo-demo/pom.xml
+16
-2
SpringBootSampleApplication.java
...ework/apollo/demo/spring/SpringBootSampleApplication.java
+30
-0
AnnotatedBean.java
...trip/framework/apollo/demo/spring/bean/AnnotatedBean.java
+9
-0
SampleRedisConfig.java
...ramework/apollo/demo/spring/config/SampleRedisConfig.java
+39
-0
No files found.
apollo-demo/pom.xml
View file @
ad241be2
...
@@ -13,8 +13,7 @@
...
@@ -13,8 +13,7 @@
<properties>
<properties>
<java.version>
1.7
</java.version>
<java.version>
1.7
</java.version>
<github.path>
${project.artifactId}
</github.path>
<github.path>
${project.artifactId}
</github.path>
<!-- apollo spring integration requires Spring 3.1.1+ -->
<spring-demo.version>
4.3.6.RELEASE
</spring-demo.version>
<spring-demo.version>
3.1.1.RELEASE
</spring-demo.version>
</properties>
</properties>
<dependencyManagement>
<dependencyManagement>
<dependencies>
<dependencies>
...
@@ -72,6 +71,21 @@
...
@@ -72,6 +71,21 @@
<groupId>
org.springframework
</groupId>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-context
</artifactId>
<artifactId>
spring-context
</artifactId>
</dependency>
</dependency>
<!-- for spring boot demo -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
<exclusions>
<exclusion>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-logging
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-log4j2
</artifactId>
</dependency>
<!-- required for spring 3.1.0 -->
<!-- required for spring 3.1.0 -->
<dependency>
<dependency>
<groupId>
cglib
</groupId>
<groupId>
cglib
</groupId>
...
...
apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/SpringBootSampleApplication.java
0 → 100644
View file @
ad241be2
package
com
.
ctrip
.
framework
.
apollo
.
demo
.
spring
;
import
com.ctrip.framework.apollo.demo.spring.config.SampleRedisConfig
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.context.annotation.Bean
;
import
java.util.Scanner
;
/**
* @author Jason Song
*/
@SpringBootApplication
public
class
SpringBootSampleApplication
{
@Bean
public
SampleRedisConfig
sampleRedisConfig
()
{
return
new
SampleRedisConfig
();
}
public
static
void
main
(
String
[]
args
)
{
new
SpringApplicationBuilder
(
SpringBootSampleApplication
.
class
).
run
(
args
);
onKeyExit
();
}
private
static
void
onKeyExit
()
{
System
.
out
.
println
(
"Press Enter to exit..."
);
new
Scanner
(
System
.
in
).
nextLine
();
}
}
apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/bean/AnnotatedBean.java
View file @
ad241be2
...
@@ -51,6 +51,9 @@ public class AnnotatedBean {
...
@@ -51,6 +51,9 @@ public class AnnotatedBean {
logger
.
info
(
"[someChangeHandler]Change - key: {}, oldValue: {}, newValue: {}, changeType: {}"
,
logger
.
info
(
"[someChangeHandler]Change - key: {}, oldValue: {}, newValue: {}, changeType: {}"
,
change
.
getPropertyName
(),
change
.
getOldValue
(),
change
.
getNewValue
(),
change
.
getPropertyName
(),
change
.
getOldValue
(),
change
.
getNewValue
(),
change
.
getChangeType
());
change
.
getChangeType
());
if
(
key
.
equals
(
"timeout"
))
{
refreshTimeout
();
}
}
}
}
}
...
@@ -64,4 +67,10 @@ public class AnnotatedBean {
...
@@ -64,4 +67,10 @@ public class AnnotatedBean {
change
.
getChangeType
());
change
.
getChangeType
());
}
}
}
}
private
void
refreshTimeout
()
{
//do some custom logic to update placeholder value
timeout
=
config
.
getIntProperty
(
"timeout"
,
timeout
);
logger
.
info
(
"Refreshing timeout to {}"
,
timeout
);
}
}
}
apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/config/SampleRedisConfig.java
0 → 100644
View file @
ad241be2
package
com
.
ctrip
.
framework
.
apollo
.
demo
.
spring
.
config
;
import
com.ctrip.framework.apollo.demo.spring.bean.AnnotatedBean
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
javax.annotation.PostConstruct
;
/**
* @author Jason Song
*/
@ConfigurationProperties
(
prefix
=
"redis.cache"
)
public
class
SampleRedisConfig
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SampleRedisConfig
.
class
);
private
int
expireSeconds
;
private
String
clusterNodes
;
private
int
commandTimeout
;
@PostConstruct
private
void
init
()
{
logger
.
info
(
"ConfigurationProperties sample - expireSeconds: {}, clusterNodes: {}, commandTimeout: {}"
,
expireSeconds
,
clusterNodes
,
commandTimeout
);
}
public
void
setExpireSeconds
(
int
expireSeconds
)
{
this
.
expireSeconds
=
expireSeconds
;
}
public
void
setClusterNodes
(
String
clusterNodes
)
{
this
.
clusterNodes
=
clusterNodes
;
}
public
void
setCommandTimeout
(
int
commandTimeout
)
{
this
.
commandTimeout
=
commandTimeout
;
}
}
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