Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dict
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈文顺
dict
Commits
8ac63f3e
Commit
8ac63f3e
authored
Aug 02, 2019
by
陈文顺
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
spring 升级
parent
b80e53fd
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
83 additions
and
48 deletions
+83
-48
springboot-demo/pom.xml
+16
-6
springboot-demo/src/main/java/com/freemud/springbootdemo/SpringbootDemoApplication.java
+2
-1
springboot-demo/src/main/java/com/freemud/springbootdemo/config/ApolloConfig.java
+49
-0
springboot-demo/src/main/java/com/freemud/springbootdemo/config/DataSourceConfig.java
+0
-5
springboot-demo/src/main/java/com/freemud/springbootdemo/config/Swagger2.java
+6
-31
springboot-demo/src/main/resources/application.yml
+10
-5
No files found.
springboot-demo/pom.xml
View file @
8ac63f3e
...
...
@@ -67,12 +67,17 @@
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
<!--<exclusions>-->
<!--<exclusion>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-tomcat</artifactId>-->
<!--</exclusion>-->
<!--</exclusions>-->
<exclusions>
<exclusion>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-tomcat
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-undertow
</artifactId>
</dependency>
<!--<dependency>-->
...
...
@@ -90,6 +95,11 @@
<artifactId>
spring-cloud-starter-sleuth
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-netflix-eureka-client
</artifactId>
</dependency>
<!--<dependency>-->
<!--<groupId>org.springframework.cloud</groupId>-->
<!--<artifactId>spring-cloud-starter-eureka</artifactId>-->
...
...
springboot-demo/src/main/java/com/freemud/springbootdemo/SpringbootDemoApplication.java
View file @
8ac63f3e
...
...
@@ -5,6 +5,7 @@ import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.netflix.eureka.EnableEurekaClient
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.http.converter.HttpMessageConverter
;
...
...
@@ -15,7 +16,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@SpringBootApplication
@ComponentScan
(
basePackages
=
"com.freemud, cn.freemud"
)
@MapperScan
(
basePackages
=
"com.freemud.demo.mapper"
)
//
@EnableEurekaClient
@EnableEurekaClient
//@EnableApolloConfig
public
class
SpringbootDemoApplication
extends
WebMvcConfigurerAdapter
{
...
...
springboot-demo/src/main/java/com/freemud/springbootdemo/config/ApolloConfig.java
0 → 100644
View file @
8ac63f3e
package
com
.
freemud
.
springbootdemo
.
config
;
import
com.ctrip.framework.apollo.Config
;
import
com.ctrip.framework.apollo.model.ConfigChangeEvent
;
import
com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.BeansException
;
import
org.springframework.cloud.context.environment.EnvironmentChangeEvent
;
import
org.springframework.cloud.context.scope.refresh.RefreshScope
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
/**
* @Auther: yong.huang
* @Date: 2019/6/24 15:19
* @Description:
*/
@Slf4j
@Component
public
class
ApolloConfig
implements
ApplicationContextAware
{
ApplicationContext
applicationContext
;
@Resource
RefreshScope
refreshScope
;
@com
.
ctrip
.
framework
.
apollo
.
spring
.
annotation
.
ApolloConfig
private
Config
config
;
@ApolloConfigChangeListener
public
void
onChange
(
ConfigChangeEvent
configChangeEvent
){
log
.
info
(
"apollo change keys {}"
,
configChangeEvent
.
changedKeys
());
refreshProperties
(
configChangeEvent
);
}
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
this
.
applicationContext
=
applicationContext
;
}
public
void
refreshProperties
(
ConfigChangeEvent
configChangeEvent
){
this
.
applicationContext
.
publishEvent
(
new
EnvironmentChangeEvent
(
configChangeEvent
.
changedKeys
()));
refreshScope
.
refreshAll
();
}
}
springboot-demo/src/main/java/com/freemud/springbootdemo/config/DataSourceConfig.java
View file @
8ac63f3e
...
...
@@ -21,11 +21,6 @@ import javax.sql.DataSource;
@Configuration
public
class
DataSourceConfig
{
private
ApplicationContext
applicationContext
;
@ApolloConfig
private
Config
config
;
@Bean
@Primary
...
...
springboot-demo/src/main/java/com/freemud/springbootdemo/config/Swagger2.java
View file @
8ac63f3e
package
com
.
freemud
.
springbootdemo
.
config
;
import
com.ctrip.framework.apollo.model.ConfigChangeEvent
;
import
com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener
;
import
com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.cloud.context.environment.EnvironmentChangeEvent
;
import
org.springframework.cloud.context.refresh.ContextRefresher
;
import
org.springframework.cloud.context.scope.refresh.RefreshScope
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Scope
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
...
...
@@ -36,30 +27,18 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
*/
@Configuration
@EnableSwagger2
public
class
Swagger2
implements
ApplicationContextAware
{
public
class
Swagger2
{
private
final
RefreshScope
refreshScope
;
private
ApplicationContext
applicationContext
;
@Value
(
"${swagger_enable:}"
)
@Value
(
"${swagger.enable:}"
)
String
swaggerEnable
;
public
Swagger2
(
RefreshScope
refreshScope
)
{
this
.
refreshScope
=
refreshScope
;
}
@ApolloConfigChangeListener
(
interestedKeys
=
{
"swagger_enable"
})
public
void
onChange
(
ConfigChangeEvent
changeEvent
){
}
@Bean
@RefreshScope
public
Docket
createRestApi
()
{
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
apiInfo
(
apiInfo
())
.
enable
(
"true"
.
equals
(
this
.
swaggerEnable
))
.
enable
(
"true"
.
equals
(
swaggerEnable
))
.
select
()
.
apis
(
RequestHandlerSelectors
.
basePackage
(
"com.freemud.springbootdemo.controller"
))
.
paths
(
PathSelectors
.
any
())
...
...
@@ -74,8 +53,4 @@ public class Swagger2 implements ApplicationContextAware {
.
build
();
}
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
this
.
applicationContext
=
applicationContext
;
}
}
springboot-demo/src/main/resources/application.yml
View file @
8ac63f3e
...
...
@@ -68,18 +68,23 @@ logging:
# ignored: /**,/swagger*,/webjars/**,/v2/**,/swagger-resources/**
#swagger_enable: true
#
eureka:
#
client:
#
service-url:
# defaultZone: http://localhost:10001
/eureka
eureka
:
client
:
service-url
:
defaultZone
:
http://localhost:9528
/eureka
apollo
:
bootstrap
:
enabled
:
true
meta
:
http://212.129.229.203
namespaces
:
application,architect.common
meta
:
http://172.81.231.147
#apollo appId
app
:
id
:
dictionary
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