# Error trying to connect to APM Server

**URL:** <https://discuss.elastic.co/t/error-trying-to-connect-to-apm-server/304145>\
**Category:** APM\
**Tags:** java, server\
**Created:** [May 6, 2022, 4:38pm UTC](https://discuss.elastic.co/t/error-trying-to-connect-to-apm-server/304145 "2022-05-06T16:38:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kama99](https://avatars.discourse-cdn.com/v4/letter/k/5f8ce5/32.png) [@kama99](https://discuss.elastic.co/u/kama99)\
**Post date:** [May 6, 2022, 4:38pm UTC](https://discuss.elastic.co/t/error-trying-to-connect-to-apm-server/304145/1 "2022-05-06T16:38:28Z")

</div>

**Kibana version** :  
7.16.3

**Elasticsearch version** :  
7.16.3

**APM Server version** :  
7.16.3

**APM Agent language and version** :  
Java, 1.30.1

**Fresh install or upgraded from other version?**  
Fresh

**Description of the problem including expected versus actual behavior. Please include screenshots (if relevant)**:  
I have spring boot project with apm-agent dependency, i started my app but there is error - Connection refused, I cannot connect to APM server. Also i'm thinking about apm server certificate, should I add it somewhere?

application.properties:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/8/f8a81af50196d94344feb503fa0ec64e2bfe83df.png)  
init function:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/7/77f149794d66692abed1616c259648f4f168212b.png)  
@Configuration:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/f/cf91c2c8d22c9b5b6e163b6cc39610deae6b728b.png)

**Provide logs and/or server output (if relevant)**:  
ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Error trying to connect to APM Server at [http://localhost:8200/intake/v2/events](http://localhost:8200/intake/v2/events). Although not necessarily related to SSL, some related SSL configurations corresponding the current connection are logged at INFO level.  
ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Failed to handle event of type JSON\_WRITER with this error: Connection refused (Connection refused)  
java.net.ConnectException: Connection refused (Connection refused)

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [May 8, 2022, 12:49pm UTC](https://discuss.elastic.co/t/error-trying-to-connect-to-apm-server/304145/2 "2022-05-08T12:49:11Z")

</div>

Hi and welcome to our forum 👋

> [@kama99](#):
>
> Also i'm thinking about apm server certificate, should I add it somewhere?

Since you are using HTTP to communicate with the APM Server, it shouldn't be related to SSL/TLS.  
Most likely the APM Server is not reachable at `http://localhost:8200` from your application host. Try `curl` to verify it is accessible from where the agent is deployed first.  
Also, check out our [troubleshooting guide](https://www.elastic.co/guide/en/apm/agent/java/current/trouble-shooting.html#trouble-shooting-no-data).

> [@kama99](#):
>
> I have spring boot project with apm-agent dependency

If you did add the agent as a dependency, then you should remove it. If you added the [`apm-agent-attach`](https://www.elastic.co/guide/en/apm/agent/java/current/setup-attach-api.html) as a dependency, then that's OK.

Make sure to go over our [setup](https://www.elastic.co/guide/en/apm/agent/java/current/setup.html) guide and the rest of the agent documentation.  
I hope you can find most answers there, let us know if not.

---

<div class="post-metadata">

**Author:** ![kama99](https://avatars.discourse-cdn.com/v4/letter/k/5f8ce5/32.png) [@kama99](https://discuss.elastic.co/u/kama99)\
**Post date:** [May 9, 2022, 7:42am UTC](https://discuss.elastic.co/t/error-trying-to-connect-to-apm-server/304145/3 "2022-05-09T07:42:22Z")

</div>

Hello again,  
So maybe I will share my configuration with more details.  
I'm using maven,java and spring  
This is my apm-agent attach dependency:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/4/148b738473af0c434e467a23b5dcc49c009ad713.png)  
Checking with guide I also have application.properties:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/2/3/23eb5eeffd47b26f4b6661dd5e59ded0cbb08ed5.png)  
Here i got my Config:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/7/f7cc3360b3b4abdaf299c1ca688e1e0ae4daffc4.png)  
In which i have method with attaching properties:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/8/18a7288c28089c954bd3b0771723bf31c0a4fe67.png)  
And I still have my problem

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [May 9, 2022, 8:15am UTC](https://discuss.elastic.co/t/error-trying-to-connect-to-apm-server/304145/4 "2022-05-09T08:15:21Z")

</div>

> [@Eyal\_Koren](#):
>
> Most likely the APM Server is not reachable at `http://localhost:8200` from your application host. Try `curl` to verify it is accessible from where the agent is deployed first.  
> Also, check out our [troubleshooting guide](https://www.elastic.co/guide/en/apm/agent/java/current/trouble-shooting.html#trouble-shooting-no-data).

☝

---

<div class="post-metadata">

**Author:** ![kama99](https://avatars.discourse-cdn.com/v4/letter/k/5f8ce5/32.png) [@kama99](https://discuss.elastic.co/u/kama99)\
**Post date:** [May 9, 2022, 8:59am UTC](https://discuss.elastic.co/t/error-trying-to-connect-to-apm-server/304145/6 "2022-05-09T08:59:40Z")

</div>

And if i change to HTTPS connection where I should add my certs considering I'm using agent attach dependency in spring boot? 🙂

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [May 9, 2022, 11:49am UTC](https://discuss.elastic.co/t/error-trying-to-connect-to-apm-server/304145/7 "2022-05-09T11:49:51Z")

</div>

Seriously, check out our [docs](https://www.elastic.co/guide/en/apm/agent/java/current/ssl-configuration.html), they are a good resource

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 30, 2022, 7:49am UTC](https://discuss.elastic.co/t/error-trying-to-connect-to-apm-server/304145/8 "2022-05-30T07:49:56Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
