搜索:spring cloud

获取eureka的注册服务的实例列表

原创 2022-07-05 16:54 阅读(1075)次
如果获取eureka中服务对应的实例列表? 代码如下: ```java @Autowired private SpringClientFactory factory; ``` ```java ILoadBalancer lb = factory.getLoadBalancer("xxxx"); //指定服务名 List allServers = lb.getAllServers(); List upServers = lb.getReachableServers(); ``` 运行结果: ...

BeanDefinitionRegistryPostProcessor作用及加载顺序

原创 2022-02-15 11:53 阅读(879)次
BeanDefinitionRegistryPostProcessor接口常用于给接口动态添加代理类。这个接口中有一个方法如下: ```java public interface BeanDefinitionRegistryPostProcessor extends BeanFactoryPostProcessor { /** * Modify the application context's internal bean definition registry after its * standard initialization. All regular bean ...

BeanDefinitionRegistryPostProcessor的实现类中注入不了类

原创 2022-02-15 10:52 阅读(1197)次
最近在用BeanDefinitionRegistryPostProcessor实现接口生成动态代理的功能,BeanDefinitionRegistryPostProcessor的实现类中想取的配置类,但发现一直取不到springboot中的配置。 配置类代码如下: ```java @Data @Component @ConfigurationProperties("my.netty.feign") public class NettyFeignConfig { /** * netty feign扫瞄的目录 */ private Strin...

spring boot或spring cloud项目中使用系统环境变量问题

原创 2021-05-25 18:08 阅读(3426)次
#### 前言 项目开发过程中有时候需要用环境变量来解决一些复杂配置的问题,比如同一个服务要部署多个实例,但这些实例需要使用不同的配置时,这些就可以用环境变量来解决,这不管是原始的部署方式或使用k8s部署方式都是可以使用环境变量来解决这种问题。 下面我们分享下开发和部署时怎么设置环境变量 #### 代码示例 先上示例代码,比如我们要在bootstrap.yml中读取env_test这个环境变量,如下配置: ```yaml env: test: ${env_test} ``` 如果你遇到spring boot项目bootstrap.yml配置无法生效,可以看看我...

spring boot项目默认日志配置

原创 2020-11-26 17:43 阅读(688)次
spring boot默认日志为logback打印,默认不配置也可以打印日志,但生产环境中这样容易让日志打到机器磁盘不足,所以我们还是需要配置一下的:logging: file: name: app.log path: /home/java/ max-size: 50MB max-history: 7

springboot项目初始化druid连接池时报错java.lang.NullPointerException: null

原创 2020-04-27 18:25 阅读(5193)次
新创建了一个springboot项目,一顿配置,以为能正常启动,结果打脸了,报错了:2020-04-27 18:14:04.655 ERROR 18376 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} init error java.lang.NullPointerException: null at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:325) ~[na:1.8.0_191] at jav...

the dependencies of some of the beans in the application context form a cycle

原创 2020-01-16 08:56 阅读(12866)次
spring项目工程在idea中运行正常,可是打包运行就报错:the dependencies of some of the beans in the application context form a cycle错误意思是spring循环依赖,开始以为是打包问题,可检查了包里面的内容是正常的,于是我build project后再打包,居然可以了。网上也找了下别人的解决办法有:1.不要使用基于构造函数的依赖注入2.在字段上使用@Autowired注解,让Spring决定在合适的时机注入3.用基于setter方法的依赖注入那我的解决办法是重新build project,在这里都记录下如果还有其...

spring cloud config取不到配置@Value报错: Could not resolve placeholder 'xxxx' in value

原创 2020-01-02 11:28 阅读(11422)次
我们项目是使用spring cloud config作为微服务配置管理,使用的是本地文件形式,今天我重新下载了一份配置,修改了配置服务的文件地址,然后config client的项目就启动不了了,一直报错:Could not resolve placeholder 'xxxx' in value "${xxxx}"开始以为是项目配置格式问题,后来想到应该是我改了config server的配置地址:spring: application: name: ms-config-server profiles: active: native c...

sprinb boot整合apache dubbo时报错 java.lang.NoClassDefFoundError: org/apache/curator/utils

原创 2019-11-11 12:14 阅读(4634)次
搭建spring boot + dubbo微服务时,有个服务工程一直报错:Caused by: java.lang.NoClassDefFoundError: org/apache/curator/utils/DefaultZookeeperFactory at org.apache.curator.framework.CuratorFrameworkFactory.<clinit>(CuratorFrameworkFactory.java:66) ~[curator-framework-4.0.1.jar:4.0.1] at org.apache.dubbo.remoti...

spring boot整合apache dubbo时报错ConfigFileApplicationListener.supportsSourceType(Ljava/lang/Class;)Z

原创 2019-11-10 23:24 阅读(5156)次
spring boot整合apache dubbo时报错:Exception in thread "main" java.lang.AbstractMethodError: org.springframework.boot.context.config.ConfigFileApplicationListener.supportsSourceType(Ljava/lang/Class;)Z at org.springframework.context.event.GenericApplicationListenerAdapter.supportsSourceType(Ge...

spring cloud gateway 获得响应body记录日志问题

原创 2019-10-30 11:07 阅读(2183)次
通常在spring cloud微服务架构中,需要在网关gateway中记录日志,比如需要记录响应的body,今天我也是一直遇到响应体记录不完整的问题,body被分段,对于响应报文大一点的请求中,在响应ServerHttpResponseDecorator包装中一次取得body只能取的一段。有问题的代码如下: ServerHttpResponse originalResponse = exchange.getResponse(); DataBufferFactory bufferFactory = originalResponse.bufferFactory(); Serve...

redis报错远程主机强迫关闭了一个现有的连接以及超时问题

原创 2019-10-11 16:37 阅读(15085)次
问题说明:spring boot2.x+redis开发时,总是时不是发生redis超时,时不时报:远程主机强迫关闭了一个现有的连接以及超时问题。这个问题总是偶有出现,烦人。spring boot2.x版本默认redis连接池为lettuce,以前在非spring boot项目中使用jedis连接redis时,好像没有过这种烦人的问题,搞的现在对redis有阴影。。。我的项目也是使用默认的lettuce连接redis。我们先看超时问题的报错:io.lettuce.core.RedisCommandTimeoutException: Command timed out after 5 second...

spring boot项目时间字段少8小时问题

原创 2019-10-10 20:00 阅读(1382)次
今天发现我的工程很多数据保存后到mysql,创建时间字段都少了8小时,看了下其他微服务兄弟项目的数据,都不会有问题,然后才发现别的项目在连接mysql的url上有加上时区+8小时的配置,如下:spring: datasource: name: mysql_test type: com.alibaba.druid.pool.DruidDataSource #druid相关配置 druid: #监控统计拦截的filters filters: stat #driver-class-name: com.mysql....

feign接口类扫瞄找不到的问题,required a bean of type 'xx.xx.xxxFeignClient' that could not be found

原创 2019-09-24 17:40 阅读(2682)次
在搭建spring cloud微服务时经常会遇到如下错误:Description: Field orderInfoFeignClient in com.mcu.stock.service.StockService required a bean of type 'com.mcu.common.feign.order.OrderInfoFeignClient' that could not be found. The injection point has the following annotations: - @org.springframework.beans.factor...

spring cloud+feign+mybatis中使用seata0.9实现分布式事务

原创 2019-09-23 17:11 阅读(6319)次
seata前身叫fescar,是阿里开源的实现分布式事务中间件。官网地址:https://github.com/seata/seata中文文档:https://github.com/seata/seata/wiki/Home_Chinese原理就不说了,话不多说,直接分享代码:首先需要安装seata服务,下载地址:https://github.com/seata/seata/releases里面都是linux、windows都同时可以用的绿色版安装包1.启动seata服务默认以file形式注册,直接可以启动,启动端口默认为8091sh seata-server.sh -p 8091加上-p参数...

spring cloud集成分布式事务中间件seata报错 not support register type: null

原创 2019-09-23 11:50 阅读(8599)次
在启动seata中的RM端时报错:Caused by: io.seata.common.exception.NotSupportYetException: not support register type: null at io.seata.config.ConfigurationFactory.buildConfiguration(ConfigurationFactory.java:87) at io.seata.config.ConfigurationFactory.getInstance(ConfigurationFactory.java:71) at io.seata.s...

如何实现生产环境关闭swagger,只有开发环境中开启swagger

原创 2019-09-19 17:29 阅读(5878)次
spring boot工程在生产环境中出于安全考虑,不想要别人能访问你的swagger接口管理页面。这时我们就可以用配置将生产环境中的swagger关闭,但同时开发环境要开启,实现方式可以用@Value来配置。具体代码与配置如下:java代码:/** * swagger文档 * */ @Configuration @EnableSwagger2 public class SwaggerConfig { @Value("${swagger.enable}") private boolean enable = false; @Bean p...

spring cloud中Feign调用诡异报错MethodNotAllowed: status 405 reading

原创 2019-07-24 13:14 阅读(8171)次
微服务中使用feign内部调用报错:Caused by: feign.FeignException$MethodNotAllowed: status 405 reading VisitorFeignClient#login(String) at feign.FeignException.errorStatus(FeignException.java:100) at feign.FeignException.errorStatus(FeignException.java:86) at feign.codec.ErrorDecoder$Default.decode(ErrorDecoder.jav...

spring cloud gatewayThe ‘Access-Control-Allow-Origin’ header contains multiple values

原创 2019-07-16 20:53 阅读(4711)次
在spring cloud gateway网关中加入了跨域支持,但是报了:The ‘Access-Control-Allow-Origin’ header contains multiple values “*, *”, but only one is allowed.错误显示设置了两次Access-Control-Allow-Origin:*,但我的代码我确定只设置了一次,怀疑是哪出了问题,找了一上午问题,百度到说是gateway的bug我的版本:spring cloud gateway:2.1.2spring cloud: Greenwich.SR2解决办法如下:设置跨域:imp...

spring cloud gateway报错Only one connection receive subscriber allowed

原创 2019-07-08 11:06 阅读(4474)次
spring cloud网关报错:reactor.core.Exceptions$ErrorCallbackNotImplemented: java.lang.IllegalStateException: Only one connection receive subscriber allowed. Caused by: java.lang.IllegalStateException: Only one connection receive subscriber allowed. at reactor.ipc.netty.channel.FluxReceive.startRecei...

openfeign与gateway中的httpClient类声明冲突

原创 2019-07-06 12:27 阅读(2783)次
启动spring cloud中的网关,报错:***************************APPLICATION FAILED TO START***************************Description:The bean 'httpClient', defined in class path resource [org/springframework/cloud/openfeign/ribbon/HttpClientFeignLoadBalancedConfiguration$HttpClientFeignConfiguration.class], could not...

Spring boot跨域配置

原创 2019-06-25 16:18 阅读(1543)次
直接贴代码了,亲测可行:import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRe...

spring boot多module项目导入Eclipse

原创 2018-11-01 18:49 阅读(1879)次
spring boot多module工程导入Eclipse中时,子module工程显示成文件夹,不会加载成项目(project)时,例如我下面的spring cloud工程:此时,如果想要将子工程显示成项目,比如maven项目,只需要将视图切成Project Explorer,在子项目中右键点击导入成工程(Import as Project)就可以了,记住一定要切成Project Explorer视图。导入后就可以将项目完美显示了,如下:

Spring boot项目引入jar包时启动报错:java.lang.StackOverflowError

原创 2018-10-19 17:52 阅读(4149)次
我在学习spring cloud zipkin时,引入如下jar后, <!-- 引入zipkin-server --> <dependency> <groupId>io.zipkin.java</groupId> <artifactId>zipkin-server</artifactId> <version>2.11.7</version> </dependency> <!-- 引入zipkin-server 图形化界面 --> &...

spring事务管理与查询是否需要事务以及可重复读的问题

原创 2018-04-04 11:12 阅读(3021)次
我们先来看下通常的spring配置: <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> ...

使用spring4实现websocket连接(二)

原创 2018-02-05 15:54 阅读(1618)次
上一篇关于使用spring4实现websocket连接的问题,我只是分享了大致如何实现,要想应用到实际项目中,还要考虑2个问题:1.是否区分用户,用户连上wesocke时,每次发消息给用户时,是否要区分用户,是不是每个人收到的消息不一样,这里就涉及获取httpSession的问题了。2.我们项目中一般不会只有一个websocket收发消息,有时一个是处理用户消息,一个是处理其他的,举个例子:批处理时的进度实时反馈等,都会用到websocket所以针对上面这两个问题,我决定再深入研究了下,pom文件还是参考上一篇文章里的,并没有新加入jar包,下面直接上代码吧,类也是上一篇里的那两个类,只是新加...

使用spring4实现websocket连接

原创 2018-02-05 12:08 阅读(2468)次
之前我们都是用tomcat的jar包去实现websocket,因为tomcat7和8实现的代码不一样,升级完后7的代码无法在8下报错。听说spring4实现了websocket,于是我今天就研究了下。我是在我原本的spring项目里加入的websocket,其他spring配置就不一一列举了,我的spring用的是4.0.6,tomcat8,jdk1.8,websocket相关具体实现如下:maven加入: <dependency> <groupId>org.springframework</groupId> ...