Nacos本地进行了远程配置而远程未配置相关信息而导致应用报内存泄漏问题的异常
程序员文章站
2022-07-15 09:42:42
...
今天在用Nacos时突然出了这么一个问题:
意思是:[main]o.a.c.loader.WebappClassLoaderBase:web应用程序[ROOT]似乎启动了一个名为[com.alibaba.nacos.naming.client.listener]的线程,但未能停止它。这很可能会造成内存泄漏。线程堆栈跟踪:具体内容如下
The web application [ROOT] appears to have started a thread named [AsyncReporter{orgaaa@qq.com7b4b8199}] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.net.DualStackPlainSocketImpl.connect0(Native Method)
java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
java.net.Socket.connect(Socket.java:589)
java.net.Socket.connect(Socket.java:538)
sun.net.NetworkClient.doConnect(NetworkClient.java:180)
sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
sun.net.www.http.HttpClient.<init>(HttpClient.java:242)
sun.net.www.http.HttpClient.New(HttpClient.java:339)
sun.net.www.http.HttpClient.New(HttpClient.java:357)
sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1220)
sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156)
sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:984)
org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:76)
org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:735)
org.springframework.cloud.sleuth.zipkin2.sender.ZipkinRestTemplateWrapper.doExecute(ZipkinRestTemplateSenderConfiguration.java:162)
org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:637)
org.springframework.cloud.sleuth.zipkin2.sender.RestTemplateSender.post(RestTemplateSender.java:129)
org.springframework.cloud.sleuth.zipkin2.sender.RestTemplateSender$HttpPostCall.doExecute(RestTemplateSender.java:142)
org.springframework.cloud.sleuth.zipkin2.sender.RestTemplateSender$HttpPostCall.doExecute(RestTemplateSender.java:132)
zipkin2.Call$Base.execute(Call.java:379)
zipkin2.reporter.AsyncReporter$BoundedAsyncReporter.flush(AsyncReporter.java:286)
zipkin2.reporter.AsyncReporter$Builder$1.run(AsyncReporter.java:190)
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-11-09 12:00:31.120 ERROR [content-center,,,] 11280 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.testController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'your.configuration' in value "${your.configuration}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:380) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1411) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:356) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
一开始很奇怪为什么会发生这种异常,后来仔细阅读了异常内容发现了这么一段:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.testController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'your.configuration' in value "${your.configuration}"
于是顺着这个思路打开了 TestController文件,
发现原来这里有获取配置文件内容的一段代码,豁然明白,之前在nacos上做远程配置中心的测试,后来nacos关掉了,那段内容也就没有了,而本地又未做这个your.configuration这个名字相关的value所以导致了这个异常,两个解决办法
1:注释掉当前代码
2:远程或本地的yml文件中添加your.configuration的配置信息,再次启动运行正常。