How to configure apm-agent properties on yaml file for a spring-boot application?

Is it possible to configure the apm properties on a yaml file? I'm trying to configure on a spring-boot application but I think it is getting the default configuration :(.

SpringBootApplication.java

public static void main(String[] args) {
	ElasticApmAttacher.attach();
	SpringApplication.run(CpoEventsKafkaApplication.class, args);
}

pom.xml

<dependency>
    <groupId>co.elastic.apm</groupId>
    <artifactId>apm-agent-attach</artifactId>
    <version>1.50.0</version>
</dependency>

application.yml

elastic:
  apm:
    enabled: true
    application_packages: com.####.cpoeventskafka
    capture_body: true
    server_url: http://10.###.##.5:8200
    environment: dev
    service_name: cpo-event

Spring-boot log showing trying to connect to ip 127.0.0.1 no 10.###.##.5

10:41:44.654 [http-nio-7056-exec-1] INFO  o.s.web.servlet.DispatcherServlet - Completed initialization in 2 ms
2024-11-24 10:41:44,744 [elastic-apm-server-reporter] ERROR co.elastic.apm.agent.report.AbstractIntakeApiHandler - Error trying to connect to APM Server at http://127.0.0.1:8200/intake/v2/events. Although not necessarily related to SSL, some related SSL configurations corresponding the current connection are logged at INFO level.
2024-11-24 10:41:44,746 [elastic-apm-server-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Failed to handle event of type TRANSACTION with this error: Connection refused

I didn't find in any documentation using a yaml file.

Kibana: 7.17.24
Elasticsearch: 7.17.24
APM: 7.17.0
Spring-boot: 2.4.2

ElasticApmAttacher has several attach methods that may be what you want. yaml is not supported but a simple properties file or directly setting properties are both supported

I solved using environment variable on docker-compose:

cpo-event:
    container_name: cpo-event
    image: lserillo/cpo-event:$IMAGE_VERSION_CPO_EVENT
    ports:
      - 7056:7056
    volumes:
      - /etc/timezone:/etc/timezone:ro
      - ......
    environment:
      - ELASTIC_APM_SERVICE_NAME=cpo-event
      - ELASTIC_APM_SERVER_URL=http://10.###.##.5:8200
      - ELASTIC_APM_ENVIRONMENT=dev
    networks:
      - cup-network