Commit 8ac63f3e by 陈文顺

spring 升级

parent b80e53fd
......@@ -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>-->
......
......@@ -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{
......
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();
}
}
......@@ -21,11 +21,6 @@ import javax.sql.DataSource;
@Configuration
public class DataSourceConfig {
private ApplicationContext applicationContext;
@ApolloConfig
private Config config;
@Bean
@Primary
......
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;
}
}
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment